Codebase list findbugs / 4665aea
remove bcel 5.2 yesx 10 years ago
355 changed file(s) with 0 addition(s) and 49092 deletion(s). Raw diff Collapse all Expand all
+0
-204
build/bcel-5.2-src/bcel-5.2/LICENSE.txt less more
0 /*
1 * Apache License
2 * Version 2.0, January 2004
3 * http://www.apache.org/licenses/
4 *
5 * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 *
7 * 1. Definitions.
8 *
9 * "License" shall mean the terms and conditions for use, reproduction,
10 * and distribution as defined by Sections 1 through 9 of this document.
11 *
12 * "Licensor" shall mean the copyright owner or entity authorized by
13 * the copyright owner that is granting the License.
14 *
15 * "Legal Entity" shall mean the union of the acting entity and all
16 * other entities that control, are controlled by, or are under common
17 * control with that entity. For the purposes of this definition,
18 * "control" means (i) the power, direct or indirect, to cause the
19 * direction or management of such entity, whether by contract or
20 * otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 * outstanding shares, or (iii) beneficial ownership of such entity.
22 *
23 * "You" (or "Your") shall mean an individual or Legal Entity
24 * exercising permissions granted by this License.
25 *
26 * "Source" form shall mean the preferred form for making modifications,
27 * including but not limited to software source code, documentation
28 * source, and configuration files.
29 *
30 * "Object" form shall mean any form resulting from mechanical
31 * transformation or translation of a Source form, including but
32 * not limited to compiled object code, generated documentation,
33 * and conversions to other media types.
34 *
35 * "Work" shall mean the work of authorship, whether in Source or
36 * Object form, made available under the License, as indicated by a
37 * copyright notice that is included in or attached to the work
38 * (an example is provided in the Appendix below).
39 *
40 * "Derivative Works" shall mean any work, whether in Source or Object
41 * form, that is based on (or derived from) the Work and for which the
42 * editorial revisions, annotations, elaborations, or other modifications
43 * represent, as a whole, an original work of authorship. For the purposes
44 * of this License, Derivative Works shall not include works that remain
45 * separable from, or merely link (or bind by name) to the interfaces of,
46 * the Work and Derivative Works thereof.
47 *
48 * "Contribution" shall mean any work of authorship, including
49 * the original version of the Work and any modifications or additions
50 * to that Work or Derivative Works thereof, that is intentionally
51 * submitted to Licensor for inclusion in the Work by the copyright owner
52 * or by an individual or Legal Entity authorized to submit on behalf of
53 * the copyright owner. For the purposes of this definition, "submitted"
54 * means any form of electronic, verbal, or written communication sent
55 * to the Licensor or its representatives, including but not limited to
56 * communication on electronic mailing lists, source code control systems,
57 * and issue tracking systems that are managed by, or on behalf of, the
58 * Licensor for the purpose of discussing and improving the Work, but
59 * excluding communication that is conspicuously marked or otherwise
60 * designated in writing by the copyright owner as "Not a Contribution."
61 *
62 * "Contributor" shall mean Licensor and any individual or Legal Entity
63 * on behalf of whom a Contribution has been received by Licensor and
64 * subsequently incorporated within the Work.
65 *
66 * 2. Grant of Copyright License. Subject to the terms and conditions of
67 * this License, each Contributor hereby grants to You a perpetual,
68 * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 * copyright license to reproduce, prepare Derivative Works of,
70 * publicly display, publicly perform, sublicense, and distribute the
71 * Work and such Derivative Works in Source or Object form.
72 *
73 * 3. Grant of Patent License. Subject to the terms and conditions of
74 * this License, each Contributor hereby grants to You a perpetual,
75 * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 * (except as stated in this section) patent license to make, have made,
77 * use, offer to sell, sell, import, and otherwise transfer the Work,
78 * where such license applies only to those patent claims licensable
79 * by such Contributor that are necessarily infringed by their
80 * Contribution(s) alone or by combination of their Contribution(s)
81 * with the Work to which such Contribution(s) was submitted. If You
82 * institute patent litigation against any entity (including a
83 * cross-claim or counterclaim in a lawsuit) alleging that the Work
84 * or a Contribution incorporated within the Work constitutes direct
85 * or contributory patent infringement, then any patent licenses
86 * granted to You under this License for that Work shall terminate
87 * as of the date such litigation is filed.
88 *
89 * 4. Redistribution. You may reproduce and distribute copies of the
90 * Work or Derivative Works thereof in any medium, with or without
91 * modifications, and in Source or Object form, provided that You
92 * meet the following conditions:
93 *
94 * (a) You must give any other recipients of the Work or
95 * Derivative Works a copy of this License; and
96 *
97 * (b) You must cause any modified files to carry prominent notices
98 * stating that You changed the files; and
99 *
100 * (c) You must retain, in the Source form of any Derivative Works
101 * that You distribute, all copyright, patent, trademark, and
102 * attribution notices from the Source form of the Work,
103 * excluding those notices that do not pertain to any part of
104 * the Derivative Works; and
105 *
106 * (d) If the Work includes a "NOTICE" text file as part of its
107 * distribution, then any Derivative Works that You distribute must
108 * include a readable copy of the attribution notices contained
109 * within such NOTICE file, excluding those notices that do not
110 * pertain to any part of the Derivative Works, in at least one
111 * of the following places: within a NOTICE text file distributed
112 * as part of the Derivative Works; within the Source form or
113 * documentation, if provided along with the Derivative Works; or,
114 * within a display generated by the Derivative Works, if and
115 * wherever such third-party notices normally appear. The contents
116 * of the NOTICE file are for informational purposes only and
117 * do not modify the License. You may add Your own attribution
118 * notices within Derivative Works that You distribute, alongside
119 * or as an addendum to the NOTICE text from the Work, provided
120 * that such additional attribution notices cannot be construed
121 * as modifying the License.
122 *
123 * You may add Your own copyright statement to Your modifications and
124 * may provide additional or different license terms and conditions
125 * for use, reproduction, or distribution of Your modifications, or
126 * for any such Derivative Works as a whole, provided Your use,
127 * reproduction, and distribution of the Work otherwise complies with
128 * the conditions stated in this License.
129 *
130 * 5. Submission of Contributions. Unless You explicitly state otherwise,
131 * any Contribution intentionally submitted for inclusion in the Work
132 * by You to the Licensor shall be under the terms and conditions of
133 * this License, without any additional terms or conditions.
134 * Notwithstanding the above, nothing herein shall supersede or modify
135 * the terms of any separate license agreement you may have executed
136 * with Licensor regarding such Contributions.
137 *
138 * 6. Trademarks. This License does not grant permission to use the trade
139 * names, trademarks, service marks, or product names of the Licensor,
140 * except as required for reasonable and customary use in describing the
141 * origin of the Work and reproducing the content of the NOTICE file.
142 *
143 * 7. Disclaimer of Warranty. Unless required by applicable law or
144 * agreed to in writing, Licensor provides the Work (and each
145 * Contributor provides its Contributions) on an "AS IS" BASIS,
146 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 * implied, including, without limitation, any warranties or conditions
148 * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 * PARTICULAR PURPOSE. You are solely responsible for determining the
150 * appropriateness of using or redistributing the Work and assume any
151 * risks associated with Your exercise of permissions under this License.
152 *
153 * 8. Limitation of Liability. In no event and under no legal theory,
154 * whether in tort (including negligence), contract, or otherwise,
155 * unless required by applicable law (such as deliberate and grossly
156 * negligent acts) or agreed to in writing, shall any Contributor be
157 * liable to You for damages, including any direct, indirect, special,
158 * incidental, or consequential damages of any character arising as a
159 * result of this License or out of the use or inability to use the
160 * Work (including but not limited to damages for loss of goodwill,
161 * work stoppage, computer failure or malfunction, or any and all
162 * other commercial damages or losses), even if such Contributor
163 * has been advised of the possibility of such damages.
164 *
165 * 9. Accepting Warranty or Additional Liability. While redistributing
166 * the Work or Derivative Works thereof, You may choose to offer,
167 * and charge a fee for, acceptance of support, warranty, indemnity,
168 * or other liability obligations and/or rights consistent with this
169 * License. However, in accepting such obligations, You may act only
170 * on Your own behalf and on Your sole responsibility, not on behalf
171 * of any other Contributor, and only if You agree to indemnify,
172 * defend, and hold each Contributor harmless for any liability
173 * incurred by, or claims asserted against, such Contributor by reason
174 * of your accepting any such warranty or additional liability.
175 *
176 * END OF TERMS AND CONDITIONS
177 *
178 * APPENDIX: How to apply the Apache License to your work.
179 *
180 * To apply the Apache License to your work, attach the following
181 * boilerplate notice, with the fields enclosed by brackets "[]"
182 * replaced with your own identifying information. (Don't include
183 * the brackets!) The text should be enclosed in the appropriate
184 * comment syntax for the file format. We also recommend that a
185 * file or class name and description of purpose be included on the
186 * same "printed page" as the copyright notice for easier
187 * identification within third-party archives.
188 *
189 * Copyright [yyyy] [name of copyright owner]
190 *
191 * Licensed under the Apache License, Version 2.0 (the "License");
192 * you may not use this file except in compliance with the License.
193 * You may obtain a copy of the License at
194 *
195 * http://www.apache.org/licenses/LICENSE-2.0
196 *
197 * Unless required by applicable law or agreed to in writing, software
198 * distributed under the License is distributed on an "AS IS" BASIS,
199 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 * See the License for the specific language governing permissions and
201 * limitations under the License.
202 */
203
+0
-10
build/bcel-5.2-src/bcel-5.2/NOTICE.txt less more
0 =========================================================================
1 == NOTICE file corresponding to the section 4 d of ==
2 == the Apache License, Version 2.0, ==
3 == in this case for the Apache Jakarta-BCEL distribution. ==
4 =========================================================================
5
6 This product includes software developed by
7 The Apache Software Foundation (http://www.apache.org/).
8
9
+0
-36
build/bcel-5.2-src/bcel-5.2/README.txt less more
0 Running a console based verifier
1
2 java org.apache.bcel.verifier.Verifier fully.qualified.class.Name
3
4 lets JustIce work standalone.
5 If you get a "java.lang.OutOfMemoryError", you should increase the
6 maximum Java heap space. A command like
7
8 java -Xmx1887436800 org.apache.bcel.verifier.Verifier f.q.c.Name
9
10 will usually resolve the problem. The value above is suitable for
11 big server machines; if your machine starts swapping to disk, try
12 to lower the value.
13
14
15
16 Running a graphics based verifier
17
18 If you prefer a graphical application, you should use a command like
19
20 java org.apache.bcel.verifier.GraphicalVerifier
21
22 to launch one. Again, you may have to resolve a memory issue depending
23 on the classes to verify.
24
25
26 Contact
27
28 If you spot a bug in the BCEL or its accompanying verifier "JustIce" please
29 check with the BCEL mailing list
30
31 http://jakarta.apache.org/bcel
32
33 or enter the issue into the BCEL bug database
34
35 http://issues.apache.org/bugzilla/enter_bug.cgi?product=BCEL
+0
-39
build/bcel-5.2-src/bcel-5.2/build.xml less more
0 <project name="bcel" default="jar">
1
2 <property name="src.dir" value="src/java"/>
3 <property name="classes.dir" value="eclipse"/>
4 <property name="jar.dir" value="."/>
5
6 <target name="jar" depends="clean,classes">
7 <!-- Main engine and command line jar file. -->
8 <jar destfile="${jar.dir}/bcel.jar" >
9 <!-- Compiled classes, properties files. -->
10 <fileset dir="${classes.dir}">
11 <include name="**/*.class"/>
12 </fileset>
13 </jar>
14 </target>
15
16 <!-- Compile Java source files, and copy other files (properties,
17 images, html, XSL stylesheets) that need to be part of the codebase. -->
18 <target name="classes">
19 <mkdir dir="${classes.dir}"/>
20 <!-- Compile Java source files. -->
21 <javac srcdir="${src.dir}"
22 destdir="${classes.dir}"
23 source="1.5"
24 target="jsr14"
25 deprecation="on"
26 debug="on">
27 </javac>
28 </target>
29 <!-- Delete generated files. -->
30 <target name="clean">
31 <delete file="${classes.dir}"/>
32 <mkdir dir="${classes.dir}"/>
33 </target>
34
35
36 </project>
37
38 <!-- vim:set ts=4: -->
+0
-33
build/bcel-5.2-src/bcel-5.2/maven.xml less more
0 <!--
1
2 Copyright 2001-2004 The Apache Software Foundation.
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
18 <project default="jar:jar" xmlns:j="jelly:core">
19
20 <preGoal name="dist:build-bin">
21 <copy todir="${maven.dist.bin.assembly.dir}">
22 <fileset file='${basedir}/NOTICE.txt'/>
23 </copy>
24 </preGoal>
25
26 <preGoal name="dist:build-src">
27 <copy todir="${maven.dist.src.assembly.dir}">
28 <fileset file='${basedir}/NOTICE.txt'/>
29 </copy>
30 </preGoal>
31
32 </project>
+0
-52
build/bcel-5.2-src/bcel-5.2/project.properties less more
0 maven.repo.list=apache.snapshots
1
2 maven.repo.apache.snapshots=scp://cvs.apache.org
3 maven.repo.apache.snapshots.directory=/www/cvs.apache.org/repository
4 maven.repo.apache.snapshots.username=${maven.repo.apache.username}
5 maven.repo.apache.snapshots.privatekey=${maven.repo.apache.privatekey}
6 maven.repo.apache.snapshots.passphrase=${maven.repo.apache.passphrase}
7 maven.repo.apache.snapshots.group=apcvs
8
9 maven.repo.apache.releases=scp://people.apache.org
10 maven.repo.apache.releases.directory=/www/www.apache.org/dist/java-repository
11 maven.repo.apache.releases.group=apcvs
12 #maven.repo.apache.releases.username=
13 #maven.repo.apache.releases.privatekey=
14 #maven.repo.apache.releases.passphrase=
15
16 #maven.mode.online =
17
18 maven.username = ${user.name}
19
20 maven.compile.debug = on
21 maven.compile.deprecation = off
22 maven.compile.optimize = off
23 maven.compile.source = 1.3
24 maven.compile.target = 1.3
25
26 maven.jar.manifest.attributes.list=X-Compile-Source-JDK,X-Compile-Target-JDK
27 maven.jar.manifest.attribute.X-Compile-Source-JDK=${maven.compile.source}
28 maven.jar.manifest.attribute.X-Compile-Target-JDK=${maven.compile.target}
29
30 maven.jarResources.basedir = src/java
31 maven.jar.excludes = **/package.html
32 #maven.junit.fork = true
33
34 maven.test.failure.ignore = true
35 maven.test.skip = false
36
37 maven.javadoc.author = false
38 maven.javadoc.links = http://java.sun.com/j2se/1.4.2/docs/api/
39
40 maven.changelog.factory = org.apache.maven.svnlib.SvnChangeLogFactory
41
42 maven.changes.issue.template = %URL%/bugzilla/show_bug.cgi?id=%ISSUE%
43
44 maven.xdoc.jsl = ../commons-build/commons-site.jsl
45 maven.xdoc.date = left
46 maven.xdoc.poweredby.image = maven-feather.png
47 maven.xdoc.version = ${pom.currentVersion}
48 maven.xdoc.developmentProcessUrl = http://jakarta.apache.org/site/management.html
49 maven.xdoc.includeProjectDocumentation = yes
50
51 maven.jar.override = off
+0
-158
build/bcel-5.2-src/bcel-5.2/project.xml less more
0 <?xml version="1.0"?>
1 <project>
2
3 <pomVersion>3</pomVersion>
4 <name>jakarta-bcel</name>
5 <id>bcel</id>
6 <currentVersion>5.2</currentVersion>
7 <organization>
8 <name>Apache Software Foundation</name>
9 <url>http://www.apache.org</url>
10 <logo>http://jakarta.apache.org/images/jakarta-logo.gif</logo>
11 </organization>
12 <inceptionYear>2002</inceptionYear>
13 <package>org.apache.bcel</package>
14
15 <logo>/images/bcel-logo.gif</logo>
16
17 <shortDescription>Bytecode Engineering Library</shortDescription>
18
19 <description>
20 Bytecode Engineering Library
21 </description>
22
23 <licenses>
24 <license>
25 <name>The Apache Software License, Version 2.0</name>
26 <url>/LICENSE.txt</url>
27 <distribution>repo</distribution>
28 </license>
29 </licenses>
30
31 <gumpRepositoryId>jakarta</gumpRepositoryId>
32 <url>http://jakarta.apache.org/bcel/</url>
33 <issueTrackingUrl>http://issues.apache.org/bugzilla</issueTrackingUrl>
34 <siteAddress>people.apache.org</siteAddress>
35 <siteDirectory>/home/tcurdt/public_html/bcel/rc3/site</siteDirectory>
36 <!--
37 <siteDirectory>/www/jakarta.apache.org/bcel/</siteDirectory>
38 -->
39 <repository>
40 <connection>scm:svn:http://svn.apache.org/repos/asf/jakarta/bcel/trunk</connection>
41 <url>http://svn.apache.org/repos/asf/jakarta/bcel/trunk</url>
42 </repository>
43
44 <mailingLists>
45 <mailingList>
46 <name>BCEL User List</name>
47 <subscribe>bcel-user-subscribe@jakarta.apache.org</subscribe>
48 <unsubscribe>bcel-user-unsubscribe@jakarta.apache.org</unsubscribe>
49 <archive>http://www.mail-archive.com/bcel-user@jakarta.apache.org/</archive>
50 </mailingList>
51 <mailingList>
52 <name>BCEL Developer List</name>
53 <subscribe>bcel-dev-subscribe@jakarta.apache.org</subscribe>
54 <unsubscribe>bcel-dev-unsubscribe@jakarta.apache.org</unsubscribe>
55 <archive>http://www.mail-archive.com/bcel-dev@jakarta.apache.org/</archive>
56 </mailingList>
57 </mailingLists>
58
59 <developers>
60
61 <developer>
62 <name>Markus Dahm</name>
63 <id>mdahm</id>
64 <email>m.dahm at gmx.de</email>
65 <organization>it-frameworksolutions</organization>
66 </developer>
67
68 <developer>
69 <name>Jason van Zyl</name>
70 <id>jvanzyl</id>
71 <email>jason at zenplex.com</email>
72 <organization>Zenplex</organization>
73 </developer>
74
75 <developer>
76 <name>Enver Haase</name>
77 <id>ehaase</id>
78 <email>enver at convergence.de</email>
79 <organization>convergence</organization>
80 </developer>
81
82 <developer>
83 <name>Dave Brosius</name>
84 <id>dbrosius</id>
85 <email>dbrosius at mebigfatguy.com</email>
86 </developer>
87
88 <developer>
89 <name>Torsten Curdt</name>
90 <id>tcurdt</id>
91 <email>tcurdt at apache.org</email>
92 </developer>
93
94 </developers>
95
96 <dependencies>
97
98 <dependency>
99 <id>regexp</id>
100 <version>1.2</version>
101 </dependency>
102
103 <!--
104 <dependency>
105 <groupId>maven-plugins</groupId>
106 <artifactId>maven-cobertura-plugin</artifactId>
107 <version>1.1</version>
108 <type>plugin</type>
109 </dependency>
110 -->
111
112 </dependencies>
113
114 <build>
115
116 <sourceDirectory>src/java</sourceDirectory>
117
118 <resources>
119 <resource>
120 <directory>${basedir}</directory>
121 <includes>
122 <include>NOTICE.txt</include>
123 </includes>
124 <targetPath>META-INF</targetPath>
125 </resource>
126 </resources>
127
128 <!--
129 <testSourceDirectory>src/java</testSourceDirectory>
130
131 <unitTestPatterns>
132 <unitTestPattern>exclude = **/*.class</unitTestPattern>
133 </unitTestPatterns>
134 -->
135
136 </build>
137
138 <reports>
139 <report>maven-license-plugin</report>
140 <report>maven-changelog-plugin</report>
141 <report>maven-changes-plugin</report>
142 <report>maven-developer-activity-plugin</report>
143 <report>maven-javadoc-plugin</report>
144 <!-- <report>maven-junit-report-plugin</report> -->
145 <!-- <report>maven-cobertura-plugin</report> -->
146 <report>maven-jxr-plugin</report>
147 <report>maven-pmd-plugin</report>
148 <!-- <report>maven-tasklist-plugin</report> -->
149 <!-- <report>maven-linkcheck-plugin</report> -->
150 <!-- <report>maven-findbugs-plugin</report> -->
151 <!-- <report>maven-jellydoc-plugin</report> -->
152 <!-- <report>maven-statcvs-plugin</report> -->
153 </reports>
154
155 </project>
156
157
+0
-769
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/Constants.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel;
17
18 /**
19 * Constants for the project, mostly defined in the JVM specification.
20 *
21 * @version $Id: Constants.java 410087 2006-05-29 12:12:19Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public interface Constants {
25 /** Major and minor version of the code.
26 */
27 public final static short MAJOR_1_1 = 45;
28 public final static short MINOR_1_1 = 3;
29 public final static short MAJOR_1_2 = 46;
30 public final static short MINOR_1_2 = 0;
31 public final static short MAJOR_1_3 = 47;
32 public final static short MINOR_1_3 = 0;
33 public final static short MAJOR_1_4 = 48;
34 public final static short MINOR_1_4 = 0;
35 public final static short MAJOR_1_5 = 49;
36 public final static short MINOR_1_5 = 0;
37 public final static short MAJOR = MAJOR_1_1; // Defaults
38 public final static short MINOR = MINOR_1_1;
39
40 /** Maximum value for an unsigned short.
41 */
42 public final static int MAX_SHORT = 65535; // 2^16 - 1
43
44 /** Maximum value for an unsigned byte.
45 */
46 public final static int MAX_BYTE = 255; // 2^8 - 1
47
48 /** Access flags for classes, fields and methods.
49 */
50 public final static short ACC_PUBLIC = 0x0001;
51 public final static short ACC_PRIVATE = 0x0002;
52 public final static short ACC_PROTECTED = 0x0004;
53 public final static short ACC_STATIC = 0x0008;
54
55 public final static short ACC_FINAL = 0x0010;
56 public final static short ACC_SYNCHRONIZED = 0x0020;
57 public final static short ACC_VOLATILE = 0x0040;
58 public final static short ACC_BRIDGE = 0x0040;
59 public final static short ACC_TRANSIENT = 0x0080;
60 public final static short ACC_VARARGS = 0x0080;
61
62 public final static short ACC_NATIVE = 0x0100;
63 public final static short ACC_INTERFACE = 0x0200;
64 public final static short ACC_ABSTRACT = 0x0400;
65 public final static short ACC_STRICT = 0x0800;
66
67 public final static short ACC_SYNTHETIC = 0x1000;
68 public final static short ACC_ANNOTATION = 0x2000;
69 public final static short ACC_ENUM = 0x4000;
70
71 // Applies to classes compiled by new compilers only
72 public final static short ACC_SUPER = 0x0020;
73
74 public final static short MAX_ACC_FLAG = ACC_ENUM;
75
76 public final static String[] ACCESS_NAMES = {
77 "public", "private", "protected", "static", "final", "synchronized",
78 "volatile", "transient", "native", "interface", "abstract", "strictfp",
79 "synthetic", "annotation", "enum"
80 };
81
82 /** Tags in constant pool to denote type of constant.
83 */
84 public final static byte CONSTANT_Utf8 = 1;
85 public final static byte CONSTANT_Integer = 3;
86 public final static byte CONSTANT_Float = 4;
87 public final static byte CONSTANT_Long = 5;
88 public final static byte CONSTANT_Double = 6;
89 public final static byte CONSTANT_Class = 7;
90 public final static byte CONSTANT_Fieldref = 9;
91 public final static byte CONSTANT_String = 8;
92 public final static byte CONSTANT_Methodref = 10;
93 public final static byte CONSTANT_InterfaceMethodref = 11;
94 public final static byte CONSTANT_NameAndType = 12;
95
96 public final static String[] CONSTANT_NAMES = {
97 "", "CONSTANT_Utf8", "", "CONSTANT_Integer",
98 "CONSTANT_Float", "CONSTANT_Long", "CONSTANT_Double",
99 "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref",
100 "CONSTANT_Methodref", "CONSTANT_InterfaceMethodref",
101 "CONSTANT_NameAndType" };
102
103 /** The name of the static initializer, also called &quot;class
104 * initialization method&quot; or &quot;interface initialization
105 * method&quot;. This is &quot;&lt;clinit&gt;&quot;.
106 */
107 public final static String STATIC_INITIALIZER_NAME = "<clinit>";
108
109 /** The name of every constructor method in a class, also called
110 * &quot;instance initialization method&quot;. This is &quot;&lt;init&gt;&quot;.
111 */
112 public final static String CONSTRUCTOR_NAME = "<init>";
113
114 /** The names of the interfaces implemented by arrays */
115 public final static String[] INTERFACES_IMPLEMENTED_BY_ARRAYS = {"java.lang.Cloneable", "java.io.Serializable"};
116
117 /**
118 * Limitations of the Java Virtual Machine.
119 * See The Java Virtual Machine Specification, Second Edition, page 152, chapter 4.10.
120 */
121 public static final int MAX_CP_ENTRIES = 65535;
122 public static final int MAX_CODE_SIZE = 65536; //bytes
123
124 /** Java VM opcodes.
125 */
126 public static final short NOP = 0;
127 public static final short ACONST_NULL = 1;
128 public static final short ICONST_M1 = 2;
129 public static final short ICONST_0 = 3;
130 public static final short ICONST_1 = 4;
131 public static final short ICONST_2 = 5;
132 public static final short ICONST_3 = 6;
133 public static final short ICONST_4 = 7;
134 public static final short ICONST_5 = 8;
135 public static final short LCONST_0 = 9;
136 public static final short LCONST_1 = 10;
137 public static final short FCONST_0 = 11;
138 public static final short FCONST_1 = 12;
139 public static final short FCONST_2 = 13;
140 public static final short DCONST_0 = 14;
141 public static final short DCONST_1 = 15;
142 public static final short BIPUSH = 16;
143 public static final short SIPUSH = 17;
144 public static final short LDC = 18;
145 public static final short LDC_W = 19;
146 public static final short LDC2_W = 20;
147 public static final short ILOAD = 21;
148 public static final short LLOAD = 22;
149 public static final short FLOAD = 23;
150 public static final short DLOAD = 24;
151 public static final short ALOAD = 25;
152 public static final short ILOAD_0 = 26;
153 public static final short ILOAD_1 = 27;
154 public static final short ILOAD_2 = 28;
155 public static final short ILOAD_3 = 29;
156 public static final short LLOAD_0 = 30;
157 public static final short LLOAD_1 = 31;
158 public static final short LLOAD_2 = 32;
159 public static final short LLOAD_3 = 33;
160 public static final short FLOAD_0 = 34;
161 public static final short FLOAD_1 = 35;
162 public static final short FLOAD_2 = 36;
163 public static final short FLOAD_3 = 37;
164 public static final short DLOAD_0 = 38;
165 public static final short DLOAD_1 = 39;
166 public static final short DLOAD_2 = 40;
167 public static final short DLOAD_3 = 41;
168 public static final short ALOAD_0 = 42;
169 public static final short ALOAD_1 = 43;
170 public static final short ALOAD_2 = 44;
171 public static final short ALOAD_3 = 45;
172 public static final short IALOAD = 46;
173 public static final short LALOAD = 47;
174 public static final short FALOAD = 48;
175 public static final short DALOAD = 49;
176 public static final short AALOAD = 50;
177 public static final short BALOAD = 51;
178 public static final short CALOAD = 52;
179 public static final short SALOAD = 53;
180 public static final short ISTORE = 54;
181 public static final short LSTORE = 55;
182 public static final short FSTORE = 56;
183 public static final short DSTORE = 57;
184 public static final short ASTORE = 58;
185 public static final short ISTORE_0 = 59;
186 public static final short ISTORE_1 = 60;
187 public static final short ISTORE_2 = 61;
188 public static final short ISTORE_3 = 62;
189 public static final short LSTORE_0 = 63;
190 public static final short LSTORE_1 = 64;
191 public static final short LSTORE_2 = 65;
192 public static final short LSTORE_3 = 66;
193 public static final short FSTORE_0 = 67;
194 public static final short FSTORE_1 = 68;
195 public static final short FSTORE_2 = 69;
196 public static final short FSTORE_3 = 70;
197 public static final short DSTORE_0 = 71;
198 public static final short DSTORE_1 = 72;
199 public static final short DSTORE_2 = 73;
200 public static final short DSTORE_3 = 74;
201 public static final short ASTORE_0 = 75;
202 public static final short ASTORE_1 = 76;
203 public static final short ASTORE_2 = 77;
204 public static final short ASTORE_3 = 78;
205 public static final short IASTORE = 79;
206 public static final short LASTORE = 80;
207 public static final short FASTORE = 81;
208 public static final short DASTORE = 82;
209 public static final short AASTORE = 83;
210 public static final short BASTORE = 84;
211 public static final short CASTORE = 85;
212 public static final short SASTORE = 86;
213 public static final short POP = 87;
214 public static final short POP2 = 88;
215 public static final short DUP = 89;
216 public static final short DUP_X1 = 90;
217 public static final short DUP_X2 = 91;
218 public static final short DUP2 = 92;
219 public static final short DUP2_X1 = 93;
220 public static final short DUP2_X2 = 94;
221 public static final short SWAP = 95;
222 public static final short IADD = 96;
223 public static final short LADD = 97;
224 public static final short FADD = 98;
225 public static final short DADD = 99;
226 public static final short ISUB = 100;
227 public static final short LSUB = 101;
228 public static final short FSUB = 102;
229 public static final short DSUB = 103;
230 public static final short IMUL = 104;
231 public static final short LMUL = 105;
232 public static final short FMUL = 106;
233 public static final short DMUL = 107;
234 public static final short IDIV = 108;
235 public static final short LDIV = 109;
236 public static final short FDIV = 110;
237 public static final short DDIV = 111;
238 public static final short IREM = 112;
239 public static final short LREM = 113;
240 public static final short FREM = 114;
241 public static final short DREM = 115;
242 public static final short INEG = 116;
243 public static final short LNEG = 117;
244 public static final short FNEG = 118;
245 public static final short DNEG = 119;
246 public static final short ISHL = 120;
247 public static final short LSHL = 121;
248 public static final short ISHR = 122;
249 public static final short LSHR = 123;
250 public static final short IUSHR = 124;
251 public static final short LUSHR = 125;
252 public static final short IAND = 126;
253 public static final short LAND = 127;
254 public static final short IOR = 128;
255 public static final short LOR = 129;
256 public static final short IXOR = 130;
257 public static final short LXOR = 131;
258 public static final short IINC = 132;
259 public static final short I2L = 133;
260 public static final short I2F = 134;
261 public static final short I2D = 135;
262 public static final short L2I = 136;
263 public static final short L2F = 137;
264 public static final short L2D = 138;
265 public static final short F2I = 139;
266 public static final short F2L = 140;
267 public static final short F2D = 141;
268 public static final short D2I = 142;
269 public static final short D2L = 143;
270 public static final short D2F = 144;
271 public static final short I2B = 145;
272 public static final short INT2BYTE = 145; // Old notion
273 public static final short I2C = 146;
274 public static final short INT2CHAR = 146; // Old notion
275 public static final short I2S = 147;
276 public static final short INT2SHORT = 147; // Old notion
277 public static final short LCMP = 148;
278 public static final short FCMPL = 149;
279 public static final short FCMPG = 150;
280 public static final short DCMPL = 151;
281 public static final short DCMPG = 152;
282 public static final short IFEQ = 153;
283 public static final short IFNE = 154;
284 public static final short IFLT = 155;
285 public static final short IFGE = 156;
286 public static final short IFGT = 157;
287 public static final short IFLE = 158;
288 public static final short IF_ICMPEQ = 159;
289 public static final short IF_ICMPNE = 160;
290 public static final short IF_ICMPLT = 161;
291 public static final short IF_ICMPGE = 162;
292 public static final short IF_ICMPGT = 163;
293 public static final short IF_ICMPLE = 164;
294 public static final short IF_ACMPEQ = 165;
295 public static final short IF_ACMPNE = 166;
296 public static final short GOTO = 167;
297 public static final short JSR = 168;
298 public static final short RET = 169;
299 public static final short TABLESWITCH = 170;
300 public static final short LOOKUPSWITCH = 171;
301 public static final short IRETURN = 172;
302 public static final short LRETURN = 173;
303 public static final short FRETURN = 174;
304 public static final short DRETURN = 175;
305 public static final short ARETURN = 176;
306 public static final short RETURN = 177;
307 public static final short GETSTATIC = 178;
308 public static final short PUTSTATIC = 179;
309 public static final short GETFIELD = 180;
310 public static final short PUTFIELD = 181;
311 public static final short INVOKEVIRTUAL = 182;
312 public static final short INVOKESPECIAL = 183;
313 public static final short INVOKENONVIRTUAL = 183; // Old name in JDK 1.0
314 public static final short INVOKESTATIC = 184;
315 public static final short INVOKEINTERFACE = 185;
316 public static final short NEW = 187;
317 public static final short NEWARRAY = 188;
318 public static final short ANEWARRAY = 189;
319 public static final short ARRAYLENGTH = 190;
320 public static final short ATHROW = 191;
321 public static final short CHECKCAST = 192;
322 public static final short INSTANCEOF = 193;
323 public static final short MONITORENTER = 194;
324 public static final short MONITOREXIT = 195;
325 public static final short WIDE = 196;
326 public static final short MULTIANEWARRAY = 197;
327 public static final short IFNULL = 198;
328 public static final short IFNONNULL = 199;
329 public static final short GOTO_W = 200;
330 public static final short JSR_W = 201;
331
332 /**
333 * Non-legal opcodes, may be used by JVM internally.
334 */
335 public static final short BREAKPOINT = 202;
336 public static final short LDC_QUICK = 203;
337 public static final short LDC_W_QUICK = 204;
338 public static final short LDC2_W_QUICK = 205;
339 public static final short GETFIELD_QUICK = 206;
340 public static final short PUTFIELD_QUICK = 207;
341 public static final short GETFIELD2_QUICK = 208;
342 public static final short PUTFIELD2_QUICK = 209;
343 public static final short GETSTATIC_QUICK = 210;
344 public static final short PUTSTATIC_QUICK = 211;
345 public static final short GETSTATIC2_QUICK = 212;
346 public static final short PUTSTATIC2_QUICK = 213;
347 public static final short INVOKEVIRTUAL_QUICK = 214;
348 public static final short INVOKENONVIRTUAL_QUICK = 215;
349 public static final short INVOKESUPER_QUICK = 216;
350 public static final short INVOKESTATIC_QUICK = 217;
351 public static final short INVOKEINTERFACE_QUICK = 218;
352 public static final short INVOKEVIRTUALOBJECT_QUICK = 219;
353 public static final short NEW_QUICK = 221;
354 public static final short ANEWARRAY_QUICK = 222;
355 public static final short MULTIANEWARRAY_QUICK = 223;
356 public static final short CHECKCAST_QUICK = 224;
357 public static final short INSTANCEOF_QUICK = 225;
358 public static final short INVOKEVIRTUAL_QUICK_W = 226;
359 public static final short GETFIELD_QUICK_W = 227;
360 public static final short PUTFIELD_QUICK_W = 228;
361 public static final short IMPDEP1 = 254;
362 public static final short IMPDEP2 = 255;
363
364 /**
365 * For internal purposes only.
366 */
367 public static final short PUSH = 4711;
368 public static final short SWITCH = 4712;
369
370 /**
371 * Illegal codes
372 */
373 public static final short UNDEFINED = -1;
374 public static final short UNPREDICTABLE = -2;
375 public static final short RESERVED = -3;
376 public static final String ILLEGAL_OPCODE = "<illegal opcode>";
377 public static final String ILLEGAL_TYPE = "<illegal type>";
378
379 public static final byte T_BOOLEAN = 4;
380 public static final byte T_CHAR = 5;
381 public static final byte T_FLOAT = 6;
382 public static final byte T_DOUBLE = 7;
383 public static final byte T_BYTE = 8;
384 public static final byte T_SHORT = 9;
385 public static final byte T_INT = 10;
386 public static final byte T_LONG = 11;
387
388 public static final byte T_VOID = 12; // Non-standard
389 public static final byte T_ARRAY = 13;
390 public static final byte T_OBJECT = 14;
391 public static final byte T_REFERENCE = 14; // Deprecated
392 public static final byte T_UNKNOWN = 15;
393 public static final byte T_ADDRESS = 16;
394
395 /** The primitive type names corresponding to the T_XX constants,
396 * e.g., TYPE_NAMES[T_INT] = "int"
397 */
398 public static final String[] TYPE_NAMES = {
399 ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
400 "boolean", "char", "float", "double", "byte", "short", "int", "long",
401 "void", "array", "object", "unknown" // Non-standard
402 };
403
404 /** The primitive class names corresponding to the T_XX constants,
405 * e.g., CLASS_TYPE_NAMES[T_INT] = "java.lang.Integer"
406 */
407 public static final String[] CLASS_TYPE_NAMES = {
408 ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
409 "java.lang.Boolean", "java.lang.Character", "java.lang.Float",
410 "java.lang.Double", "java.lang.Byte", "java.lang.Short",
411 "java.lang.Integer", "java.lang.Long", "java.lang.Void",
412 ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE
413 };
414
415 /** The signature characters corresponding to primitive types,
416 * e.g., SHORT_TYPE_NAMES[T_INT] = "I"
417 */
418 public static final String[] SHORT_TYPE_NAMES = {
419 ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE,
420 "Z", "C", "F", "D", "B", "S", "I", "J",
421 "V", ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE
422 };
423
424 /**
425 * Number of byte code operands, i.e., number of bytes after the tag byte
426 * itself.
427 */
428 public static final short[] NO_OF_OPERANDS = {
429 0/*nop*/, 0/*aconst_null*/, 0/*iconst_m1*/, 0/*iconst_0*/,
430 0/*iconst_1*/, 0/*iconst_2*/, 0/*iconst_3*/, 0/*iconst_4*/,
431 0/*iconst_5*/, 0/*lconst_0*/, 0/*lconst_1*/, 0/*fconst_0*/,
432 0/*fconst_1*/, 0/*fconst_2*/, 0/*dconst_0*/, 0/*dconst_1*/,
433 1/*bipush*/, 2/*sipush*/, 1/*ldc*/, 2/*ldc_w*/, 2/*ldc2_w*/,
434 1/*iload*/, 1/*lload*/, 1/*fload*/, 1/*dload*/, 1/*aload*/,
435 0/*iload_0*/, 0/*iload_1*/, 0/*iload_2*/, 0/*iload_3*/,
436 0/*lload_0*/, 0/*lload_1*/, 0/*lload_2*/, 0/*lload_3*/,
437 0/*fload_0*/, 0/*fload_1*/, 0/*fload_2*/, 0/*fload_3*/,
438 0/*dload_0*/, 0/*dload_1*/, 0/*dload_2*/, 0/*dload_3*/,
439 0/*aload_0*/, 0/*aload_1*/, 0/*aload_2*/, 0/*aload_3*/,
440 0/*iaload*/, 0/*laload*/, 0/*faload*/, 0/*daload*/,
441 0/*aaload*/, 0/*baload*/, 0/*caload*/, 0/*saload*/,
442 1/*istore*/, 1/*lstore*/, 1/*fstore*/, 1/*dstore*/,
443 1/*astore*/, 0/*istore_0*/, 0/*istore_1*/, 0/*istore_2*/,
444 0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/, 0/*lstore_2*/,
445 0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/,
446 0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/,
447 0/*dstore_3*/, 0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/,
448 0/*astore_3*/, 0/*iastore*/, 0/*lastore*/, 0/*fastore*/,
449 0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/,
450 0/*sastore*/, 0/*pop*/, 0/*pop2*/, 0/*dup*/, 0/*dup_x1*/,
451 0/*dup_x2*/, 0/*dup2*/, 0/*dup2_x1*/, 0/*dup2_x2*/, 0/*swap*/,
452 0/*iadd*/, 0/*ladd*/, 0/*fadd*/, 0/*dadd*/, 0/*isub*/,
453 0/*lsub*/, 0/*fsub*/, 0/*dsub*/, 0/*imul*/, 0/*lmul*/,
454 0/*fmul*/, 0/*dmul*/, 0/*idiv*/, 0/*ldiv*/, 0/*fdiv*/,
455 0/*ddiv*/, 0/*irem*/, 0/*lrem*/, 0/*frem*/, 0/*drem*/,
456 0/*ineg*/, 0/*lneg*/, 0/*fneg*/, 0/*dneg*/, 0/*ishl*/,
457 0/*lshl*/, 0/*ishr*/, 0/*lshr*/, 0/*iushr*/, 0/*lushr*/,
458 0/*iand*/, 0/*land*/, 0/*ior*/, 0/*lor*/, 0/*ixor*/, 0/*lxor*/,
459 2/*iinc*/, 0/*i2l*/, 0/*i2f*/, 0/*i2d*/, 0/*l2i*/, 0/*l2f*/,
460 0/*l2d*/, 0/*f2i*/, 0/*f2l*/, 0/*f2d*/, 0/*d2i*/, 0/*d2l*/,
461 0/*d2f*/, 0/*i2b*/, 0/*i2c*/, 0/*i2s*/, 0/*lcmp*/, 0/*fcmpl*/,
462 0/*fcmpg*/, 0/*dcmpl*/, 0/*dcmpg*/, 2/*ifeq*/, 2/*ifne*/,
463 2/*iflt*/, 2/*ifge*/, 2/*ifgt*/, 2/*ifle*/, 2/*if_icmpeq*/,
464 2/*if_icmpne*/, 2/*if_icmplt*/, 2/*if_icmpge*/, 2/*if_icmpgt*/,
465 2/*if_icmple*/, 2/*if_acmpeq*/, 2/*if_acmpne*/, 2/*goto*/,
466 2/*jsr*/, 1/*ret*/, UNPREDICTABLE/*tableswitch*/, UNPREDICTABLE/*lookupswitch*/,
467 0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/,
468 0/*dreturn*/, 0/*areturn*/, 0/*return*/,
469 2/*getstatic*/, 2/*putstatic*/, 2/*getfield*/,
470 2/*putfield*/, 2/*invokevirtual*/, 2/*invokespecial*/, 2/*invokestatic*/,
471 4/*invokeinterface*/, UNDEFINED, 2/*new*/,
472 1/*newarray*/, 2/*anewarray*/,
473 0/*arraylength*/, 0/*athrow*/, 2/*checkcast*/,
474 2/*instanceof*/, 0/*monitorenter*/,
475 0/*monitorexit*/, UNPREDICTABLE/*wide*/, 3/*multianewarray*/,
476 2/*ifnull*/, 2/*ifnonnull*/, 4/*goto_w*/,
477 4/*jsr_w*/, 0/*breakpoint*/, UNDEFINED,
478 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
479 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
480 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
481 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
482 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
483 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
484 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
485 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
486 UNDEFINED, UNDEFINED, RESERVED/*impdep1*/, RESERVED/*impdep2*/
487 };
488
489 /**
490 * How the byte code operands are to be interpreted.
491 */
492 public static final short[][] TYPE_OF_OPERANDS = {
493 {}/*nop*/, {}/*aconst_null*/, {}/*iconst_m1*/, {}/*iconst_0*/,
494 {}/*iconst_1*/, {}/*iconst_2*/, {}/*iconst_3*/, {}/*iconst_4*/,
495 {}/*iconst_5*/, {}/*lconst_0*/, {}/*lconst_1*/, {}/*fconst_0*/,
496 {}/*fconst_1*/, {}/*fconst_2*/, {}/*dconst_0*/, {}/*dconst_1*/,
497 {T_BYTE}/*bipush*/, {T_SHORT}/*sipush*/, {T_BYTE}/*ldc*/,
498 {T_SHORT}/*ldc_w*/, {T_SHORT}/*ldc2_w*/,
499 {T_BYTE}/*iload*/, {T_BYTE}/*lload*/, {T_BYTE}/*fload*/,
500 {T_BYTE}/*dload*/, {T_BYTE}/*aload*/, {}/*iload_0*/,
501 {}/*iload_1*/, {}/*iload_2*/, {}/*iload_3*/, {}/*lload_0*/,
502 {}/*lload_1*/, {}/*lload_2*/, {}/*lload_3*/, {}/*fload_0*/,
503 {}/*fload_1*/, {}/*fload_2*/, {}/*fload_3*/, {}/*dload_0*/,
504 {}/*dload_1*/, {}/*dload_2*/, {}/*dload_3*/, {}/*aload_0*/,
505 {}/*aload_1*/, {}/*aload_2*/, {}/*aload_3*/, {}/*iaload*/,
506 {}/*laload*/, {}/*faload*/, {}/*daload*/, {}/*aaload*/,
507 {}/*baload*/, {}/*caload*/, {}/*saload*/, {T_BYTE}/*istore*/,
508 {T_BYTE}/*lstore*/, {T_BYTE}/*fstore*/, {T_BYTE}/*dstore*/,
509 {T_BYTE}/*astore*/, {}/*istore_0*/, {}/*istore_1*/,
510 {}/*istore_2*/, {}/*istore_3*/, {}/*lstore_0*/, {}/*lstore_1*/,
511 {}/*lstore_2*/, {}/*lstore_3*/, {}/*fstore_0*/, {}/*fstore_1*/,
512 {}/*fstore_2*/, {}/*fstore_3*/, {}/*dstore_0*/, {}/*dstore_1*/,
513 {}/*dstore_2*/, {}/*dstore_3*/, {}/*astore_0*/, {}/*astore_1*/,
514 {}/*astore_2*/, {}/*astore_3*/, {}/*iastore*/, {}/*lastore*/,
515 {}/*fastore*/, {}/*dastore*/, {}/*aastore*/, {}/*bastore*/,
516 {}/*castore*/, {}/*sastore*/, {}/*pop*/, {}/*pop2*/, {}/*dup*/,
517 {}/*dup_x1*/, {}/*dup_x2*/, {}/*dup2*/, {}/*dup2_x1*/,
518 {}/*dup2_x2*/, {}/*swap*/, {}/*iadd*/, {}/*ladd*/, {}/*fadd*/,
519 {}/*dadd*/, {}/*isub*/, {}/*lsub*/, {}/*fsub*/, {}/*dsub*/,
520 {}/*imul*/, {}/*lmul*/, {}/*fmul*/, {}/*dmul*/, {}/*idiv*/,
521 {}/*ldiv*/, {}/*fdiv*/, {}/*ddiv*/, {}/*irem*/, {}/*lrem*/,
522 {}/*frem*/, {}/*drem*/, {}/*ineg*/, {}/*lneg*/, {}/*fneg*/,
523 {}/*dneg*/, {}/*ishl*/, {}/*lshl*/, {}/*ishr*/, {}/*lshr*/,
524 {}/*iushr*/, {}/*lushr*/, {}/*iand*/, {}/*land*/, {}/*ior*/,
525 {}/*lor*/, {}/*ixor*/, {}/*lxor*/, {T_BYTE, T_BYTE}/*iinc*/,
526 {}/*i2l*/, {}/*i2f*/, {}/*i2d*/, {}/*l2i*/, {}/*l2f*/, {}/*l2d*/,
527 {}/*f2i*/, {}/*f2l*/, {}/*f2d*/, {}/*d2i*/, {}/*d2l*/, {}/*d2f*/,
528 {}/*i2b*/, {}/*i2c*/,{}/*i2s*/, {}/*lcmp*/, {}/*fcmpl*/,
529 {}/*fcmpg*/, {}/*dcmpl*/, {}/*dcmpg*/, {T_SHORT}/*ifeq*/,
530 {T_SHORT}/*ifne*/, {T_SHORT}/*iflt*/, {T_SHORT}/*ifge*/,
531 {T_SHORT}/*ifgt*/, {T_SHORT}/*ifle*/, {T_SHORT}/*if_icmpeq*/,
532 {T_SHORT}/*if_icmpne*/, {T_SHORT}/*if_icmplt*/,
533 {T_SHORT}/*if_icmpge*/, {T_SHORT}/*if_icmpgt*/,
534 {T_SHORT}/*if_icmple*/, {T_SHORT}/*if_acmpeq*/,
535 {T_SHORT}/*if_acmpne*/, {T_SHORT}/*goto*/, {T_SHORT}/*jsr*/,
536 {T_BYTE}/*ret*/, {}/*tableswitch*/, {}/*lookupswitch*/,
537 {}/*ireturn*/, {}/*lreturn*/, {}/*freturn*/, {}/*dreturn*/,
538 {}/*areturn*/, {}/*return*/, {T_SHORT}/*getstatic*/,
539 {T_SHORT}/*putstatic*/, {T_SHORT}/*getfield*/,
540 {T_SHORT}/*putfield*/, {T_SHORT}/*invokevirtual*/,
541 {T_SHORT}/*invokespecial*/, {T_SHORT}/*invokestatic*/,
542 {T_SHORT, T_BYTE, T_BYTE}/*invokeinterface*/, {},
543 {T_SHORT}/*new*/, {T_BYTE}/*newarray*/,
544 {T_SHORT}/*anewarray*/, {}/*arraylength*/, {}/*athrow*/,
545 {T_SHORT}/*checkcast*/, {T_SHORT}/*instanceof*/,
546 {}/*monitorenter*/, {}/*monitorexit*/, {T_BYTE}/*wide*/,
547 {T_SHORT, T_BYTE}/*multianewarray*/, {T_SHORT}/*ifnull*/,
548 {T_SHORT}/*ifnonnull*/, {T_INT}/*goto_w*/, {T_INT}/*jsr_w*/,
549 {}/*breakpoint*/, {}, {}, {}, {}, {}, {}, {},
550 {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
551 {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
552 {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
553 {}/*impdep1*/, {}/*impdep2*/
554 };
555
556 /**
557 * Names of opcodes.
558 */
559 public static final String[] OPCODE_NAMES = {
560 "nop", "aconst_null", "iconst_m1", "iconst_0", "iconst_1",
561 "iconst_2", "iconst_3", "iconst_4", "iconst_5", "lconst_0",
562 "lconst_1", "fconst_0", "fconst_1", "fconst_2", "dconst_0",
563 "dconst_1", "bipush", "sipush", "ldc", "ldc_w", "ldc2_w", "iload",
564 "lload", "fload", "dload", "aload", "iload_0", "iload_1", "iload_2",
565 "iload_3", "lload_0", "lload_1", "lload_2", "lload_3", "fload_0",
566 "fload_1", "fload_2", "fload_3", "dload_0", "dload_1", "dload_2",
567 "dload_3", "aload_0", "aload_1", "aload_2", "aload_3", "iaload",
568 "laload", "faload", "daload", "aaload", "baload", "caload", "saload",
569 "istore", "lstore", "fstore", "dstore", "astore", "istore_0",
570 "istore_1", "istore_2", "istore_3", "lstore_0", "lstore_1",
571 "lstore_2", "lstore_3", "fstore_0", "fstore_1", "fstore_2",
572 "fstore_3", "dstore_0", "dstore_1", "dstore_2", "dstore_3",
573 "astore_0", "astore_1", "astore_2", "astore_3", "iastore", "lastore",
574 "fastore", "dastore", "aastore", "bastore", "castore", "sastore",
575 "pop", "pop2", "dup", "dup_x1", "dup_x2", "dup2", "dup2_x1",
576 "dup2_x2", "swap", "iadd", "ladd", "fadd", "dadd", "isub", "lsub",
577 "fsub", "dsub", "imul", "lmul", "fmul", "dmul", "idiv", "ldiv",
578 "fdiv", "ddiv", "irem", "lrem", "frem", "drem", "ineg", "lneg",
579 "fneg", "dneg", "ishl", "lshl", "ishr", "lshr", "iushr", "lushr",
580 "iand", "land", "ior", "lor", "ixor", "lxor", "iinc", "i2l", "i2f",
581 "i2d", "l2i", "l2f", "l2d", "f2i", "f2l", "f2d", "d2i", "d2l", "d2f",
582 "i2b", "i2c", "i2s", "lcmp", "fcmpl", "fcmpg",
583 "dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge", "ifgt", "ifle",
584 "if_icmpeq", "if_icmpne", "if_icmplt", "if_icmpge", "if_icmpgt",
585 "if_icmple", "if_acmpeq", "if_acmpne", "goto", "jsr", "ret",
586 "tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn",
587 "dreturn", "areturn", "return", "getstatic", "putstatic", "getfield",
588 "putfield", "invokevirtual", "invokespecial", "invokestatic",
589 "invokeinterface", ILLEGAL_OPCODE, "new", "newarray", "anewarray",
590 "arraylength", "athrow", "checkcast", "instanceof", "monitorenter",
591 "monitorexit", "wide", "multianewarray", "ifnull", "ifnonnull",
592 "goto_w", "jsr_w", "breakpoint", ILLEGAL_OPCODE, ILLEGAL_OPCODE,
593 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
594 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
595 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
596 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
597 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
598 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
599 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
600 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
601 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
602 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
603 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
604 ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
605 ILLEGAL_OPCODE, "impdep1", "impdep2"
606 };
607
608 /**
609 * Number of words consumed on operand stack by instructions.
610 */
611 public static final int[] CONSUME_STACK = {
612 0/*nop*/, 0/*aconst_null*/, 0/*iconst_m1*/, 0/*iconst_0*/, 0/*iconst_1*/,
613 0/*iconst_2*/, 0/*iconst_3*/, 0/*iconst_4*/, 0/*iconst_5*/, 0/*lconst_0*/,
614 0/*lconst_1*/, 0/*fconst_0*/, 0/*fconst_1*/, 0/*fconst_2*/, 0/*dconst_0*/,
615 0/*dconst_1*/, 0/*bipush*/, 0/*sipush*/, 0/*ldc*/, 0/*ldc_w*/, 0/*ldc2_w*/, 0/*iload*/,
616 0/*lload*/, 0/*fload*/, 0/*dload*/, 0/*aload*/, 0/*iload_0*/, 0/*iload_1*/, 0/*iload_2*/,
617 0/*iload_3*/, 0/*lload_0*/, 0/*lload_1*/, 0/*lload_2*/, 0/*lload_3*/, 0/*fload_0*/,
618 0/*fload_1*/, 0/*fload_2*/, 0/*fload_3*/, 0/*dload_0*/, 0/*dload_1*/, 0/*dload_2*/,
619 0/*dload_3*/, 0/*aload_0*/, 0/*aload_1*/, 0/*aload_2*/, 0/*aload_3*/, 2/*iaload*/,
620 2/*laload*/, 2/*faload*/, 2/*daload*/, 2/*aaload*/, 2/*baload*/, 2/*caload*/, 2/*saload*/,
621 1/*istore*/, 2/*lstore*/, 1/*fstore*/, 2/*dstore*/, 1/*astore*/, 1/*istore_0*/,
622 1/*istore_1*/, 1/*istore_2*/, 1/*istore_3*/, 2/*lstore_0*/, 2/*lstore_1*/,
623 2/*lstore_2*/, 2/*lstore_3*/, 1/*fstore_0*/, 1/*fstore_1*/, 1/*fstore_2*/,
624 1/*fstore_3*/, 2/*dstore_0*/, 2/*dstore_1*/, 2/*dstore_2*/, 2/*dstore_3*/,
625 1/*astore_0*/, 1/*astore_1*/, 1/*astore_2*/, 1/*astore_3*/, 3/*iastore*/, 4/*lastore*/,
626 3/*fastore*/, 4/*dastore*/, 3/*aastore*/, 3/*bastore*/, 3/*castore*/, 3/*sastore*/,
627 1/*pop*/, 2/*pop2*/, 1/*dup*/, 2/*dup_x1*/, 3/*dup_x2*/, 2/*dup2*/, 3/*dup2_x1*/,
628 4/*dup2_x2*/, 2/*swap*/, 2/*iadd*/, 4/*ladd*/, 2/*fadd*/, 4/*dadd*/, 2/*isub*/, 4/*lsub*/,
629 2/*fsub*/, 4/*dsub*/, 2/*imul*/, 4/*lmul*/, 2/*fmul*/, 4/*dmul*/, 2/*idiv*/, 4/*ldiv*/,
630 2/*fdiv*/, 4/*ddiv*/, 2/*irem*/, 4/*lrem*/, 2/*frem*/, 4/*drem*/, 1/*ineg*/, 2/*lneg*/,
631 1/*fneg*/, 2/*dneg*/, 2/*ishl*/, 3/*lshl*/, 2/*ishr*/, 3/*lshr*/, 2/*iushr*/, 3/*lushr*/,
632 2/*iand*/, 4/*land*/, 2/*ior*/, 4/*lor*/, 2/*ixor*/, 4/*lxor*/, 0/*iinc*/,
633 1/*i2l*/, 1/*i2f*/, 1/*i2d*/, 2/*l2i*/, 2/*l2f*/, 2/*l2d*/, 1/*f2i*/, 1/*f2l*/,
634 1/*f2d*/, 2/*d2i*/, 2/*d2l*/, 2/*d2f*/, 1/*i2b*/, 1/*i2c*/, 1/*i2s*/,
635 4/*lcmp*/, 2/*fcmpl*/, 2/*fcmpg*/, 4/*dcmpl*/, 4/*dcmpg*/, 1/*ifeq*/, 1/*ifne*/,
636 1/*iflt*/, 1/*ifge*/, 1/*ifgt*/, 1/*ifle*/, 2/*if_icmpeq*/, 2/*if_icmpne*/, 2/*if_icmplt*/,
637 2 /*if_icmpge*/, 2/*if_icmpgt*/, 2/*if_icmple*/, 2/*if_acmpeq*/, 2/*if_acmpne*/,
638 0/*goto*/, 0/*jsr*/, 0/*ret*/, 1/*tableswitch*/, 1/*lookupswitch*/, 1/*ireturn*/,
639 2/*lreturn*/, 1/*freturn*/, 2/*dreturn*/, 1/*areturn*/, 0/*return*/, 0/*getstatic*/,
640 UNPREDICTABLE/*putstatic*/, 1/*getfield*/, UNPREDICTABLE/*putfield*/,
641 UNPREDICTABLE/*invokevirtual*/, UNPREDICTABLE/*invokespecial*/,
642 UNPREDICTABLE/*invokestatic*/,
643 UNPREDICTABLE/*invokeinterface*/, UNDEFINED, 0/*new*/, 1/*newarray*/, 1/*anewarray*/,
644 1/*arraylength*/, 1/*athrow*/, 1/*checkcast*/, 1/*instanceof*/, 1/*monitorenter*/,
645 1/*monitorexit*/, 0/*wide*/, UNPREDICTABLE/*multianewarray*/, 1/*ifnull*/, 1/*ifnonnull*/,
646 0/*goto_w*/, 0/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, UNDEFINED,
647 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
648 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
649 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
650 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
651 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
652 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
653 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
654 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
655 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
656 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
657 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
658 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
659 UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/
660 };
661
662 /**
663 * Number of words produced onto operand stack by instructions.
664 */
665 public static final int[] PRODUCE_STACK = {
666 0/*nop*/, 1/*aconst_null*/, 1/*iconst_m1*/, 1/*iconst_0*/, 1/*iconst_1*/,
667 1/*iconst_2*/, 1/*iconst_3*/, 1/*iconst_4*/, 1/*iconst_5*/, 2/*lconst_0*/,
668 2/*lconst_1*/, 1/*fconst_0*/, 1/*fconst_1*/, 1/*fconst_2*/, 2/*dconst_0*/,
669 2/*dconst_1*/, 1/*bipush*/, 1/*sipush*/, 1/*ldc*/, 1/*ldc_w*/, 2/*ldc2_w*/, 1/*iload*/,
670 2/*lload*/, 1/*fload*/, 2/*dload*/, 1/*aload*/, 1/*iload_0*/, 1/*iload_1*/, 1/*iload_2*/,
671 1/*iload_3*/, 2/*lload_0*/, 2/*lload_1*/, 2/*lload_2*/, 2/*lload_3*/, 1/*fload_0*/,
672 1/*fload_1*/, 1/*fload_2*/, 1/*fload_3*/, 2/*dload_0*/, 2/*dload_1*/, 2/*dload_2*/,
673 2/*dload_3*/, 1/*aload_0*/, 1/*aload_1*/, 1/*aload_2*/, 1/*aload_3*/, 1/*iaload*/,
674 2/*laload*/, 1/*faload*/, 2/*daload*/, 1/*aaload*/, 1/*baload*/, 1/*caload*/, 1/*saload*/,
675 0/*istore*/, 0/*lstore*/, 0/*fstore*/, 0/*dstore*/, 0/*astore*/, 0/*istore_0*/,
676 0/*istore_1*/, 0/*istore_2*/, 0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/,
677 0/*lstore_2*/, 0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/,
678 0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/, 0/*dstore_3*/,
679 0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/, 0/*astore_3*/, 0/*iastore*/, 0/*lastore*/,
680 0/*fastore*/, 0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/, 0/*sastore*/,
681 0/*pop*/, 0/*pop2*/, 2/*dup*/, 3/*dup_x1*/, 4/*dup_x2*/, 4/*dup2*/, 5/*dup2_x1*/,
682 6/*dup2_x2*/, 2/*swap*/, 1/*iadd*/, 2/*ladd*/, 1/*fadd*/, 2/*dadd*/, 1/*isub*/, 2/*lsub*/,
683 1/*fsub*/, 2/*dsub*/, 1/*imul*/, 2/*lmul*/, 1/*fmul*/, 2/*dmul*/, 1/*idiv*/, 2/*ldiv*/,
684 1/*fdiv*/, 2/*ddiv*/, 1/*irem*/, 2/*lrem*/, 1/*frem*/, 2/*drem*/, 1/*ineg*/, 2/*lneg*/,
685 1/*fneg*/, 2/*dneg*/, 1/*ishl*/, 2/*lshl*/, 1/*ishr*/, 2/*lshr*/, 1/*iushr*/, 2/*lushr*/,
686 1/*iand*/, 2/*land*/, 1/*ior*/, 2/*lor*/, 1/*ixor*/, 2/*lxor*/,
687 0/*iinc*/, 2/*i2l*/, 1/*i2f*/, 2/*i2d*/, 1/*l2i*/, 1/*l2f*/, 2/*l2d*/, 1/*f2i*/,
688 2/*f2l*/, 2/*f2d*/, 1/*d2i*/, 2/*d2l*/, 1/*d2f*/,
689 1/*i2b*/, 1/*i2c*/, 1/*i2s*/, 1/*lcmp*/, 1/*fcmpl*/, 1/*fcmpg*/,
690 1/*dcmpl*/, 1/*dcmpg*/, 0/*ifeq*/, 0/*ifne*/, 0/*iflt*/, 0/*ifge*/, 0/*ifgt*/, 0/*ifle*/,
691 0/*if_icmpeq*/, 0/*if_icmpne*/, 0/*if_icmplt*/, 0/*if_icmpge*/, 0/*if_icmpgt*/,
692 0/*if_icmple*/, 0/*if_acmpeq*/, 0/*if_acmpne*/, 0/*goto*/, 1/*jsr*/, 0/*ret*/,
693 0/*tableswitch*/, 0/*lookupswitch*/, 0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/,
694 0/*dreturn*/, 0/*areturn*/, 0/*return*/, UNPREDICTABLE/*getstatic*/, 0/*putstatic*/,
695 UNPREDICTABLE/*getfield*/, 0/*putfield*/, UNPREDICTABLE/*invokevirtual*/,
696 UNPREDICTABLE/*invokespecial*/, UNPREDICTABLE/*invokestatic*/,
697 UNPREDICTABLE/*invokeinterface*/, UNDEFINED, 1/*new*/, 1/*newarray*/, 1/*anewarray*/,
698 1/*arraylength*/, 1/*athrow*/, 1/*checkcast*/, 1/*instanceof*/, 0/*monitorenter*/,
699 0/*monitorexit*/, 0/*wide*/, 1/*multianewarray*/, 0/*ifnull*/, 0/*ifnonnull*/,
700 0/*goto_w*/, 1/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, UNDEFINED,
701 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
702 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
703 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
704 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
705 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
706 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
707 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
708 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
709 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
710 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
711 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
712 UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED,
713 UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/
714 };
715
716 /** Attributes and their corresponding names.
717 */
718 public static final byte ATTR_UNKNOWN = -1;
719 public static final byte ATTR_SOURCE_FILE = 0;
720 public static final byte ATTR_CONSTANT_VALUE = 1;
721 public static final byte ATTR_CODE = 2;
722 public static final byte ATTR_EXCEPTIONS = 3;
723 public static final byte ATTR_LINE_NUMBER_TABLE = 4;
724 public static final byte ATTR_LOCAL_VARIABLE_TABLE = 5;
725 public static final byte ATTR_INNER_CLASSES = 6;
726 public static final byte ATTR_SYNTHETIC = 7;
727 public static final byte ATTR_DEPRECATED = 8;
728 public static final byte ATTR_PMG = 9;
729 public static final byte ATTR_SIGNATURE = 10;
730 public static final byte ATTR_STACK_MAP = 11;
731 public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE = 12;
732 public static final byte ATTR_RUNTIMEVISIBLE_ANNOTATIONS = 13;
733 public static final byte ATTR_RUNTIMEINVISIBLE_ANNOTATIONS = 14;
734 public static final byte ATTR_RUNTIMEVISIBLE_PARAMETER_ANNOTATIONS = 15;
735 public static final byte ATTR_RUNTIMEINVISIBLE_PARAMETER_ANNOTATIONS = 16;
736 public static final byte ATTR_ANNOTATION_DEFAULT = 17;
737
738
739
740 public static final short KNOWN_ATTRIBUTES = 13;//should be 17
741
742 public static final String[] ATTRIBUTE_NAMES = {
743 "SourceFile", "ConstantValue", "Code", "Exceptions",
744 "LineNumberTable", "LocalVariableTable",
745 "InnerClasses", "Synthetic", "Deprecated",
746 "PMGClass", "Signature", "StackMap", "LocalVariableTypeTable",
747 "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
748 "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations",
749 "AnnotationDefault"
750 };
751
752 /** Constants used in the StackMap attribute.
753 */
754 public static final byte ITEM_Bogus = 0;
755 public static final byte ITEM_Integer = 1;
756 public static final byte ITEM_Float = 2;
757 public static final byte ITEM_Double = 3;
758 public static final byte ITEM_Long = 4;
759 public static final byte ITEM_Null = 5;
760 public static final byte ITEM_InitObject = 6;
761 public static final byte ITEM_Object = 7;
762 public static final byte ITEM_NewObject = 8;
763
764 public static final String[] ITEM_NAMES = {
765 "Bogus", "Integer", "Float", "Double", "Long",
766 "Null", "InitObject", "Object", "NewObject"
767 };
768 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/ExceptionConstants.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel;
17
18 /**
19 * Exception constants.
20 *
21 * @version $Id: ExceptionConstants.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author E. Haase
23 */
24 public interface ExceptionConstants {
25
26 /** The mother of all exceptions
27 */
28 public static final Class THROWABLE = Throwable.class;
29 /** Super class of any run-time exception
30 */
31 public static final Class RUNTIME_EXCEPTION = RuntimeException.class;
32 /** Super class of any linking exception (aka Linkage Error)
33 */
34 public static final Class LINKING_EXCEPTION = LinkageError.class;
35 /** Linking Exceptions
36 */
37 public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class;
38 public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class;
39 public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class;
40 public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class;
41 public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class;
42 public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class;
43 public static final Class INSTANTIATION_ERROR = InstantiationError.class;
44 public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class;
45 public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class;
46 public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class;
47 public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class;
48 public static final Class VERIFY_ERROR = VerifyError.class;
49 /* UnsupportedClassVersionError is new in JDK 1.2 */
50 //public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class;
51 /** Run-Time Exceptions
52 */
53 public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class;
54 public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class;
55 public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class;
56 public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class;
57 public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class;
58 public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class;
59 /** Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual
60 * Machine Specification
61 */
62 public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = {
63 NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR,
64 EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR
65 }; // Chapter 5.1
66 public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = {
67 NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR
68 }; // Chapter 5.2
69 public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below)
70 public static final Class[] EXCS_STRING_RESOLUTION = new Class[0];
71 // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
72 public static final Class[] EXCS_ARRAY_EXCEPTION = {
73 NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
74 };
75 }
+0
-261
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/Repository.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel;
17
18 import java.io.IOException;
19 import org.apache.bcel.classfile.JavaClass;
20 import org.apache.bcel.util.ClassPath;
21 import org.apache.bcel.util.SyntheticRepository;
22
23 /**
24 * The repository maintains informations about class interdependencies, e.g.,
25 * whether a class is a sub-class of another. Delegates actual class loading
26 * to SyntheticRepository with current class path by default.
27 *
28 * @see org.apache.bcel.util.Repository
29 * @see org.apache.bcel.util.SyntheticRepository
30 *
31 * @version $Id: Repository.java 386056 2006-03-15 11:31:56Z tcurdt $
32 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33 */
34 public abstract class Repository {
35
36 private static org.apache.bcel.util.Repository _repository = SyntheticRepository.getInstance();
37
38
39 /** @return currently used repository instance
40 */
41 public static org.apache.bcel.util.Repository getRepository() {
42 return _repository;
43 }
44
45
46 /** Set repository instance to be used for class loading
47 */
48 public static void setRepository( org.apache.bcel.util.Repository rep ) {
49 _repository = rep;
50 }
51
52
53 /** Lookup class somewhere found on your CLASSPATH, or whereever the
54 * repository instance looks for it.
55 *
56 * @return class object for given fully qualified class name
57 * @throws ClassNotFoundException if the class could not be found or
58 * parsed correctly
59 */
60 public static JavaClass lookupClass( String class_name ) throws ClassNotFoundException {
61 return _repository.loadClass(class_name);
62 }
63
64
65 /**
66 * Try to find class source using the internal repository instance.
67 * @see Class
68 * @return JavaClass object for given runtime class
69 * @throws ClassNotFoundException if the class could not be found or
70 * parsed correctly
71 */
72 public static JavaClass lookupClass( Class clazz ) throws ClassNotFoundException {
73 return _repository.loadClass(clazz);
74 }
75
76
77 /**
78 * @return class file object for given Java class by looking on the
79 * system class path; returns null if the class file can't be
80 * found
81 */
82 public static ClassPath.ClassFile lookupClassFile( String class_name ) {
83 try {
84 ClassPath path = _repository.getClassPath();
85 if (path == null) {
86 return null;
87 }
88 return path.getClassFile(class_name);
89 } catch (IOException e) {
90 return null;
91 }
92 }
93
94
95 /** Clear the repository.
96 */
97 public static void clearCache() {
98 _repository.clear();
99 }
100
101
102 /**
103 * Add clazz to repository if there isn't an equally named class already in there.
104 *
105 * @return old entry in repository
106 */
107 public static JavaClass addClass( JavaClass clazz ) {
108 JavaClass old = _repository.findClass(clazz.getClassName());
109 _repository.storeClass(clazz);
110 return old;
111 }
112
113
114 /**
115 * Remove class with given (fully qualified) name from repository.
116 */
117 public static void removeClass( String clazz ) {
118 _repository.removeClass(_repository.findClass(clazz));
119 }
120
121
122 /**
123 * Remove given class from repository.
124 */
125 public static void removeClass( JavaClass clazz ) {
126 _repository.removeClass(clazz);
127 }
128
129
130 /**
131 * @return list of super classes of clazz in ascending order, i.e.,
132 * Object is always the last element
133 * @throws ClassNotFoundException if any of the superclasses can't be found
134 */
135 public static JavaClass[] getSuperClasses( JavaClass clazz ) throws ClassNotFoundException {
136 return clazz.getSuperClasses();
137 }
138
139
140 /**
141 * @return list of super classes of clazz in ascending order, i.e.,
142 * Object is always the last element.
143 * @throws ClassNotFoundException if the named class or any of its
144 * superclasses can't be found
145 */
146 public static JavaClass[] getSuperClasses( String class_name ) throws ClassNotFoundException {
147 JavaClass jc = lookupClass(class_name);
148 return getSuperClasses(jc);
149 }
150
151
152 /**
153 * @return all interfaces implemented by class and its super
154 * classes and the interfaces that those interfaces extend, and so on.
155 * (Some people call this a transitive hull).
156 * @throws ClassNotFoundException if any of the class's
157 * superclasses or superinterfaces can't be found
158 */
159 public static JavaClass[] getInterfaces( JavaClass clazz ) throws ClassNotFoundException {
160 return clazz.getAllInterfaces();
161 }
162
163
164 /**
165 * @return all interfaces implemented by class and its super
166 * classes and the interfaces that extend those interfaces, and so on
167 * @throws ClassNotFoundException if the named class can't be found,
168 * or if any of its superclasses or superinterfaces can't be found
169 */
170 public static JavaClass[] getInterfaces( String class_name ) throws ClassNotFoundException {
171 return getInterfaces(lookupClass(class_name));
172 }
173
174
175 /**
176 * Equivalent to runtime "instanceof" operator.
177 * @return true, if clazz is an instance of super_class
178 * @throws ClassNotFoundException if any superclasses or superinterfaces
179 * of clazz can't be found
180 */
181 public static boolean instanceOf( JavaClass clazz, JavaClass super_class )
182 throws ClassNotFoundException {
183 return clazz.instanceOf(super_class);
184 }
185
186
187 /**
188 * @return true, if clazz is an instance of super_class
189 * @throws ClassNotFoundException if either clazz or super_class
190 * can't be found
191 */
192 public static boolean instanceOf( String clazz, String super_class )
193 throws ClassNotFoundException {
194 return instanceOf(lookupClass(clazz), lookupClass(super_class));
195 }
196
197
198 /**
199 * @return true, if clazz is an instance of super_class
200 * @throws ClassNotFoundException if super_class can't be found
201 */
202 public static boolean instanceOf( JavaClass clazz, String super_class )
203 throws ClassNotFoundException {
204 return instanceOf(clazz, lookupClass(super_class));
205 }
206
207
208 /**
209 * @return true, if clazz is an instance of super_class
210 * @throws ClassNotFoundException if clazz can't be found
211 */
212 public static boolean instanceOf( String clazz, JavaClass super_class )
213 throws ClassNotFoundException {
214 return instanceOf(lookupClass(clazz), super_class);
215 }
216
217
218 /**
219 * @return true, if clazz is an implementation of interface inter
220 * @throws ClassNotFoundException if any superclasses or superinterfaces
221 * of clazz can't be found
222 */
223 public static boolean implementationOf( JavaClass clazz, JavaClass inter )
224 throws ClassNotFoundException {
225 return clazz.implementationOf(inter);
226 }
227
228
229 /**
230 * @return true, if clazz is an implementation of interface inter
231 * @throws ClassNotFoundException if clazz, inter, or any superclasses
232 * or superinterfaces of clazz can't be found
233 */
234 public static boolean implementationOf( String clazz, String inter )
235 throws ClassNotFoundException {
236 return implementationOf(lookupClass(clazz), lookupClass(inter));
237 }
238
239
240 /**
241 * @return true, if clazz is an implementation of interface inter
242 * @throws ClassNotFoundException if inter or any superclasses
243 * or superinterfaces of clazz can't be found
244 */
245 public static boolean implementationOf( JavaClass clazz, String inter )
246 throws ClassNotFoundException {
247 return implementationOf(clazz, lookupClass(inter));
248 }
249
250
251 /**
252 * @return true, if clazz is an implementation of interface inter
253 * @throws ClassNotFoundException if clazz or any superclasses or
254 * superinterfaces of clazz can't be found
255 */
256 public static boolean implementationOf( String clazz, JavaClass inter )
257 throws ClassNotFoundException {
258 return implementationOf(lookupClass(clazz), inter);
259 }
260 }
+0
-187
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/AbstractLocalVariableTable.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents colection of local variables in a
25 * method. This attribute is contained in the <em>Code</em> attribute.
26 *
27 * @version $Id: bcel.diff,v 1.2 2007/08/14 03:33:02 wpugh Exp $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see Code
30 * @see LocalVariable
31 */
32 abstract public class AbstractLocalVariableTable extends Attribute {
33
34 private int local_variable_table_length; // Table of local
35 private LocalVariable[] local_variable_table; // variables
36
37
38 /**
39 * Initialize from another object. Note that both objects use the same
40 * references (shallow copy). Use copy() for a physical copy.
41 */
42 public AbstractLocalVariableTable(AbstractLocalVariableTable c) {
43 this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(), c.getConstantPool());
44 }
45
46
47 /**
48 * @param name_index Index in constant pool to `LocalVariableTable'
49 * @param length Content length in bytes
50 * @param local_variable_table Table of local variables
51 * @param constant_pool Array of constants
52 */
53 public AbstractLocalVariableTable(int name_index, int length, LocalVariable[] local_variable_table,
54 ConstantPool constant_pool) {
55 super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool);
56 setLocalVariableTable(local_variable_table);
57 }
58
59
60 /**
61 * Construct object from file stream.
62 * @param name_index Index in constant pool
63 * @param length Content length in bytes
64 * @param file Input stream
65 * @param constant_pool Array of constants
66 * @throws IOException
67 */
68 AbstractLocalVariableTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
69 throws IOException {
70 this(name_index, length, (LocalVariable[]) null, constant_pool);
71 local_variable_table_length = (file.readUnsignedShort());
72 local_variable_table = new LocalVariable[local_variable_table_length];
73 for (int i = 0; i < local_variable_table_length; i++) {
74 local_variable_table[i] = new LocalVariable(file, constant_pool);
75 }
76 }
77
78
79
80
81 /**
82 * Dump local variable table attribute to file stream in binary format.
83 *
84 * @param file Output file stream
85 * @throws IOException
86 */
87 public final void dump( DataOutputStream file ) throws IOException {
88 super.dump(file);
89 file.writeShort(local_variable_table_length);
90 for (int i = 0; i < local_variable_table_length; i++) {
91 local_variable_table[i].dump(file);
92 }
93 }
94
95
96 /**
97 * @return Array of local variables of method.
98 */
99 public final LocalVariable[] getLocalVariableTable() {
100 return local_variable_table;
101 }
102
103
104 /**
105 * @return first matching variable using index
106 *
107 * @param index the variable slot
108 *
109 * @return the first LocalVariable that matches the slot or null if not found
110 *
111 * @deprecated since 5.2 because multiple variables can share the
112 * same slot, use getLocalVariable(int index, int pc) instead.
113 */
114 public final LocalVariable getLocalVariable( int index ) {
115 for (int i = 0; i < local_variable_table_length; i++) {
116 if (local_variable_table[i].getIndex() == index) {
117 return local_variable_table[i];
118 }
119 }
120 return null;
121 }
122
123
124 /**
125 * @return matching variable using index when variable is used at supplied pc
126 *
127 * @param index the variable slot
128 * @param pc the current pc that this variable is alive
129 *
130 * @return the LocalVariable that matches or null if not found
131 */
132 public final LocalVariable getLocalVariable( int index, int pc ) {
133 for (int i = 0; i < local_variable_table_length; i++) {
134 if (local_variable_table[i].getIndex() == index) {
135 int start_pc = local_variable_table[i].getStartPC();
136 int end_pc = start_pc + local_variable_table[i].getLength();
137 if ((pc >= start_pc) && (pc < end_pc)) {
138 return local_variable_table[i];
139 }
140 }
141 }
142 return null;
143 }
144
145
146 public final void setLocalVariableTable( LocalVariable[] local_variable_table ) {
147 this.local_variable_table = local_variable_table;
148 local_variable_table_length = (local_variable_table == null)
149 ? 0
150 : local_variable_table.length;
151 }
152
153
154 /**
155 * @return String representation.
156 */
157 public final String toString() {
158 StringBuffer buf = new StringBuffer("");
159 for (int i = 0; i < local_variable_table_length; i++) {
160 buf.append(local_variable_table[i].toString());
161 if (i < local_variable_table_length - 1) {
162 buf.append('\n');
163 }
164 }
165 return buf.toString();
166 }
167
168
169 /**
170 * @return deep copy of this attribute
171 */
172 public Attribute copy( ConstantPool _constant_pool ) {
173 AbstractLocalVariableTable c = (AbstractLocalVariableTable) clone();
174 c.local_variable_table = new LocalVariable[local_variable_table_length];
175 for (int i = 0; i < local_variable_table_length; i++) {
176 c.local_variable_table[i] = local_variable_table[i].copy();
177 }
178 c.constant_pool = _constant_pool;
179 return c;
180 }
181
182
183 public final int getTableLength() {
184 return local_variable_table_length;
185 }
186 }
+0
-238
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/AccessFlags.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Super class for all objects that have modifiers like private, final, ...
22 * I.e. classes, fields, and methods.
23 *
24 * @version $Id: AccessFlags.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public abstract class AccessFlags implements java.io.Serializable {
28
29 protected int access_flags;
30
31
32 public AccessFlags() {
33 }
34
35
36 /**
37 * @param a inital access flags
38 */
39 public AccessFlags(int a) {
40 access_flags = a;
41 }
42
43
44 /**
45 * @return Access flags of the object aka. "modifiers".
46 */
47 public final int getAccessFlags() {
48 return access_flags;
49 }
50
51
52 /**
53 * @return Access flags of the object aka. "modifiers".
54 */
55 public final int getModifiers() {
56 return access_flags;
57 }
58
59
60 /** Set access flags aka "modifiers".
61 * @param access_flags Access flags of the object.
62 */
63 public final void setAccessFlags( int access_flags ) {
64 this.access_flags = access_flags;
65 }
66
67
68 /** Set access flags aka "modifiers".
69 * @param access_flags Access flags of the object.
70 */
71 public final void setModifiers( int access_flags ) {
72 setAccessFlags(access_flags);
73 }
74
75
76 private final void setFlag( int flag, boolean set ) {
77 if ((access_flags & flag) != 0) { // Flag is set already
78 if (!set) {
79 access_flags ^= flag;
80 }
81 } else { // Flag not set
82 if (set) {
83 access_flags |= flag;
84 }
85 }
86 }
87
88
89 public final void isPublic( boolean flag ) {
90 setFlag(Constants.ACC_PUBLIC, flag);
91 }
92
93
94 public final boolean isPublic() {
95 return (access_flags & Constants.ACC_PUBLIC) != 0;
96 }
97
98
99 public final void isPrivate( boolean flag ) {
100 setFlag(Constants.ACC_PRIVATE, flag);
101 }
102
103
104 public final boolean isPrivate() {
105 return (access_flags & Constants.ACC_PRIVATE) != 0;
106 }
107
108
109 public final void isProtected( boolean flag ) {
110 setFlag(Constants.ACC_PROTECTED, flag);
111 }
112
113
114 public final boolean isProtected() {
115 return (access_flags & Constants.ACC_PROTECTED) != 0;
116 }
117
118
119 public final void isStatic( boolean flag ) {
120 setFlag(Constants.ACC_STATIC, flag);
121 }
122
123
124 public final boolean isStatic() {
125 return (access_flags & Constants.ACC_STATIC) != 0;
126 }
127
128
129 public final void isFinal( boolean flag ) {
130 setFlag(Constants.ACC_FINAL, flag);
131 }
132
133
134 public final boolean isFinal() {
135 return (access_flags & Constants.ACC_FINAL) != 0;
136 }
137
138
139 public final void isSynchronized( boolean flag ) {
140 setFlag(Constants.ACC_SYNCHRONIZED, flag);
141 }
142
143
144 public final boolean isSynchronized() {
145 return (access_flags & Constants.ACC_SYNCHRONIZED) != 0;
146 }
147
148
149 public final void isVolatile( boolean flag ) {
150 setFlag(Constants.ACC_VOLATILE, flag);
151 }
152
153
154 public final boolean isVolatile() {
155 return (access_flags & Constants.ACC_VOLATILE) != 0;
156 }
157
158
159 public final void isTransient( boolean flag ) {
160 setFlag(Constants.ACC_TRANSIENT, flag);
161 }
162
163
164 public final boolean isTransient() {
165 return (access_flags & Constants.ACC_TRANSIENT) != 0;
166 }
167
168
169 public final void isNative( boolean flag ) {
170 setFlag(Constants.ACC_NATIVE, flag);
171 }
172
173
174 public final boolean isNative() {
175 return (access_flags & Constants.ACC_NATIVE) != 0;
176 }
177
178
179 public final void isInterface( boolean flag ) {
180 setFlag(Constants.ACC_INTERFACE, flag);
181 }
182
183
184 public final boolean isInterface() {
185 return (access_flags & Constants.ACC_INTERFACE) != 0;
186 }
187
188
189 public final void isAbstract( boolean flag ) {
190 setFlag(Constants.ACC_ABSTRACT, flag);
191 }
192
193
194 public final boolean isAbstract() {
195 return (access_flags & Constants.ACC_ABSTRACT) != 0;
196 }
197
198
199 public final void isStrictfp( boolean flag ) {
200 setFlag(Constants.ACC_STRICT, flag);
201 }
202
203
204 public final boolean isStrictfp() {
205 return (access_flags & Constants.ACC_STRICT) != 0;
206 }
207
208
209 public final void isSynthetic( boolean flag ) {
210 setFlag(Constants.ACC_SYNTHETIC, flag);
211 }
212
213
214 public final boolean isSynthetic() {
215 return (access_flags & Constants.ACC_SYNTHETIC) != 0;
216 }
217
218
219 public final void isAnnotation( boolean flag ) {
220 setFlag(Constants.ACC_ANNOTATION, flag);
221 }
222
223
224 public final boolean isAnnotation() {
225 return (access_flags & Constants.ACC_ANNOTATION) != 0;
226 }
227
228
229 public final void isEnum( boolean flag ) {
230 setFlag(Constants.ACC_ENUM, flag);
231 }
232
233
234 public final boolean isEnum() {
235 return (access_flags & Constants.ACC_ENUM) != 0;
236 }
237 }
+0
-280
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Attribute.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import java.util.HashMap;
23 import java.util.Map;
24 import org.apache.bcel.Constants;
25
26 /**
27 * Abstract super class for <em>Attribute</em> objects. Currently the
28 * <em>ConstantValue</em>, <em>SourceFile</em>, <em>Code</em>,
29 * <em>Exceptiontable</em>, <em>LineNumberTable</em>,
30 * <em>LocalVariableTable</em>, <em>InnerClasses</em> and
31 * <em>Synthetic</em> attributes are supported. The
32 * <em>Unknown</em> attribute stands for non-standard-attributes.
33 *
34 * @version $Id: Attribute.java 386056 2006-03-15 11:31:56Z tcurdt $
35 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36 * @see ConstantValue
37 * @see SourceFile
38 * @see Code
39 * @see Unknown
40 * @see ExceptionTable
41 * @see LineNumberTable
42 * @see LocalVariableTable
43 * @see InnerClasses
44 * @see Synthetic
45 * @see Deprecated
46 * @see Signature
47 */
48 public abstract class Attribute implements Cloneable, Node, Serializable {
49
50 protected int name_index; // Points to attribute name in constant pool
51 protected int length; // Content length of attribute field
52 protected byte tag; // Tag to distiguish subclasses
53 protected ConstantPool constant_pool;
54
55
56 protected Attribute(byte tag, int name_index, int length, ConstantPool constant_pool) {
57 this.tag = tag;
58 this.name_index = name_index;
59 this.length = length;
60 this.constant_pool = constant_pool;
61 }
62
63
64 /**
65 * Called by objects that are traversing the nodes of the tree implicitely
66 * defined by the contents of a Java class. I.e., the hierarchy of methods,
67 * fields, attributes, etc. spawns a tree of objects.
68 *
69 * @param v Visitor object
70 */
71 public abstract void accept( Visitor v );
72
73
74 /**
75 * Dump attribute to file stream in binary format.
76 *
77 * @param file Output file stream
78 * @throws IOException
79 */
80 public void dump( DataOutputStream file ) throws IOException {
81 file.writeShort(name_index);
82 file.writeInt(length);
83 }
84
85 private static Map readers = new HashMap();
86
87
88 /** Add an Attribute reader capable of parsing (user-defined) attributes
89 * named "name". You should not add readers for the standard attributes
90 * such as "LineNumberTable", because those are handled internally.
91 *
92 * @param name the name of the attribute as stored in the class file
93 * @param r the reader object
94 */
95 public static void addAttributeReader( String name, AttributeReader r ) {
96 readers.put(name, r);
97 }
98
99
100 /** Remove attribute reader
101 *
102 * @param name the name of the attribute as stored in the class file
103 */
104 public static void removeAttributeReader( String name ) {
105 readers.remove(name);
106 }
107
108
109 /* Class method reads one attribute from the input data stream.
110 * This method must not be accessible from the outside. It is
111 * called by the Field and Method constructor methods.
112 *
113 * @see Field
114 * @see Method
115 * @param file Input stream
116 * @param constant_pool Array of constants
117 * @return Attribute
118 * @throws IOException
119 * @throws ClassFormatException
120 */
121 public static final Attribute readAttribute( DataInputStream file, ConstantPool constant_pool )
122 throws IOException, ClassFormatException {
123 ConstantUtf8 c;
124 String name;
125 int name_index;
126 int length;
127 byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute
128 // Get class name from constant pool via `name_index' indirection
129 name_index = file.readUnsignedShort();
130 c = (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
131 name = c.getBytes();
132 // Length of data in bytes
133 length = file.readInt();
134 // Compare strings to find known attribute
135 for (byte i = 0; i < Constants.KNOWN_ATTRIBUTES; i++) {
136 if (name.equals(Constants.ATTRIBUTE_NAMES[i])) {
137 tag = i; // found!
138 break;
139 }
140 }
141 // Call proper constructor, depending on `tag'
142 switch (tag) {
143 case Constants.ATTR_UNKNOWN:
144 AttributeReader r = (AttributeReader) readers.get(name);
145 if (r != null) {
146 return r.createAttribute(name_index, length, file, constant_pool);
147 }
148 return new Unknown(name_index, length, file, constant_pool);
149 case Constants.ATTR_CONSTANT_VALUE:
150 return new ConstantValue(name_index, length, file, constant_pool);
151 case Constants.ATTR_SOURCE_FILE:
152 return new SourceFile(name_index, length, file, constant_pool);
153 case Constants.ATTR_CODE:
154 return new Code(name_index, length, file, constant_pool);
155 case Constants.ATTR_EXCEPTIONS:
156 return new ExceptionTable(name_index, length, file, constant_pool);
157 case Constants.ATTR_LINE_NUMBER_TABLE:
158 return new LineNumberTable(name_index, length, file, constant_pool);
159 case Constants.ATTR_LOCAL_VARIABLE_TABLE:
160 return new LocalVariableTable(name_index, length, file, constant_pool);
161 case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
162 return new LocalVariableTypeTable(name_index, length, file, constant_pool);
163 case Constants.ATTR_INNER_CLASSES:
164 return new InnerClasses(name_index, length, file, constant_pool);
165 case Constants.ATTR_SYNTHETIC:
166 return new Synthetic(name_index, length, file, constant_pool);
167 case Constants.ATTR_DEPRECATED:
168 return new Deprecated(name_index, length, file, constant_pool);
169 case Constants.ATTR_PMG:
170 return new PMGClass(name_index, length, file, constant_pool);
171 case Constants.ATTR_SIGNATURE:
172 return new Signature(name_index, length, file, constant_pool);
173 case Constants.ATTR_STACK_MAP:
174 return new StackMap(name_index, length, file, constant_pool);
175 // case Constants.ATTR_RUNTIMEVISIBLE_ANNOTATIONS:
176 // return new RuntimeVisibleAnnotations(name_index, length, file, constant_pool);
177 // case Constants.ATTR_RUNTIMEINVISIBLE_ANNOTATIONS:
178 // return new RuntimeInvisibleAnnotations(name_index, length, file, constant_pool);
179 // case Constants.ATTR_RUNTIMEVISIBLE_PARAMETER_ANNOTATIONS:
180 // return new RuntimeVisibleParameterAnnotations(name_index, length, file, constant_pool);
181 // case Constants.ATTR_RUNTIMEINVISIBLE_PARAMETER_ANNOTATIONS:
182 // return new RuntimeInvisibleParameterAnnotations(name_index, length, file, constant_pool);
183 // case Constants.ATTR_ANNOTATION_DEFAULT:
184 // return new AnnotationDefault(name_index, length, file, constant_pool);
185 default: // Never reached
186 throw new IllegalStateException("Ooops! default case reached.");
187 }
188 }
189
190
191 /**
192 * @return Length of attribute field in bytes.
193 */
194 public final int getLength() {
195 return length;
196 }
197
198
199 /**
200 * @param length length in bytes.
201 */
202 public final void setLength( int length ) {
203 this.length = length;
204 }
205
206
207 /**
208 * @param name_index of attribute.
209 */
210 public final void setNameIndex( int name_index ) {
211 this.name_index = name_index;
212 }
213
214
215 /**
216 * @return Name index in constant pool of attribute name.
217 */
218 public final int getNameIndex() {
219 return name_index;
220 }
221
222
223 /**
224 * @return Tag of attribute, i.e., its type. Value may not be altered, thus
225 * there is no setTag() method.
226 */
227 public final byte getTag() {
228 return tag;
229 }
230
231
232 /**
233 * @return Constant pool used by this object.
234 * @see ConstantPool
235 */
236 public final ConstantPool getConstantPool() {
237 return constant_pool;
238 }
239
240
241 /**
242 * @param constant_pool Constant pool to be used for this object.
243 * @see ConstantPool
244 */
245 public final void setConstantPool( ConstantPool constant_pool ) {
246 this.constant_pool = constant_pool;
247 }
248
249
250 /**
251 * Use copy() if you want to have a deep copy(), i.e., with all references
252 * copied correctly.
253 *
254 * @return shallow copy of this attribute
255 */
256 public Object clone() {
257 Object o = null;
258 try {
259 o = super.clone();
260 } catch (CloneNotSupportedException e) {
261 e.printStackTrace(); // Never occurs
262 }
263 return o;
264 }
265
266
267 /**
268 * @return deep copy of this attribute
269 */
270 public abstract Attribute copy( ConstantPool _constant_pool );
271
272
273 /**
274 * @return attribute name.
275 */
276 public String toString() {
277 return Constants.ATTRIBUTE_NAMES[tag];
278 }
279 }
+0
-58
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/AttributeReader.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * Unknown (non-standard) attributes may be read via user-defined factory
20 * objects that can be registered with the Attribute.addAttributeReader
21 * method. These factory objects should implement this interface.
22
23 * @see Attribute
24 * @version $Id: AttributeReader.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public interface AttributeReader {
28
29 /**
30 When this attribute reader is added via the static method
31 Attribute.addAttributeReader, an attribute name is associated with it.
32 As the class file parser parses attributes, it will call various
33 AttributeReaders based on the name of the attributes it is
34 constructing.
35
36 @param name_index An index into the constant pool, indexing a
37 ConstantUtf8 that represents the name of the attribute.
38
39 @param length The length of the data contained in the attribute. This
40 is written into the constant pool and should agree with what the
41 factory expects the length to be.
42
43 @param file This is the data input stream that the factory needs to read
44 its data from.
45
46 @param constant_pool This is the constant pool associated with the
47 Attribute that we are constructing.
48
49 @return The user-defined AttributeReader should take this data and use
50 it to construct an attribute. In the case of errors, a null can be
51 returned which will cause the parsing of the class file to fail.
52
53 @see Attribute#addAttributeReader( String, AttributeReader )
54 */
55 public Attribute createAttribute( int name_index, int length, java.io.DataInputStream file,
56 ConstantPool constant_pool );
57 }
+0
-37
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ClassFormatException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * Thrown when the BCEL attempts to read a class file and determines
20 * that the file is malformed or otherwise cannot be interpreted as a
21 * class file.
22 *
23 * @version $Id: ClassFormatException.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class ClassFormatException extends RuntimeException {
27
28 public ClassFormatException() {
29 super();
30 }
31
32
33 public ClassFormatException(String s) {
34 super(s);
35 }
36 }
+0
-295
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ClassParser.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.BufferedInputStream;
19 import java.io.DataInputStream;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.zip.ZipEntry;
24 import java.util.zip.ZipFile;
25 import org.apache.bcel.Constants;
26
27 /**
28 * Wrapper class that parses a given Java .class file. The method <A
29 * href ="#parse">parse</A> returns a <A href ="JavaClass.html">
30 * JavaClass</A> object on success. When an I/O error or an
31 * inconsistency occurs an appropiate exception is propagated back to
32 * the caller.
33 *
34 * The structure and the names comply, except for a few conveniences,
35 * exactly with the <A href="ftp://java.sun.com/docs/specs/vmspec.ps">
36 * JVM specification 1.0</a>. See this paper for
37 * further details about the structure of a bytecode file.
38 *
39 * @version $Id: ClassParser.java 386056 2006-03-15 11:31:56Z tcurdt $
40 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
41 */
42 public final class ClassParser {
43
44 private DataInputStream file;
45 private boolean fileOwned;
46 private String file_name;
47 private String zip_file;
48 private int class_name_index, superclass_name_index;
49 private int major, minor; // Compiler version
50 private int access_flags; // Access rights of parsed class
51 private int[] interfaces; // Names of implemented interfaces
52 private ConstantPool constant_pool; // collection of constants
53 private Field[] fields; // class fields, i.e., its variables
54 private Method[] methods; // methods defined in the class
55 private Attribute[] attributes; // attributes defined in the class
56 private boolean is_zip; // Loaded from zip file
57 private static final int BUFSIZE = 8192;
58
59
60 /**
61 * Parse class from the given stream.
62 *
63 * @param file Input stream
64 * @param file_name File name
65 */
66 public ClassParser(InputStream file, String file_name) {
67 this.file_name = file_name;
68 fileOwned = false;
69 String clazz = file.getClass().getName(); // Not a very clean solution ...
70 is_zip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar.");
71 if (file instanceof DataInputStream) {
72 this.file = (DataInputStream) file;
73 } else {
74 this.file = new DataInputStream(new BufferedInputStream(file, BUFSIZE));
75 }
76 }
77
78
79 /** Parse class from given .class file.
80 *
81 * @param file_name file name
82 */
83 public ClassParser(String file_name) throws IOException {
84 is_zip = false;
85 this.file_name = file_name;
86 fileOwned = true;
87 }
88
89
90 /** Parse class from given .class file in a ZIP-archive
91 *
92 * @param zip_file zip file name
93 * @param file_name file name
94 */
95 public ClassParser(String zip_file, String file_name) {
96 is_zip = true;
97 fileOwned = true;
98 this.zip_file = zip_file;
99 this.file_name = file_name;
100 }
101
102
103 /**
104 * Parse the given Java class file and return an object that represents
105 * the contained data, i.e., constants, methods, fields and commands.
106 * A <em>ClassFormatException</em> is raised, if the file is not a valid
107 * .class file. (This does not include verification of the byte code as it
108 * is performed by the java interpreter).
109 *
110 * @return Class object representing the parsed class file
111 * @throws IOException
112 * @throws ClassFormatException
113 */
114 public JavaClass parse() throws IOException, ClassFormatException {
115 ZipFile zip = null;
116 try {
117 if (fileOwned) {
118 if (is_zip) {
119 zip = new ZipFile(zip_file);
120 ZipEntry entry = zip.getEntry(file_name);
121 file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry),
122 BUFSIZE));
123 } else {
124 file = new DataInputStream(new BufferedInputStream(new FileInputStream(
125 file_name), BUFSIZE));
126 }
127 }
128 /****************** Read headers ********************************/
129 // Check magic tag of class file
130 readID();
131 // Get compiler version
132 readVersion();
133 /****************** Read constant pool and related **************/
134 // Read constant pool entries
135 readConstantPool();
136 // Get class information
137 readClassInfo();
138 // Get interface information, i.e., implemented interfaces
139 readInterfaces();
140 /****************** Read class fields and methods ***************/
141 // Read class fields, i.e., the variables of the class
142 readFields();
143 // Read class methods, i.e., the functions in the class
144 readMethods();
145 // Read class attributes
146 readAttributes();
147 // Check for unknown variables
148 //Unknown[] u = Unknown.getUnknownAttributes();
149 //for(int i=0; i < u.length; i++)
150 // System.err.println("WARNING: " + u[i]);
151 // Everything should have been read now
152 // if(file.available() > 0) {
153 // int bytes = file.available();
154 // byte[] buf = new byte[bytes];
155 // file.read(buf);
156 // if(!(is_zip && (buf.length == 1))) {
157 // System.err.println("WARNING: Trailing garbage at end of " + file_name);
158 // System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf));
159 // }
160 // }
161 } finally {
162 // Read everything of interest, so close the file
163 if (fileOwned) {
164 file.close();
165 if (zip != null) {
166 zip.close();
167 }
168 }
169 }
170 // Return the information we have gathered in a new object
171 return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
172 access_flags, constant_pool, interfaces, fields, methods, attributes, is_zip
173 ? JavaClass.ZIP
174 : JavaClass.FILE);
175 }
176
177
178 /**
179 * Read information about the attributes of the class.
180 * @throws IOException
181 * @throws ClassFormatException
182 */
183 private final void readAttributes() throws IOException, ClassFormatException {
184 int attributes_count;
185 attributes_count = file.readUnsignedShort();
186 attributes = new Attribute[attributes_count];
187 for (int i = 0; i < attributes_count; i++) {
188 attributes[i] = Attribute.readAttribute(file, constant_pool);
189 }
190 }
191
192
193 /**
194 * Read information about the class and its super class.
195 * @throws IOException
196 * @throws ClassFormatException
197 */
198 private final void readClassInfo() throws IOException, ClassFormatException {
199 access_flags = file.readUnsignedShort();
200 /* Interfaces are implicitely abstract, the flag should be set
201 * according to the JVM specification.
202 */
203 if ((access_flags & Constants.ACC_INTERFACE) != 0) {
204 access_flags |= Constants.ACC_ABSTRACT;
205 }
206 if (((access_flags & Constants.ACC_ABSTRACT) != 0)
207 && ((access_flags & Constants.ACC_FINAL) != 0)) {
208 throw new ClassFormatException("Class can't be both final and abstract");
209 }
210 class_name_index = file.readUnsignedShort();
211 superclass_name_index = file.readUnsignedShort();
212 }
213
214
215 /**
216 * Read constant pool entries.
217 * @throws IOException
218 * @throws ClassFormatException
219 */
220 private final void readConstantPool() throws IOException, ClassFormatException {
221 constant_pool = new ConstantPool(file);
222 }
223
224
225 /**
226 * Read information about the fields of the class, i.e., its variables.
227 * @throws IOException
228 * @throws ClassFormatException
229 */
230 private final void readFields() throws IOException, ClassFormatException {
231 int fields_count;
232 fields_count = file.readUnsignedShort();
233 fields = new Field[fields_count];
234 for (int i = 0; i < fields_count; i++) {
235 fields[i] = new Field(file, constant_pool);
236 }
237 }
238
239
240 /******************** Private utility methods **********************/
241 /**
242 * Check whether the header of the file is ok.
243 * Of course, this has to be the first action on successive file reads.
244 * @throws IOException
245 * @throws ClassFormatException
246 */
247 private final void readID() throws IOException, ClassFormatException {
248 int magic = 0xCAFEBABE;
249 if (file.readInt() != magic) {
250 throw new ClassFormatException(file_name + " is not a Java .class file");
251 }
252 }
253
254
255 /**
256 * Read information about the interfaces implemented by this class.
257 * @throws IOException
258 * @throws ClassFormatException
259 */
260 private final void readInterfaces() throws IOException, ClassFormatException {
261 int interfaces_count;
262 interfaces_count = file.readUnsignedShort();
263 interfaces = new int[interfaces_count];
264 for (int i = 0; i < interfaces_count; i++) {
265 interfaces[i] = file.readUnsignedShort();
266 }
267 }
268
269
270 /**
271 * Read information about the methods of the class.
272 * @throws IOException
273 * @throws ClassFormatException
274 */
275 private final void readMethods() throws IOException, ClassFormatException {
276 int methods_count;
277 methods_count = file.readUnsignedShort();
278 methods = new Method[methods_count];
279 for (int i = 0; i < methods_count; i++) {
280 methods[i] = new Method(file, constant_pool);
281 }
282 }
283
284
285 /**
286 * Read major and minor version of compiler which created the file.
287 * @throws IOException
288 * @throws ClassFormatException
289 */
290 private final void readVersion() throws IOException, ClassFormatException {
291 minor = file.readUnsignedShort();
292 major = file.readUnsignedShort();
293 }
294 }
+0
-352
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Code.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents a chunk of Java byte code contained in a
25 * method. It is instantiated by the
26 * <em>Attribute.readAttribute()</em> method. A <em>Code</em>
27 * attribute contains informations about operand stack, local
28 * variables, byte code and the exceptions handled within this
29 * method.
30 *
31 * This attribute has attributes itself, namely <em>LineNumberTable</em> which
32 * is used for debugging purposes and <em>LocalVariableTable</em> which
33 * contains information about the local variables.
34 *
35 * @version $Id: Code.java 386056 2006-03-15 11:31:56Z tcurdt $
36 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
37 * @see Attribute
38 * @see CodeException
39 * @see LineNumberTable
40 * @see LocalVariableTable
41 */
42 public final class Code extends Attribute {
43
44 private int max_stack; // Maximum size of stack used by this method
45 private int max_locals; // Number of local variables
46 private int code_length; // Length of code in bytes
47 private byte[] code; // Actual byte code
48 private int exception_table_length;
49 private CodeException[] exception_table; // Table of handled exceptions
50 private int attributes_count; // Attributes of code: LineNumber
51 private Attribute[] attributes; // or LocalVariable
52
53
54 /**
55 * Initialize from another object. Note that both objects use the same
56 * references (shallow copy). Use copy() for a physical copy.
57 */
58 public Code(Code c) {
59 this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), c.getCode(), c
60 .getExceptionTable(), c.getAttributes(), c.getConstantPool());
61 }
62
63
64 /**
65 * @param name_index Index pointing to the name <em>Code</em>
66 * @param length Content length in bytes
67 * @param file Input stream
68 * @param constant_pool Array of constants
69 */
70 Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
71 throws IOException {
72 // Initialize with some default values which will be overwritten later
73 this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), (byte[]) null,
74 (CodeException[]) null, (Attribute[]) null, constant_pool);
75 code_length = file.readInt();
76 code = new byte[code_length]; // Read byte code
77 file.readFully(code);
78 /* Read exception table that contains all regions where an exception
79 * handler is active, i.e., a try { ... } catch() block.
80 */
81 exception_table_length = file.readUnsignedShort();
82 exception_table = new CodeException[exception_table_length];
83 for (int i = 0; i < exception_table_length; i++) {
84 exception_table[i] = new CodeException(file);
85 }
86 /* Read all attributes, currently `LineNumberTable' and
87 * `LocalVariableTable'
88 */
89 attributes_count = file.readUnsignedShort();
90 attributes = new Attribute[attributes_count];
91 for (int i = 0; i < attributes_count; i++) {
92 attributes[i] = Attribute.readAttribute(file, constant_pool);
93 }
94 /* Adjust length, because of setAttributes in this(), s.b. length
95 * is incorrect, because it didn't take the internal attributes
96 * into account yet! Very subtle bug, fixed in 3.1.1.
97 */
98 this.length = length;
99 }
100
101
102 /**
103 * @param name_index Index pointing to the name <em>Code</em>
104 * @param length Content length in bytes
105 * @param max_stack Maximum size of stack
106 * @param max_locals Number of local variables
107 * @param code Actual byte code
108 * @param exception_table Table of handled exceptions
109 * @param attributes Attributes of code: LineNumber or LocalVariable
110 * @param constant_pool Array of constants
111 */
112 public Code(int name_index, int length, int max_stack, int max_locals, byte[] code,
113 CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) {
114 super(Constants.ATTR_CODE, name_index, length, constant_pool);
115 this.max_stack = max_stack;
116 this.max_locals = max_locals;
117 setCode(code);
118 setExceptionTable(exception_table);
119 setAttributes(attributes); // Overwrites length!
120 }
121
122
123 /**
124 * Called by objects that are traversing the nodes of the tree implicitely
125 * defined by the contents of a Java class. I.e., the hierarchy of methods,
126 * fields, attributes, etc. spawns a tree of objects.
127 *
128 * @param v Visitor object
129 */
130 public void accept( Visitor v ) {
131 v.visitCode(this);
132 }
133
134
135 /**
136 * Dump code attribute to file stream in binary format.
137 *
138 * @param file Output file stream
139 * @throws IOException
140 */
141 public final void dump( DataOutputStream file ) throws IOException {
142 super.dump(file);
143 file.writeShort(max_stack);
144 file.writeShort(max_locals);
145 file.writeInt(code_length);
146 file.write(code, 0, code_length);
147 file.writeShort(exception_table_length);
148 for (int i = 0; i < exception_table_length; i++) {
149 exception_table[i].dump(file);
150 }
151 file.writeShort(attributes_count);
152 for (int i = 0; i < attributes_count; i++) {
153 attributes[i].dump(file);
154 }
155 }
156
157
158 /**
159 * @return Collection of code attributes.
160 * @see Attribute
161 */
162 public final Attribute[] getAttributes() {
163 return attributes;
164 }
165
166
167 /**
168 * @return LineNumberTable of Code, if it has one
169 */
170 public LineNumberTable getLineNumberTable() {
171 for (int i = 0; i < attributes_count; i++) {
172 if (attributes[i] instanceof LineNumberTable) {
173 return (LineNumberTable) attributes[i];
174 }
175 }
176 return null;
177 }
178
179
180 /**
181 * @return LocalVariableTable of Code, if it has one
182 */
183 public LocalVariableTable getLocalVariableTable() {
184 for (int i = 0; i < attributes_count; i++) {
185 if (attributes[i] instanceof LocalVariableTable) {
186 return (LocalVariableTable) attributes[i];
187 }
188 }
189 return null;
190 }
191
192
193 /**
194 * @return Actual byte code of the method.
195 */
196 public final byte[] getCode() {
197 return code;
198 }
199
200
201 /**
202 * @return Table of handled exceptions.
203 * @see CodeException
204 */
205 public final CodeException[] getExceptionTable() {
206 return exception_table;
207 }
208
209
210 /**
211 * @return Number of local variables.
212 */
213 public final int getMaxLocals() {
214 return max_locals;
215 }
216
217
218 /**
219 * @return Maximum size of stack used by this method.
220 */
221 public final int getMaxStack() {
222 return max_stack;
223 }
224
225
226 /**
227 * @return the internal length of this code attribute (minus the first 6 bytes)
228 * and excluding all its attributes
229 */
230 private final int getInternalLength() {
231 return 2 /*max_stack*/+ 2 /*max_locals*/+ 4 /*code length*/
232 + code_length /*byte-code*/
233 + 2 /*exception-table length*/
234 + 8 * exception_table_length /* exception table */
235 + 2 /* attributes count */;
236 }
237
238
239 /**
240 * @return the full size of this code attribute, minus its first 6 bytes,
241 * including the size of all its contained attributes
242 */
243 private final int calculateLength() {
244 int len = 0;
245 for (int i = 0; i < attributes_count; i++) {
246 len += attributes[i].length + 6 /*attribute header size*/;
247 }
248 return len + getInternalLength();
249 }
250
251
252 /**
253 * @param attributes the attributes to set for this Code
254 */
255 public final void setAttributes( Attribute[] attributes ) {
256 this.attributes = attributes;
257 attributes_count = (attributes == null) ? 0 : attributes.length;
258 length = calculateLength(); // Adjust length
259 }
260
261
262 /**
263 * @param code byte code
264 */
265 public final void setCode( byte[] code ) {
266 this.code = code;
267 code_length = (code == null) ? 0 : code.length;
268 }
269
270
271 /**
272 * @param exception_table exception table
273 */
274 public final void setExceptionTable( CodeException[] exception_table ) {
275 this.exception_table = exception_table;
276 exception_table_length = (exception_table == null) ? 0 : exception_table.length;
277 }
278
279
280 /**
281 * @param max_locals maximum number of local variables
282 */
283 public final void setMaxLocals( int max_locals ) {
284 this.max_locals = max_locals;
285 }
286
287
288 /**
289 * @param max_stack maximum stack size
290 */
291 public final void setMaxStack( int max_stack ) {
292 this.max_stack = max_stack;
293 }
294
295
296 /**
297 * @return String representation of code chunk.
298 */
299 public final String toString( boolean verbose ) {
300 StringBuffer buf;
301 buf = new StringBuffer(100);
302 buf.append("Code(max_stack = ").append(max_stack).append(", max_locals = ").append(
303 max_locals).append(", code_length = ").append(code_length).append(")\n").append(
304 Utility.codeToString(code, constant_pool, 0, -1, verbose));
305 if (exception_table_length > 0) {
306 buf.append("\nException handler(s) = \n").append("From\tTo\tHandler\tType\n");
307 for (int i = 0; i < exception_table_length; i++) {
308 buf.append(exception_table[i].toString(constant_pool, verbose)).append("\n");
309 }
310 }
311 if (attributes_count > 0) {
312 buf.append("\nAttribute(s) = \n");
313 for (int i = 0; i < attributes_count; i++) {
314 buf.append(attributes[i].toString()).append("\n");
315 }
316 }
317 return buf.toString();
318 }
319
320
321 /**
322 * @return String representation of code chunk.
323 */
324 public final String toString() {
325 return toString(true);
326 }
327
328
329 /**
330 * @return deep copy of this attribute
331 *
332 * @param _constant_pool the constant pool to duplicate
333 */
334 public Attribute copy( ConstantPool _constant_pool ) {
335 Code c = (Code) clone();
336 if (code != null) {
337 c.code = new byte[code.length];
338 System.arraycopy(code, 0, c.code, 0, code.length);
339 }
340 c.constant_pool = _constant_pool;
341 c.exception_table = new CodeException[exception_table_length];
342 for (int i = 0; i < exception_table_length; i++) {
343 c.exception_table[i] = exception_table[i].copy();
344 }
345 c.attributes = new Attribute[attributes_count];
346 for (int i = 0; i < attributes_count; i++) {
347 c.attributes[i] = attributes[i].copy(_constant_pool);
348 }
349 return c;
350 }
351 }
+0
-214
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/CodeException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import org.apache.bcel.Constants;
23
24 /**
25 * This class represents an entry in the exception table of the <em>Code</em>
26 * attribute and is used only there. It contains a range in which a
27 * particular exception handler is active.
28 *
29 * @version $Id: CodeException.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see Code
32 */
33 public final class CodeException implements Cloneable, Constants, Node, Serializable {
34
35 private int start_pc; // Range in the code the exception handler is
36 private int end_pc; // active. start_pc is inclusive, end_pc exclusive
37 private int handler_pc; /* Starting address of exception handler, i.e.,
38 * an offset from start of code.
39 */
40 private int catch_type; /* If this is zero the handler catches any
41 * exception, otherwise it points to the
42 * exception class which is to be caught.
43 */
44
45
46 /**
47 * Initialize from another object.
48 */
49 public CodeException(CodeException c) {
50 this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType());
51 }
52
53
54 /**
55 * Construct object from file stream.
56 * @param file Input stream
57 * @throws IOException
58 */
59 CodeException(DataInputStream file) throws IOException {
60 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
61 .readUnsignedShort());
62 }
63
64
65 /**
66 * @param start_pc Range in the code the exception handler is active,
67 * start_pc is inclusive while
68 * @param end_pc is exclusive
69 * @param handler_pc Starting address of exception handler, i.e.,
70 * an offset from start of code.
71 * @param catch_type If zero the handler catches any
72 * exception, otherwise it points to the exception class which is
73 * to be caught.
74 */
75 public CodeException(int start_pc, int end_pc, int handler_pc, int catch_type) {
76 this.start_pc = start_pc;
77 this.end_pc = end_pc;
78 this.handler_pc = handler_pc;
79 this.catch_type = catch_type;
80 }
81
82
83 /**
84 * Called by objects that are traversing the nodes of the tree implicitely
85 * defined by the contents of a Java class. I.e., the hierarchy of methods,
86 * fields, attributes, etc. spawns a tree of objects.
87 *
88 * @param v Visitor object
89 */
90 public void accept( Visitor v ) {
91 v.visitCodeException(this);
92 }
93
94
95 /**
96 * Dump code exception to file stream in binary format.
97 *
98 * @param file Output file stream
99 * @throws IOException
100 */
101 public final void dump( DataOutputStream file ) throws IOException {
102 file.writeShort(start_pc);
103 file.writeShort(end_pc);
104 file.writeShort(handler_pc);
105 file.writeShort(catch_type);
106 }
107
108
109 /**
110 * @return 0, if the handler catches any exception, otherwise it points to
111 * the exception class which is to be caught.
112 */
113 public final int getCatchType() {
114 return catch_type;
115 }
116
117
118 /**
119 * @return Exclusive end index of the region where the handler is active.
120 */
121 public final int getEndPC() {
122 return end_pc;
123 }
124
125
126 /**
127 * @return Starting address of exception handler, relative to the code.
128 */
129 public final int getHandlerPC() {
130 return handler_pc;
131 }
132
133
134 /**
135 * @return Inclusive start index of the region where the handler is active.
136 */
137 public final int getStartPC() {
138 return start_pc;
139 }
140
141
142 /**
143 * @param catch_type the type of exception that is caught
144 */
145 public final void setCatchType( int catch_type ) {
146 this.catch_type = catch_type;
147 }
148
149
150 /**
151 * @param end_pc end of handled block
152 */
153 public final void setEndPC( int end_pc ) {
154 this.end_pc = end_pc;
155 }
156
157
158 /**
159 * @param handler_pc where the actual code is
160 */
161 public final void setHandlerPC( int handler_pc ) {
162 this.handler_pc = handler_pc;
163 }
164
165
166 /**
167 * @param start_pc start of handled block
168 */
169 public final void setStartPC( int start_pc ) {
170 this.start_pc = start_pc;
171 }
172
173
174 /**
175 * @return String representation.
176 */
177 public final String toString() {
178 return "CodeException(start_pc = " + start_pc + ", end_pc = " + end_pc + ", handler_pc = "
179 + handler_pc + ", catch_type = " + catch_type + ")";
180 }
181
182
183 /**
184 * @return String representation.
185 */
186 public final String toString( ConstantPool cp, boolean verbose ) {
187 String str;
188 if (catch_type == 0) {
189 str = "<Any exception>(0)";
190 } else {
191 str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class), false)
192 + (verbose ? "(" + catch_type + ")" : "");
193 }
194 return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str;
195 }
196
197
198 public final String toString( ConstantPool cp ) {
199 return toString(cp, true);
200 }
201
202
203 /**
204 * @return deep copy of this object
205 */
206 public CodeException copy() {
207 try {
208 return (CodeException) clone();
209 } catch (CloneNotSupportedException e) {
210 }
211 return null;
212 }
213 }
+0
-188
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Constant.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import org.apache.bcel.Constants;
23 import org.apache.bcel.util.BCELComparator;
24
25 /**
26 * Abstract superclass for classes to represent the different constant types
27 * in the constant pool of a class file. The classes keep closely to
28 * the JVM specification.
29 *
30 * @version $Id: Constant.java 386056 2006-03-15 11:31:56Z tcurdt $
31 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32 */
33 public abstract class Constant implements Cloneable, Node, Serializable {
34
35 private static BCELComparator _cmp = new BCELComparator() {
36
37 public boolean equals( Object o1, Object o2 ) {
38 Constant THIS = (Constant) o1;
39 Constant THAT = (Constant) o2;
40 return THIS.toString().equals(THAT.toString());
41 }
42
43
44 public int hashCode( Object o ) {
45 Constant THIS = (Constant) o;
46 return THIS.toString().hashCode();
47 }
48 };
49 /* In fact this tag is redundant since we can distinguish different
50 * `Constant' objects by their type, i.e., via `instanceof'. In some
51 * places we will use the tag for switch()es anyway.
52 *
53 * First, we want match the specification as closely as possible. Second we
54 * need the tag as an index to select the corresponding class name from the
55 * `CONSTANT_NAMES' array.
56 */
57 protected byte tag;
58
59
60 Constant(byte tag) {
61 this.tag = tag;
62 }
63
64
65 /**
66 * Called by objects that are traversing the nodes of the tree implicitely
67 * defined by the contents of a Java class. I.e., the hierarchy of methods,
68 * fields, attributes, etc. spawns a tree of objects.
69 *
70 * @param v Visitor object
71 */
72 public abstract void accept( Visitor v );
73
74
75 public abstract void dump( DataOutputStream file ) throws IOException;
76
77
78 /**
79 * @return Tag of constant, i.e., its type. No setTag() method to avoid
80 * confusion.
81 */
82 public final byte getTag() {
83 return tag;
84 }
85
86
87 /**
88 * @return String representation.
89 */
90 public String toString() {
91 return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]";
92 }
93
94
95 /**
96 * @return deep copy of this constant
97 */
98 public Constant copy() {
99 try {
100 return (Constant) super.clone();
101 } catch (CloneNotSupportedException e) {
102 }
103 return null;
104 }
105
106
107 public Object clone() throws CloneNotSupportedException {
108 return super.clone();
109 }
110
111
112 /**
113 * Read one constant from the given file, the type depends on a tag byte.
114 *
115 * @param file Input stream
116 * @return Constant object
117 */
118 static final Constant readConstant( DataInputStream file ) throws IOException,
119 ClassFormatException {
120 byte b = file.readByte(); // Read tag byte
121 switch (b) {
122 case Constants.CONSTANT_Class:
123 return new ConstantClass(file);
124 case Constants.CONSTANT_Fieldref:
125 return new ConstantFieldref(file);
126 case Constants.CONSTANT_Methodref:
127 return new ConstantMethodref(file);
128 case Constants.CONSTANT_InterfaceMethodref:
129 return new ConstantInterfaceMethodref(file);
130 case Constants.CONSTANT_String:
131 return new ConstantString(file);
132 case Constants.CONSTANT_Integer:
133 return new ConstantInteger(file);
134 case Constants.CONSTANT_Float:
135 return new ConstantFloat(file);
136 case Constants.CONSTANT_Long:
137 return new ConstantLong(file);
138 case Constants.CONSTANT_Double:
139 return new ConstantDouble(file);
140 case Constants.CONSTANT_NameAndType:
141 return new ConstantNameAndType(file);
142 case Constants.CONSTANT_Utf8:
143 return ConstantUtf8.getInstance(file);
144 default:
145 throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
146 }
147 }
148
149
150 /**
151 * @return Comparison strategy object
152 */
153 public static BCELComparator getComparator() {
154 return _cmp;
155 }
156
157
158 /**
159 * @param comparator Comparison strategy object
160 */
161 public static void setComparator( BCELComparator comparator ) {
162 _cmp = comparator;
163 }
164
165
166 /**
167 * Return value as defined by given BCELComparator strategy.
168 * By default two Constant objects are said to be equal when
169 * the result of toString() is equal.
170 *
171 * @see java.lang.Object#equals(java.lang.Object)
172 */
173 public boolean equals( Object obj ) {
174 return _cmp.equals(this, obj);
175 }
176
177
178 /**
179 * Return value as defined by given BCELComparator strategy.
180 * By default return the hashcode of the result of toString().
181 *
182 * @see java.lang.Object#hashCode()
183 */
184 public int hashCode() {
185 return _cmp.hashCode(this);
186 }
187 }
+0
-131
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantCP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * Abstract super class for Fieldref and Methodref constants.
25 *
26 * @version $Id: ConstantCP.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 * @see ConstantFieldref
29 * @see ConstantMethodref
30 * @see ConstantInterfaceMethodref
31 */
32 public abstract class ConstantCP extends Constant {
33
34 /** References to the constants containing the class and the field signature
35 */
36 protected int class_index, name_and_type_index;
37
38
39 /**
40 * Initialize from another object.
41 */
42 public ConstantCP(ConstantCP c) {
43 this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex());
44 }
45
46
47 /**
48 * Initialize instance from file data.
49 *
50 * @param tag Constant type tag
51 * @param file Input stream
52 * @throws IOException
53 */
54 ConstantCP(byte tag, DataInputStream file) throws IOException {
55 this(tag, file.readUnsignedShort(), file.readUnsignedShort());
56 }
57
58
59 /**
60 * @param class_index Reference to the class containing the field
61 * @param name_and_type_index and the field signature
62 */
63 protected ConstantCP(byte tag, int class_index, int name_and_type_index) {
64 super(tag);
65 this.class_index = class_index;
66 this.name_and_type_index = name_and_type_index;
67 }
68
69
70 /**
71 * Dump constant field reference to file stream in binary format.
72 *
73 * @param file Output file stream
74 * @throws IOException
75 */
76 public final void dump( DataOutputStream file ) throws IOException {
77 file.writeByte(tag);
78 file.writeShort(class_index);
79 file.writeShort(name_and_type_index);
80 }
81
82
83 /**
84 * @return Reference (index) to class this field or method belongs to.
85 */
86 public final int getClassIndex() {
87 return class_index;
88 }
89
90
91 /**
92 * @return Reference (index) to signature of the field.
93 */
94 public final int getNameAndTypeIndex() {
95 return name_and_type_index;
96 }
97
98
99 /**
100 * @param class_index points to Constant_class
101 */
102 public final void setClassIndex( int class_index ) {
103 this.class_index = class_index;
104 }
105
106
107 /**
108 * @return Class this field belongs to.
109 */
110 public String getClass( ConstantPool cp ) {
111 return cp.constantToString(class_index, Constants.CONSTANT_Class);
112 }
113
114
115 /**
116 * @param name_and_type_index points to Constant_NameAndType
117 */
118 public final void setNameAndTypeIndex( int name_and_type_index ) {
119 this.name_and_type_index = name_and_type_index;
120 }
121
122
123 /**
124 * @return String representation.
125 */
126 public final String toString() {
127 return super.toString() + "(class_index = " + class_index + ", name_and_type_index = "
128 + name_and_type_index + ")";
129 }
130 }
+0
-128
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantClass.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to a (external) class.
27 *
28 * @version $Id: ConstantClass.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantClass extends Constant implements ConstantObject {
33
34 private int name_index; // Identical to ConstantString except for the name
35
36
37 /**
38 * Initialize from another object.
39 */
40 public ConstantClass(ConstantClass c) {
41 this(c.getNameIndex());
42 }
43
44
45 /**
46 * Initialize instance from file data.
47 *
48 * @param file Input stream
49 * @throws IOException
50 */
51 ConstantClass(DataInputStream file) throws IOException {
52 this(file.readUnsignedShort());
53 }
54
55
56 /**
57 * @param name_index Name index in constant pool. Should refer to a
58 * ConstantUtf8.
59 */
60 public ConstantClass(int name_index) {
61 super(Constants.CONSTANT_Class);
62 this.name_index = name_index;
63 }
64
65
66 /**
67 * Called by objects that are traversing the nodes of the tree implicitely
68 * defined by the contents of a Java class. I.e., the hierarchy of methods,
69 * fields, attributes, etc. spawns a tree of objects.
70 *
71 * @param v Visitor object
72 */
73 public void accept( Visitor v ) {
74 v.visitConstantClass(this);
75 }
76
77
78 /**
79 * Dump constant class to file stream in binary format.
80 *
81 * @param file Output file stream
82 * @throws IOException
83 */
84 public final void dump( DataOutputStream file ) throws IOException {
85 file.writeByte(tag);
86 file.writeShort(name_index);
87 }
88
89
90 /**
91 * @return Name index in constant pool of class name.
92 */
93 public final int getNameIndex() {
94 return name_index;
95 }
96
97
98 /**
99 * @param name_index the name index in the constant pool of this Constant Class
100 */
101 public final void setNameIndex( int name_index ) {
102 this.name_index = name_index;
103 }
104
105
106 /** @return String object
107 */
108 public Object getConstantValue( ConstantPool cp ) {
109 Constant c = cp.getConstant(name_index, Constants.CONSTANT_Utf8);
110 return ((ConstantUtf8) c).getBytes();
111 }
112
113
114 /** @return dereferenced string
115 */
116 public String getBytes( ConstantPool cp ) {
117 return (String) getConstantValue(cp);
118 }
119
120
121 /**
122 * @return String representation.
123 */
124 public final String toString() {
125 return super.toString() + "(name_index = " + name_index + ")";
126 }
127 }
+0
-119
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantDouble.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to a Double object.
27 *
28 * @version $Id: ConstantDouble.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantDouble extends Constant implements ConstantObject {
33
34 private double bytes;
35
36
37 /**
38 * @param bytes Data
39 */
40 public ConstantDouble(double bytes) {
41 super(Constants.CONSTANT_Double);
42 this.bytes = bytes;
43 }
44
45
46 /**
47 * Initialize from another object.
48 */
49 public ConstantDouble(ConstantDouble c) {
50 this(c.getBytes());
51 }
52
53
54 /**
55 * Initialize instance from file data.
56 *
57 * @param file Input stream
58 * @throws IOException
59 */
60 ConstantDouble(DataInputStream file) throws IOException {
61 this(file.readDouble());
62 }
63
64
65 /**
66 * Called by objects that are traversing the nodes of the tree implicitely
67 * defined by the contents of a Java class. I.e., the hierarchy of methods,
68 * fields, attributes, etc. spawns a tree of objects.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitConstantDouble(this);
74 }
75
76
77 /**
78 * Dump constant double to file stream in binary format.
79 *
80 * @param file Output file stream
81 * @throws IOException
82 */
83 public final void dump( DataOutputStream file ) throws IOException {
84 file.writeByte(tag);
85 file.writeDouble(bytes);
86 }
87
88
89 /**
90 * @return data, i.e., 8 bytes.
91 */
92 public final double getBytes() {
93 return bytes;
94 }
95
96
97 /**
98 * @param bytes the raw bytes that represent the double value
99 */
100 public final void setBytes( double bytes ) {
101 this.bytes = bytes;
102 }
103
104
105 /**
106 * @return String representation.
107 */
108 public final String toString() {
109 return super.toString() + "(bytes = " + bytes + ")";
110 }
111
112
113 /** @return Double object
114 */
115 public Object getConstantValue( ConstantPool cp ) {
116 return new Double(bytes);
117 }
118 }
+0
-69
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantFieldref.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21
22 /**
23 * This class represents a constant pool reference to a field.
24 *
25 * @version $Id: ConstantFieldref.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public final class ConstantFieldref extends ConstantCP {
29
30 /**
31 * Initialize from another object.
32 */
33 public ConstantFieldref(ConstantFieldref c) {
34 super(Constants.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex());
35 }
36
37
38 /**
39 * Initialize instance from file data.
40 *
41 * @param file input stream
42 * @throws IOException
43 */
44 ConstantFieldref(DataInputStream file) throws IOException {
45 super(Constants.CONSTANT_Fieldref, file);
46 }
47
48
49 /**
50 * @param class_index Reference to the class containing the Field
51 * @param name_and_type_index and the Field signature
52 */
53 public ConstantFieldref(int class_index, int name_and_type_index) {
54 super(Constants.CONSTANT_Fieldref, class_index, name_and_type_index);
55 }
56
57
58 /**
59 * Called by objects that are traversing the nodes of the tree implicitely
60 * defined by the contents of a Java class. I.e., the hierarchy of Fields,
61 * fields, attributes, etc. spawns a tree of objects.
62 *
63 * @param v Visitor object
64 */
65 public void accept( Visitor v ) {
66 v.visitConstantFieldref(this);
67 }
68 }
+0
-120
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantFloat.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to a float object.
27 *
28 * @version $Id: ConstantFloat.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantFloat extends Constant implements ConstantObject {
33
34 private float bytes;
35
36
37 /**
38 * @param bytes Data
39 */
40 public ConstantFloat(float bytes) {
41 super(Constants.CONSTANT_Float);
42 this.bytes = bytes;
43 }
44
45
46 /**
47 * Initialize from another object. Note that both objects use the same
48 * references (shallow copy). Use clone() for a physical copy.
49 */
50 public ConstantFloat(ConstantFloat c) {
51 this(c.getBytes());
52 }
53
54
55 /**
56 * Initialize instance from file data.
57 *
58 * @param file Input stream
59 * @throws IOException
60 */
61 ConstantFloat(DataInputStream file) throws IOException {
62 this(file.readFloat());
63 }
64
65
66 /**
67 * Called by objects that are traversing the nodes of the tree implicitely
68 * defined by the contents of a Java class. I.e., the hierarchy of methods,
69 * fields, attributes, etc. spawns a tree of objects.
70 *
71 * @param v Visitor object
72 */
73 public void accept( Visitor v ) {
74 v.visitConstantFloat(this);
75 }
76
77
78 /**
79 * Dump constant float to file stream in binary format.
80 *
81 * @param file Output file stream
82 * @throws IOException
83 */
84 public final void dump( DataOutputStream file ) throws IOException {
85 file.writeByte(tag);
86 file.writeFloat(bytes);
87 }
88
89
90 /**
91 * @return data, i.e., 4 bytes.
92 */
93 public final float getBytes() {
94 return bytes;
95 }
96
97
98 /**
99 * @param bytes the raw bytes that represent this float
100 */
101 public final void setBytes( float bytes ) {
102 this.bytes = bytes;
103 }
104
105
106 /**
107 * @return String representation.
108 */
109 public final String toString() {
110 return super.toString() + "(bytes = " + bytes + ")";
111 }
112
113
114 /** @return Float object
115 */
116 public Object getConstantValue( ConstantPool cp ) {
117 return new Float(bytes);
118 }
119 }
+0
-119
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantInteger.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to an int object.
27 *
28 * @version $Id: ConstantInteger.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantInteger extends Constant implements ConstantObject {
33
34 private int bytes;
35
36
37 /**
38 * @param bytes Data
39 */
40 public ConstantInteger(int bytes) {
41 super(Constants.CONSTANT_Integer);
42 this.bytes = bytes;
43 }
44
45
46 /**
47 * Initialize from another object.
48 */
49 public ConstantInteger(ConstantInteger c) {
50 this(c.getBytes());
51 }
52
53
54 /**
55 * Initialize instance from file data.
56 *
57 * @param file Input stream
58 * @throws IOException
59 */
60 ConstantInteger(DataInputStream file) throws IOException {
61 this(file.readInt());
62 }
63
64
65 /**
66 * Called by objects that are traversing the nodes of the tree implicitely
67 * defined by the contents of a Java class. I.e., the hierarchy of methods,
68 * fields, attributes, etc. spawns a tree of objects.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitConstantInteger(this);
74 }
75
76
77 /**
78 * Dump constant integer to file stream in binary format.
79 *
80 * @param file Output file stream
81 * @throws IOException
82 */
83 public final void dump( DataOutputStream file ) throws IOException {
84 file.writeByte(tag);
85 file.writeInt(bytes);
86 }
87
88
89 /**
90 * @return data, i.e., 4 bytes.
91 */
92 public final int getBytes() {
93 return bytes;
94 }
95
96
97 /**
98 * @param bytes the raw bytes that represent this integer
99 */
100 public final void setBytes( int bytes ) {
101 this.bytes = bytes;
102 }
103
104
105 /**
106 * @return String representation.
107 */
108 public final String toString() {
109 return super.toString() + "(bytes = " + bytes + ")";
110 }
111
112
113 /** @return Integer object
114 */
115 public Object getConstantValue( ConstantPool cp ) {
116 return new Integer(bytes);
117 }
118 }
+0
-69
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantInterfaceMethodref.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21
22 /**
23 * This class represents a constant pool reference to an interface method.
24 *
25 * @version $Id: ConstantInterfaceMethodref.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public final class ConstantInterfaceMethodref extends ConstantCP {
29
30 /**
31 * Initialize from another object.
32 */
33 public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) {
34 super(Constants.CONSTANT_InterfaceMethodref, c.getClassIndex(), c.getNameAndTypeIndex());
35 }
36
37
38 /**
39 * Initialize instance from file data.
40 *
41 * @param file input stream
42 * @throws IOException
43 */
44 ConstantInterfaceMethodref(DataInputStream file) throws IOException {
45 super(Constants.CONSTANT_InterfaceMethodref, file);
46 }
47
48
49 /**
50 * @param class_index Reference to the class containing the method
51 * @param name_and_type_index and the method signature
52 */
53 public ConstantInterfaceMethodref(int class_index, int name_and_type_index) {
54 super(Constants.CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
55 }
56
57
58 /**
59 * Called by objects that are traversing the nodes of the tree implicitely
60 * defined by the contents of a Java class. I.e., the hierarchy of methods,
61 * fields, attributes, etc. spawns a tree of objects.
62 *
63 * @param v Visitor object
64 */
65 public void accept( Visitor v ) {
66 v.visitConstantInterfaceMethodref(this);
67 }
68 }
+0
-119
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantLong.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to a long object.
27 *
28 * @version $Id: ConstantLong.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantLong extends Constant implements ConstantObject {
33
34 private long bytes;
35
36
37 /**
38 * @param bytes Data
39 */
40 public ConstantLong(long bytes) {
41 super(Constants.CONSTANT_Long);
42 this.bytes = bytes;
43 }
44
45
46 /**
47 * Initialize from another object.
48 */
49 public ConstantLong(ConstantLong c) {
50 this(c.getBytes());
51 }
52
53
54 /**
55 * Initialize instance from file data.
56 *
57 * @param file Input stream
58 * @throws IOException
59 */
60 ConstantLong(DataInputStream file) throws IOException {
61 this(file.readLong());
62 }
63
64
65 /**
66 * Called by objects that are traversing the nodes of the tree implicitely
67 * defined by the contents of a Java class. I.e., the hierarchy of methods,
68 * fields, attributes, etc. spawns a tree of objects.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitConstantLong(this);
74 }
75
76
77 /**
78 * Dump constant long to file stream in binary format.
79 *
80 * @param file Output file stream
81 * @throws IOException
82 */
83 public final void dump( DataOutputStream file ) throws IOException {
84 file.writeByte(tag);
85 file.writeLong(bytes);
86 }
87
88
89 /**
90 * @return data, i.e., 8 bytes.
91 */
92 public final long getBytes() {
93 return bytes;
94 }
95
96
97 /**
98 * @param bytes thr raw bytes that represent this long
99 */
100 public final void setBytes( long bytes ) {
101 this.bytes = bytes;
102 }
103
104
105 /**
106 * @return String representation.
107 */
108 public final String toString() {
109 return super.toString() + "(bytes = " + bytes + ")";
110 }
111
112
113 /** @return Long object
114 */
115 public Object getConstantValue( ConstantPool cp ) {
116 return new Long(bytes);
117 }
118 }
+0
-69
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantMethodref.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21
22 /**
23 * This class represents a constant pool reference to a method.
24 *
25 * @version $Id: ConstantMethodref.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public final class ConstantMethodref extends ConstantCP {
29
30 /**
31 * Initialize from another object.
32 */
33 public ConstantMethodref(ConstantMethodref c) {
34 super(Constants.CONSTANT_Methodref, c.getClassIndex(), c.getNameAndTypeIndex());
35 }
36
37
38 /**
39 * Initialize instance from file data.
40 *
41 * @param file input stream
42 * @throws IOException
43 */
44 ConstantMethodref(DataInputStream file) throws IOException {
45 super(Constants.CONSTANT_Methodref, file);
46 }
47
48
49 /**
50 * @param class_index Reference to the class containing the method
51 * @param name_and_type_index and the method signature
52 */
53 public ConstantMethodref(int class_index, int name_and_type_index) {
54 super(Constants.CONSTANT_Methodref, class_index, name_and_type_index);
55 }
56
57
58 /**
59 * Called by objects that are traversing the nodes of the tree implicitely
60 * defined by the contents of a Java class. I.e., the hierarchy of methods,
61 * fields, attributes, etc. spawns a tree of objects.
62 *
63 * @param v Visitor object
64 */
65 public void accept( Visitor v ) {
66 v.visitConstantMethodref(this);
67 }
68 }
+0
-148
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantNameAndType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to the name and signature
27 * of a field or method.
28 *
29 * @version $Id: ConstantNameAndType.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see Constant
32 */
33 public final class ConstantNameAndType extends Constant {
34
35 private int name_index; // Name of field/method
36 private int signature_index; // and its signature.
37
38
39 /**
40 * Initialize from another object.
41 */
42 public ConstantNameAndType(ConstantNameAndType c) {
43 this(c.getNameIndex(), c.getSignatureIndex());
44 }
45
46
47 /**
48 * Initialize instance from file data.
49 *
50 * @param file Input stream
51 * @throws IOException
52 */
53 ConstantNameAndType(DataInputStream file) throws IOException {
54 this(file.readUnsignedShort(), file.readUnsignedShort());
55 }
56
57
58 /**
59 * @param name_index Name of field/method
60 * @param signature_index and its signature
61 */
62 public ConstantNameAndType(int name_index, int signature_index) {
63 super(Constants.CONSTANT_NameAndType);
64 this.name_index = name_index;
65 this.signature_index = signature_index;
66 }
67
68
69 /**
70 * Called by objects that are traversing the nodes of the tree implicitely
71 * defined by the contents of a Java class. I.e., the hierarchy of methods,
72 * fields, attributes, etc. spawns a tree of objects.
73 *
74 * @param v Visitor object
75 */
76 public void accept( Visitor v ) {
77 v.visitConstantNameAndType(this);
78 }
79
80
81 /**
82 * Dump name and signature index to file stream in binary format.
83 *
84 * @param file Output file stream
85 * @throws IOException
86 */
87 public final void dump( DataOutputStream file ) throws IOException {
88 file.writeByte(tag);
89 file.writeShort(name_index);
90 file.writeShort(signature_index);
91 }
92
93
94 /**
95 * @return Name index in constant pool of field/method name.
96 */
97 public final int getNameIndex() {
98 return name_index;
99 }
100
101
102 /** @return name
103 */
104 public final String getName( ConstantPool cp ) {
105 return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
106 }
107
108
109 /**
110 * @return Index in constant pool of field/method signature.
111 */
112 public final int getSignatureIndex() {
113 return signature_index;
114 }
115
116
117 /** @return signature
118 */
119 public final String getSignature( ConstantPool cp ) {
120 return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
121 }
122
123
124 /**
125 * @param name_index the name index of this constant
126 */
127 public final void setNameIndex( int name_index ) {
128 this.name_index = name_index;
129 }
130
131
132 /**
133 * @param signature_index the signature index in the constant pool of this type
134 */
135 public final void setSignatureIndex( int signature_index ) {
136 this.signature_index = signature_index;
137 }
138
139
140 /**
141 * @return String representation
142 */
143 public final String toString() {
144 return super.toString() + "(name_index = " + name_index + ", signature_index = "
145 + signature_index + ")";
146 }
147 }
+0
-32
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantObject.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * This interface denotes those constants that have a "natural" value,
20 * such as ConstantLong, ConstantString, etc..
21 *
22 * @version $Id: ConstantObject.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 * @see Constant
25 */
26 public interface ConstantObject {
27
28 /** @return object representing the constant, e.g., Long for ConstantLong
29 */
30 public abstract Object getConstantValue( ConstantPool cp );
31 }
+0
-353
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantPool.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import org.apache.bcel.Constants;
23
24 /**
25 * This class represents the constant pool, i.e., a table of constants, of
26 * a parsed classfile. It may contain null references, due to the JVM
27 * specification that skips an entry after an 8-byte constant (double,
28 * long) entry. Those interested in generating constant pools
29 * programatically should see <a href="../generic/ConstantPoolGen.html">
30 * ConstantPoolGen</a>.
31
32 * @version $Id: ConstantPool.java 386056 2006-03-15 11:31:56Z tcurdt $
33 * @see Constant
34 * @see org.apache.bcel.generic.ConstantPoolGen
35 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36 */
37 public class ConstantPool implements Cloneable, Node, Serializable {
38
39 private int constant_pool_count;
40 private Constant[] constant_pool;
41
42
43 /**
44 * @param constant_pool Array of constants
45 */
46 public ConstantPool(Constant[] constant_pool) {
47 setConstantPool(constant_pool);
48 }
49
50
51 /**
52 * Read constants from given file stream.
53 *
54 * @param file Input stream
55 * @throws IOException
56 * @throws ClassFormatException
57 */
58 ConstantPool(DataInputStream file) throws IOException, ClassFormatException {
59 byte tag;
60 constant_pool_count = file.readUnsignedShort();
61 constant_pool = new Constant[constant_pool_count];
62 /* constant_pool[0] is unused by the compiler and may be used freely
63 * by the implementation.
64 */
65 for (int i = 1; i < constant_pool_count; i++) {
66 constant_pool[i] = Constant.readConstant(file);
67 /* Quote from the JVM specification:
68 * "All eight byte constants take up two spots in the constant pool.
69 * If this is the n'th byte in the constant pool, then the next item
70 * will be numbered n+2"
71 *
72 * Thus we have to increment the index counter.
73 */
74 tag = constant_pool[i].getTag();
75 if ((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long)) {
76 i++;
77 }
78 }
79 }
80
81
82 /**
83 * Called by objects that are traversing the nodes of the tree implicitely
84 * defined by the contents of a Java class. I.e., the hierarchy of methods,
85 * fields, attributes, etc. spawns a tree of objects.
86 *
87 * @param v Visitor object
88 */
89 public void accept( Visitor v ) {
90 v.visitConstantPool(this);
91 }
92
93
94 /**
95 * Resolve constant to a string representation.
96 *
97 * @param c Constant to be printed
98 * @return String representation
99 */
100 public String constantToString( Constant c ) throws ClassFormatException {
101 String str;
102 int i;
103 byte tag = c.getTag();
104 switch (tag) {
105 case Constants.CONSTANT_Class:
106 i = ((ConstantClass) c).getNameIndex();
107 c = getConstant(i, Constants.CONSTANT_Utf8);
108 str = Utility.compactClassName(((ConstantUtf8) c).getBytes(), false);
109 break;
110 case Constants.CONSTANT_String:
111 i = ((ConstantString) c).getStringIndex();
112 c = getConstant(i, Constants.CONSTANT_Utf8);
113 str = "\"" + escape(((ConstantUtf8) c).getBytes()) + "\"";
114 break;
115 case Constants.CONSTANT_Utf8:
116 str = ((ConstantUtf8) c).getBytes();
117 break;
118 case Constants.CONSTANT_Double:
119 str = "" + ((ConstantDouble) c).getBytes();
120 break;
121 case Constants.CONSTANT_Float:
122 str = "" + ((ConstantFloat) c).getBytes();
123 break;
124 case Constants.CONSTANT_Long:
125 str = "" + ((ConstantLong) c).getBytes();
126 break;
127 case Constants.CONSTANT_Integer:
128 str = "" + ((ConstantInteger) c).getBytes();
129 break;
130 case Constants.CONSTANT_NameAndType:
131 str = (constantToString(((ConstantNameAndType) c).getNameIndex(),
132 Constants.CONSTANT_Utf8)
133 + " " + constantToString(((ConstantNameAndType) c).getSignatureIndex(),
134 Constants.CONSTANT_Utf8));
135 break;
136 case Constants.CONSTANT_InterfaceMethodref:
137 case Constants.CONSTANT_Methodref:
138 case Constants.CONSTANT_Fieldref:
139 str = (constantToString(((ConstantCP) c).getClassIndex(), Constants.CONSTANT_Class)
140 + "." + constantToString(((ConstantCP) c).getNameAndTypeIndex(),
141 Constants.CONSTANT_NameAndType));
142 break;
143 default: // Never reached
144 throw new RuntimeException("Unknown constant type " + tag);
145 }
146 return str;
147 }
148
149
150 private static final String escape( String str ) {
151 int len = str.length();
152 StringBuffer buf = new StringBuffer(len + 5);
153 char[] ch = str.toCharArray();
154 for (int i = 0; i < len; i++) {
155 switch (ch[i]) {
156 case '\n':
157 buf.append("\\n");
158 break;
159 case '\r':
160 buf.append("\\r");
161 break;
162 case '\t':
163 buf.append("\\t");
164 break;
165 case '\b':
166 buf.append("\\b");
167 break;
168 case '"':
169 buf.append("\\\"");
170 break;
171 default:
172 buf.append(ch[i]);
173 }
174 }
175 return buf.toString();
176 }
177
178
179 /**
180 * Retrieve constant at `index' from constant pool and resolve it to
181 * a string representation.
182 *
183 * @param index of constant in constant pool
184 * @param tag expected type
185 * @return String representation
186 */
187 public String constantToString( int index, byte tag ) throws ClassFormatException {
188 Constant c = getConstant(index, tag);
189 return constantToString(c);
190 }
191
192
193 /**
194 * Dump constant pool to file stream in binary format.
195 *
196 * @param file Output file stream
197 * @throws IOException
198 */
199 public void dump( DataOutputStream file ) throws IOException {
200 file.writeShort(constant_pool_count);
201 for (int i = 1; i < constant_pool_count; i++) {
202 if (constant_pool[i] != null) {
203 constant_pool[i].dump(file);
204 }
205 }
206 }
207
208
209 /**
210 * Get constant from constant pool.
211 *
212 * @param index Index in constant pool
213 * @return Constant value
214 * @see Constant
215 */
216 public Constant getConstant( int index ) {
217 if (index >= constant_pool.length || index < 0) {
218 throw new ClassFormatException("Invalid constant pool reference: " + index
219 + ". Constant pool size is: " + constant_pool.length);
220 }
221 return constant_pool[index];
222 }
223
224
225 /**
226 * Get constant from constant pool and check whether it has the
227 * expected type.
228 *
229 * @param index Index in constant pool
230 * @param tag Tag of expected constant, i.e., its type
231 * @return Constant value
232 * @see Constant
233 * @throws ClassFormatException
234 */
235 public Constant getConstant( int index, byte tag ) throws ClassFormatException {
236 Constant c;
237 c = getConstant(index);
238 if (c == null) {
239 throw new ClassFormatException("Constant pool at index " + index + " is null.");
240 }
241 if (c.getTag() != tag) {
242 throw new ClassFormatException("Expected class `" + Constants.CONSTANT_NAMES[tag]
243 + "' at index " + index + " and got " + c);
244 }
245 return c;
246 }
247
248
249 /**
250 * @return Array of constants.
251 * @see Constant
252 */
253 public Constant[] getConstantPool() {
254 return constant_pool;
255 }
256
257
258 /**
259 * Get string from constant pool and bypass the indirection of
260 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
261 * an index field that points to another entry of the constant pool of
262 * type `ConstantUtf8' which contains the real data.
263 *
264 * @param index Index in constant pool
265 * @param tag Tag of expected constant, either ConstantClass or ConstantString
266 * @return Contents of string reference
267 * @see ConstantClass
268 * @see ConstantString
269 * @throws ClassFormatException
270 */
271 public String getConstantString( int index, byte tag ) throws ClassFormatException {
272 Constant c;
273 int i;
274 c = getConstant(index, tag);
275 /* This switch() is not that elegant, since the two classes have the
276 * same contents, they just differ in the name of the index
277 * field variable.
278 * But we want to stick to the JVM naming conventions closely though
279 * we could have solved these more elegantly by using the same
280 * variable name or by subclassing.
281 */
282 switch (tag) {
283 case Constants.CONSTANT_Class:
284 i = ((ConstantClass) c).getNameIndex();
285 break;
286 case Constants.CONSTANT_String:
287 i = ((ConstantString) c).getStringIndex();
288 break;
289 default:
290 throw new RuntimeException("getConstantString called with illegal tag " + tag);
291 }
292 // Finally get the string from the constant pool
293 c = getConstant(i, Constants.CONSTANT_Utf8);
294 return ((ConstantUtf8) c).getBytes();
295 }
296
297
298 /**
299 * @return Length of constant pool.
300 */
301 public int getLength() {
302 return constant_pool_count;
303 }
304
305
306 /**
307 * @param constant Constant to set
308 */
309 public void setConstant( int index, Constant constant ) {
310 constant_pool[index] = constant;
311 }
312
313
314 /**
315 * @param constant_pool
316 */
317 public void setConstantPool( Constant[] constant_pool ) {
318 this.constant_pool = constant_pool;
319 constant_pool_count = (constant_pool == null) ? 0 : constant_pool.length;
320 }
321
322
323 /**
324 * @return String representation.
325 */
326 public String toString() {
327 StringBuffer buf = new StringBuffer();
328 for (int i = 1; i < constant_pool_count; i++) {
329 buf.append(i).append(")").append(constant_pool[i]).append("\n");
330 }
331 return buf.toString();
332 }
333
334
335 /**
336 * @return deep copy of this constant pool
337 */
338 public ConstantPool copy() {
339 ConstantPool c = null;
340 try {
341 c = (ConstantPool) clone();
342 c.constant_pool = new Constant[constant_pool_count];
343 for (int i = 1; i < constant_pool_count; i++) {
344 if (constant_pool[i] != null) {
345 c.constant_pool[i] = constant_pool[i].copy();
346 }
347 }
348 } catch (CloneNotSupportedException e) {
349 }
350 return c;
351 }
352 }
+0
-127
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantString.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from the abstract
25 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
26 * and represents a reference to a String object.
27 *
28 * @version $Id: ConstantString.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Constant
31 */
32 public final class ConstantString extends Constant implements ConstantObject {
33
34 private int string_index; // Identical to ConstantClass except for this name
35
36
37 /**
38 * Initialize from another object.
39 */
40 public ConstantString(ConstantString c) {
41 this(c.getStringIndex());
42 }
43
44
45 /**
46 * Initialize instance from file data.
47 *
48 * @param file Input stream
49 * @throws IOException
50 */
51 ConstantString(DataInputStream file) throws IOException {
52 this(file.readUnsignedShort());
53 }
54
55
56 /**
57 * @param string_index Index of Constant_Utf8 in constant pool
58 */
59 public ConstantString(int string_index) {
60 super(Constants.CONSTANT_String);
61 this.string_index = string_index;
62 }
63
64
65 /**
66 * Called by objects that are traversing the nodes of the tree implicitely
67 * defined by the contents of a Java class. I.e., the hierarchy of methods,
68 * fields, attributes, etc. spawns a tree of objects.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitConstantString(this);
74 }
75
76
77 /**
78 * Dump constant field reference to file stream in binary format.
79 *
80 * @param file Output file stream
81 * @throws IOException
82 */
83 public final void dump( DataOutputStream file ) throws IOException {
84 file.writeByte(tag);
85 file.writeShort(string_index);
86 }
87
88
89 /**
90 * @return Index in constant pool of the string (ConstantUtf8).
91 */
92 public final int getStringIndex() {
93 return string_index;
94 }
95
96
97 /**
98 * @param string_index the index into the constant of the string value
99 */
100 public final void setStringIndex( int string_index ) {
101 this.string_index = string_index;
102 }
103
104
105 /**
106 * @return String representation.
107 */
108 public final String toString() {
109 return super.toString() + "(string_index = " + string_index + ")";
110 }
111
112
113 /** @return String object
114 */
115 public Object getConstantValue( ConstantPool cp ) {
116 Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8);
117 return ((ConstantUtf8) c).getBytes();
118 }
119
120
121 /** @return dereferenced string
122 */
123 public String getBytes( ConstantPool cp ) {
124 return (String) getConstantValue(cp);
125 }
126 }
+0
-175
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantUtf8.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.util.HashMap;
22 import java.util.LinkedHashMap;
23 import java.util.Map;
24
25 import org.apache.bcel.Constants;
26 import org.apache.bcel.generic.ObjectType;
27
28 /**
29 * This class is derived from the abstract
30 * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
31 * and represents a reference to a Utf8 encoded string.
32 *
33 * @version $Id: ConstantUtf8.java 386056 2006-03-15 11:31:56Z tcurdt $
34 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35 * @see Constant
36 */
37 public final class ConstantUtf8 extends Constant {
38
39 private final String bytes;
40
41 private static final int MAX_CACHE_ENTRIES = 20000;
42 private static final int INITIAL_CACHE_CAPACITY = (int)(MAX_CACHE_ENTRIES/0.75);
43 private static HashMap<String, ConstantUtf8> cache;
44 private static int considered = 0;
45 private static int hits = 0;
46 private static int skipped = 0;
47 private static int created = 0;
48 final static boolean BCEL_STATISTICS = Boolean.getBoolean("bcel.statistics");
49 final static boolean BCEL_DONT_CACHE = Boolean.getBoolean("bcel.dontCache");
50
51 static {
52 if (BCEL_STATISTICS)
53 Runtime.getRuntime().addShutdownHook(new Thread() {
54 public void run() {
55 System.err.println("Cache hit " + hits + "/" + considered +", "
56 + skipped + " skipped");
57 System.err.println("Total of " + created + " ConstantUtf8 objects created");
58 }
59 });
60 }
61 public static synchronized ConstantUtf8 getCachedInstance(String s) {
62 if (BCEL_DONT_CACHE || s.length() > 200) {
63 skipped++;
64 return new ConstantUtf8(s);
65 }
66 considered++;
67 if (cache == null) {
68 cache = new LinkedHashMap<String, ConstantUtf8>(INITIAL_CACHE_CAPACITY, 0.75f, true) {
69
70 protected boolean removeEldestEntry(Map.Entry eldest) {
71 return size() > MAX_CACHE_ENTRIES;
72 }
73
74 };
75 }
76 ConstantUtf8 result = cache.get(s);
77 if (result != null) {
78 hits++;
79 return result;
80 }
81 result = new ConstantUtf8(s);
82 cache.put(s, result);
83 return result;
84 }
85
86 public static ConstantUtf8 getInstance(String s) {
87 return getCachedInstance(s);
88 }
89
90 public static ConstantUtf8 getInstance (DataInputStream file) throws IOException {
91 return getInstance(file.readUTF());
92 }
93 /**
94 * Initialize from another object.
95 */
96 public ConstantUtf8(ConstantUtf8 c) {
97 this(c.getBytes());
98 }
99
100
101 /**
102 * Initialize instance from file data.
103 *
104 * @param file Input stream
105 * @throws IOException
106 */
107 ConstantUtf8(DataInputStream file) throws IOException {
108 super(Constants.CONSTANT_Utf8);
109 bytes = file.readUTF();
110 created++;
111 }
112
113
114 /**
115 * @param bytes Data
116 */
117 public ConstantUtf8(String bytes) {
118 super(Constants.CONSTANT_Utf8);
119 if (bytes == null) {
120 throw new IllegalArgumentException("bytes must not be null!");
121 }
122 this.bytes = bytes;
123 created++;
124 }
125
126
127 /**
128 * Called by objects that are traversing the nodes of the tree implicitely
129 * defined by the contents of a Java class. I.e., the hierarchy of methods,
130 * fields, attributes, etc. spawns a tree of objects.
131 *
132 * @param v Visitor object
133 */
134 public void accept( Visitor v ) {
135 v.visitConstantUtf8(this);
136 }
137
138
139 /**
140 * Dump String in Utf8 format to file stream.
141 *
142 * @param file Output file stream
143 * @throws IOException
144 */
145 public final void dump( DataOutputStream file ) throws IOException {
146 file.writeByte(tag);
147 file.writeUTF(bytes);
148 }
149
150
151 /**
152 * @return Data converted to string.
153 */
154 public final String getBytes() {
155 return bytes;
156 }
157
158
159 /**
160 * @param bytes the raw bytes of this Utf-8
161 * @deprecated
162 */
163 public final void setBytes( String bytes ) {
164 throw new UnsupportedOperationException();
165 }
166
167
168 /**
169 * @return String representation
170 */
171 public final String toString() {
172 return super.toString() + "(\"" + Utility.replace(bytes, "\n", "\\n") + "\")";
173 }
174 }
+0
-155
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ConstantValue.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and represents a constant
25 * value, i.e., a default value for initializing a class field.
26 * This class is instantiated by the <em>Attribute.readAttribute()</em> method.
27 *
28 * @version $Id: ConstantValue.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Attribute
31 */
32 public final class ConstantValue extends Attribute {
33
34 private int constantvalue_index;
35
36
37 /**
38 * Initialize from another object. Note that both objects use the same
39 * references (shallow copy). Use clone() for a physical copy.
40 */
41 public ConstantValue(ConstantValue c) {
42 this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(), c.getConstantPool());
43 }
44
45
46 /**
47 * Construct object from file stream.
48 * @param name_index Name index in constant pool
49 * @param length Content length in bytes
50 * @param file Input stream
51 * @param constant_pool Array of constants
52 * @throws IOException
53 */
54 ConstantValue(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
55 throws IOException {
56 this(name_index, length, file.readUnsignedShort(), constant_pool);
57 }
58
59
60 /**
61 * @param name_index Name index in constant pool
62 * @param length Content length in bytes
63 * @param constantvalue_index Index in constant pool
64 * @param constant_pool Array of constants
65 */
66 public ConstantValue(int name_index, int length, int constantvalue_index,
67 ConstantPool constant_pool) {
68 super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool);
69 this.constantvalue_index = constantvalue_index;
70 }
71
72
73 /**
74 * Called by objects that are traversing the nodes of the tree implicitely
75 * defined by the contents of a Java class. I.e., the hierarchy of methods,
76 * fields, attributes, etc. spawns a tree of objects.
77 *
78 * @param v Visitor object
79 */
80 public void accept( Visitor v ) {
81 v.visitConstantValue(this);
82 }
83
84
85 /**
86 * Dump constant value attribute to file stream on binary format.
87 *
88 * @param file Output file stream
89 * @throws IOException
90 */
91 public final void dump( DataOutputStream file ) throws IOException {
92 super.dump(file);
93 file.writeShort(constantvalue_index);
94 }
95
96
97 /**
98 * @return Index in constant pool of constant value.
99 */
100 public final int getConstantValueIndex() {
101 return constantvalue_index;
102 }
103
104
105 /**
106 * @param constantvalue_index the index info the constant pool of this constant value
107 */
108 public final void setConstantValueIndex( int constantvalue_index ) {
109 this.constantvalue_index = constantvalue_index;
110 }
111
112
113 /**
114 * @return String representation of constant value.
115 */
116 public final String toString() {
117 Constant c = constant_pool.getConstant(constantvalue_index);
118 String buf;
119 int i;
120 // Print constant to string depending on its type
121 switch (c.getTag()) {
122 case Constants.CONSTANT_Long:
123 buf = "" + ((ConstantLong) c).getBytes();
124 break;
125 case Constants.CONSTANT_Float:
126 buf = "" + ((ConstantFloat) c).getBytes();
127 break;
128 case Constants.CONSTANT_Double:
129 buf = "" + ((ConstantDouble) c).getBytes();
130 break;
131 case Constants.CONSTANT_Integer:
132 buf = "" + ((ConstantInteger) c).getBytes();
133 break;
134 case Constants.CONSTANT_String:
135 i = ((ConstantString) c).getStringIndex();
136 c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8);
137 buf = "\"" + Utility.convertString(((ConstantUtf8) c).getBytes()) + "\"";
138 break;
139 default:
140 throw new IllegalStateException("Type of ConstValue invalid: " + c);
141 }
142 return buf;
143 }
144
145
146 /**
147 * @return deep copy of this attribute
148 */
149 public Attribute copy( ConstantPool _constant_pool ) {
150 ConstantValue c = (ConstantValue) clone();
151 c.constant_pool = _constant_pool;
152 return c;
153 }
154 }
+0
-140
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Deprecated.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and denotes that this is a
25 * deprecated method.
26 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
27 *
28 * @version $Id: Deprecated.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Attribute
31 */
32 public final class Deprecated extends Attribute {
33
34 private byte[] bytes;
35
36
37 /**
38 * Initialize from another object. Note that both objects use the same
39 * references (shallow copy). Use clone() for a physical copy.
40 */
41 public Deprecated(Deprecated c) {
42 this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
43 }
44
45
46 /**
47 * @param name_index Index in constant pool to CONSTANT_Utf8
48 * @param length Content length in bytes
49 * @param bytes Attribute contents
50 * @param constant_pool Array of constants
51 */
52 public Deprecated(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
53 super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool);
54 this.bytes = bytes;
55 }
56
57
58 /**
59 * Construct object from file stream.
60 * @param name_index Index in constant pool to CONSTANT_Utf8
61 * @param length Content length in bytes
62 * @param file Input stream
63 * @param constant_pool Array of constants
64 * @throws IOException
65 */
66 Deprecated(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
67 throws IOException {
68 this(name_index, length, (byte[]) null, constant_pool);
69 if (length > 0) {
70 bytes = new byte[length];
71 file.readFully(bytes);
72 System.err.println("Deprecated attribute with length > 0");
73 }
74 }
75
76
77 /**
78 * Called by objects that are traversing the nodes of the tree implicitely
79 * defined by the contents of a Java class. I.e., the hierarchy of methods,
80 * fields, attributes, etc. spawns a tree of objects.
81 *
82 * @param v Visitor object
83 */
84 public void accept( Visitor v ) {
85 v.visitDeprecated(this);
86 }
87
88
89 /**
90 * Dump source file attribute to file stream in binary format.
91 *
92 * @param file Output file stream
93 * @throws IOException
94 */
95 public final void dump( DataOutputStream file ) throws IOException {
96 super.dump(file);
97 if (length > 0) {
98 file.write(bytes, 0, length);
99 }
100 }
101
102
103 /**
104 * @return data bytes.
105 */
106 public final byte[] getBytes() {
107 return bytes;
108 }
109
110
111 /**
112 * @param bytes the raw bytes that represents this byte array
113 */
114 public final void setBytes( byte[] bytes ) {
115 this.bytes = bytes;
116 }
117
118
119 /**
120 * @return attribute name
121 */
122 public final String toString() {
123 return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED];
124 }
125
126
127 /**
128 * @return deep copy of this attribute
129 */
130 public Attribute copy( ConstantPool _constant_pool ) {
131 Deprecated c = (Deprecated) clone();
132 if (bytes != null) {
133 c.bytes = new byte[bytes.length];
134 System.arraycopy(bytes, 0, c.bytes, 0, bytes.length);
135 }
136 c.constant_pool = _constant_pool;
137 return c;
138 }
139 }
+0
-359
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/DescendingVisitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.util.Stack;
19
20 /**
21 * Traverses a JavaClass with another Visitor object 'piggy-backed'
22 * that is applied to all components of a JavaClass object. I.e. this
23 * class supplies the traversal strategy, other classes can make use
24 * of it.
25 *
26 * @version $Id: DescendingVisitor.java 388707 2006-03-25 05:40:28Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public class DescendingVisitor implements Visitor {
30
31 private JavaClass clazz;
32 private Visitor visitor;
33 private Stack stack = new Stack();
34
35
36 /** @return container of current entitity, i.e., predecessor during traversal
37 */
38 public Object predecessor() {
39 return predecessor(0);
40 }
41
42
43 /**
44 * @param level nesting level, i.e., 0 returns the direct predecessor
45 * @return container of current entitity, i.e., predecessor during traversal
46 */
47 public Object predecessor( int level ) {
48 int size = stack.size();
49 if ((size < 2) || (level < 0)) {
50 return null;
51 } else {
52 return stack.elementAt(size - (level + 2)); // size - 1 == current
53 }
54 }
55
56
57 /** @return current object
58 */
59 public Object current() {
60 return stack.peek();
61 }
62
63
64 /**
65 * @param clazz Class to traverse
66 * @param visitor visitor object to apply to all components
67 */
68 public DescendingVisitor(JavaClass clazz, Visitor visitor) {
69 this.clazz = clazz;
70 this.visitor = visitor;
71 }
72
73
74 /**
75 * Start traversal.
76 */
77 public void visit() {
78 clazz.accept(this);
79 }
80
81
82 public void visitJavaClass( JavaClass _clazz ) {
83 stack.push(_clazz);
84 _clazz.accept(visitor);
85 Field[] fields = _clazz.getFields();
86 for (int i = 0; i < fields.length; i++) {
87 fields[i].accept(this);
88 }
89 Method[] methods = _clazz.getMethods();
90 for (int i = 0; i < methods.length; i++) {
91 methods[i].accept(this);
92 }
93 Attribute[] attributes = _clazz.getAttributes();
94 for (int i = 0; i < attributes.length; i++) {
95 attributes[i].accept(this);
96 }
97 _clazz.getConstantPool().accept(this);
98 stack.pop();
99 }
100
101
102 public void visitField( Field field ) {
103 stack.push(field);
104 field.accept(visitor);
105 Attribute[] attributes = field.getAttributes();
106 for (int i = 0; i < attributes.length; i++) {
107 attributes[i].accept(this);
108 }
109 stack.pop();
110 }
111
112
113 public void visitConstantValue( ConstantValue cv ) {
114 stack.push(cv);
115 cv.accept(visitor);
116 stack.pop();
117 }
118
119
120 public void visitMethod( Method method ) {
121 stack.push(method);
122 method.accept(visitor);
123 Attribute[] attributes = method.getAttributes();
124 for (int i = 0; i < attributes.length; i++) {
125 attributes[i].accept(this);
126 }
127 stack.pop();
128 }
129
130
131 public void visitExceptionTable( ExceptionTable table ) {
132 stack.push(table);
133 table.accept(visitor);
134 stack.pop();
135 }
136
137
138 public void visitCode( Code code ) {
139 stack.push(code);
140 code.accept(visitor);
141 CodeException[] table = code.getExceptionTable();
142 for (int i = 0; i < table.length; i++) {
143 table[i].accept(this);
144 }
145 Attribute[] attributes = code.getAttributes();
146 for (int i = 0; i < attributes.length; i++) {
147 attributes[i].accept(this);
148 }
149 stack.pop();
150 }
151
152
153 public void visitCodeException( CodeException ce ) {
154 stack.push(ce);
155 ce.accept(visitor);
156 stack.pop();
157 }
158
159
160 public void visitLineNumberTable( LineNumberTable table ) {
161 stack.push(table);
162 table.accept(visitor);
163 LineNumber[] numbers = table.getLineNumberTable();
164 for (int i = 0; i < numbers.length; i++) {
165 numbers[i].accept(this);
166 }
167 stack.pop();
168 }
169
170
171 public void visitLineNumber( LineNumber number ) {
172 stack.push(number);
173 number.accept(visitor);
174 stack.pop();
175 }
176
177
178 public void visitLocalVariableTable( LocalVariableTable table ) {
179 stack.push(table);
180 table.accept(visitor);
181 LocalVariable[] vars = table.getLocalVariableTable();
182 for (int i = 0; i < vars.length; i++) {
183 vars[i].accept(this);
184 }
185 stack.pop();
186 }
187 public void visitLocalVariableTypeTable( LocalVariableTypeTable table ) {
188
189 }
190
191
192 public void visitStackMap( StackMap table ) {
193 stack.push(table);
194 table.accept(visitor);
195 StackMapEntry[] vars = table.getStackMap();
196 for (int i = 0; i < vars.length; i++) {
197 vars[i].accept(this);
198 }
199 stack.pop();
200 }
201
202
203 public void visitStackMapEntry( StackMapEntry var ) {
204 stack.push(var);
205 var.accept(visitor);
206 stack.pop();
207 }
208
209
210 public void visitLocalVariable( LocalVariable var ) {
211 stack.push(var);
212 var.accept(visitor);
213 stack.pop();
214 }
215
216
217 public void visitConstantPool( ConstantPool cp ) {
218 stack.push(cp);
219 cp.accept(visitor);
220 Constant[] constants = cp.getConstantPool();
221 for (int i = 1; i < constants.length; i++) {
222 if (constants[i] != null) {
223 constants[i].accept(this);
224 }
225 }
226 stack.pop();
227 }
228
229
230 public void visitConstantClass( ConstantClass constant ) {
231 stack.push(constant);
232 constant.accept(visitor);
233 stack.pop();
234 }
235
236
237 public void visitConstantDouble( ConstantDouble constant ) {
238 stack.push(constant);
239 constant.accept(visitor);
240 stack.pop();
241 }
242
243
244 public void visitConstantFieldref( ConstantFieldref constant ) {
245 stack.push(constant);
246 constant.accept(visitor);
247 stack.pop();
248 }
249
250
251 public void visitConstantFloat( ConstantFloat constant ) {
252 stack.push(constant);
253 constant.accept(visitor);
254 stack.pop();
255 }
256
257
258 public void visitConstantInteger( ConstantInteger constant ) {
259 stack.push(constant);
260 constant.accept(visitor);
261 stack.pop();
262 }
263
264
265 public void visitConstantInterfaceMethodref( ConstantInterfaceMethodref constant ) {
266 stack.push(constant);
267 constant.accept(visitor);
268 stack.pop();
269 }
270
271
272 public void visitConstantLong( ConstantLong constant ) {
273 stack.push(constant);
274 constant.accept(visitor);
275 stack.pop();
276 }
277
278
279 public void visitConstantMethodref( ConstantMethodref constant ) {
280 stack.push(constant);
281 constant.accept(visitor);
282 stack.pop();
283 }
284
285
286 public void visitConstantNameAndType( ConstantNameAndType constant ) {
287 stack.push(constant);
288 constant.accept(visitor);
289 stack.pop();
290 }
291
292
293 public void visitConstantString( ConstantString constant ) {
294 stack.push(constant);
295 constant.accept(visitor);
296 stack.pop();
297 }
298
299
300 public void visitConstantUtf8( ConstantUtf8 constant ) {
301 stack.push(constant);
302 constant.accept(visitor);
303 stack.pop();
304 }
305
306
307 public void visitInnerClasses( InnerClasses ic ) {
308 stack.push(ic);
309 ic.accept(visitor);
310 InnerClass[] ics = ic.getInnerClasses();
311 for (int i = 0; i < ics.length; i++) {
312 ics[i].accept(this);
313 }
314 stack.pop();
315 }
316
317
318 public void visitInnerClass( InnerClass inner ) {
319 stack.push(inner);
320 inner.accept(visitor);
321 stack.pop();
322 }
323
324
325 public void visitDeprecated( Deprecated attribute ) {
326 stack.push(attribute);
327 attribute.accept(visitor);
328 stack.pop();
329 }
330
331
332 public void visitSignature( Signature attribute ) {
333 stack.push(attribute);
334 attribute.accept(visitor);
335 stack.pop();
336 }
337
338
339 public void visitSourceFile( SourceFile attribute ) {
340 stack.push(attribute);
341 attribute.accept(visitor);
342 stack.pop();
343 }
344
345
346 public void visitSynthetic( Synthetic attribute ) {
347 stack.push(attribute);
348 attribute.accept(visitor);
349 stack.pop();
350 }
351
352
353 public void visitUnknown( Unknown attribute ) {
354 stack.push(attribute);
355 attribute.accept(visitor);
356 stack.pop();
357 }
358 }
+0
-167
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/EmptyVisitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * Visitor with empty method bodies, can be extended and used in conjunction with the
20 * DescendingVisitor class, e.g.
21 *
22 * By courtesy of David Spencer.
23 *
24 * @see DescendingVisitor
25 * @version $Id: EmptyVisitor.java 388707 2006-03-25 05:40:28Z tcurdt $
26 *
27 */
28 public class EmptyVisitor implements Visitor {
29
30 protected EmptyVisitor() {
31 }
32
33
34 public void visitCode( Code obj ) {
35 }
36
37
38 public void visitCodeException( CodeException obj ) {
39 }
40
41
42 public void visitConstantClass( ConstantClass obj ) {
43 }
44
45
46 public void visitConstantDouble( ConstantDouble obj ) {
47 }
48
49
50 public void visitConstantFieldref( ConstantFieldref obj ) {
51 }
52
53
54 public void visitConstantFloat( ConstantFloat obj ) {
55 }
56
57
58 public void visitConstantInteger( ConstantInteger obj ) {
59 }
60
61
62 public void visitConstantInterfaceMethodref( ConstantInterfaceMethodref obj ) {
63 }
64
65
66 public void visitConstantLong( ConstantLong obj ) {
67 }
68
69
70 public void visitConstantMethodref( ConstantMethodref obj ) {
71 }
72
73
74 public void visitConstantNameAndType( ConstantNameAndType obj ) {
75 }
76
77
78 public void visitConstantPool( ConstantPool obj ) {
79 }
80
81
82 public void visitConstantString( ConstantString obj ) {
83 }
84
85
86 public void visitConstantUtf8( ConstantUtf8 obj ) {
87 }
88
89
90 public void visitConstantValue( ConstantValue obj ) {
91 }
92
93
94 public void visitDeprecated( Deprecated obj ) {
95 }
96
97
98 public void visitExceptionTable( ExceptionTable obj ) {
99 }
100
101
102 public void visitField( Field obj ) {
103 }
104
105
106 public void visitInnerClass( InnerClass obj ) {
107 }
108
109
110 public void visitInnerClasses( InnerClasses obj ) {
111 }
112
113
114 public void visitJavaClass( JavaClass obj ) {
115 }
116
117
118 public void visitLineNumber( LineNumber obj ) {
119 }
120
121
122 public void visitLineNumberTable( LineNumberTable obj ) {
123 }
124
125
126 public void visitLocalVariable( LocalVariable obj ) {
127 }
128
129
130 public void visitLocalVariableTable( LocalVariableTable obj ) {
131 }
132
133
134 public void visitMethod( Method obj ) {
135 }
136
137
138 public void visitSignature( Signature obj ) {
139 }
140
141
142 public void visitSourceFile( SourceFile obj ) {
143 }
144
145
146 public void visitSynthetic( Synthetic obj ) {
147 }
148
149
150 public void visitUnknown( Unknown obj ) {
151 }
152
153
154 public void visitStackMap( StackMap obj ) {
155 }
156
157
158 public void visitStackMapEntry( StackMapEntry obj ) {
159 }
160
161
162 public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {
163 // TODO Auto-generated method stub
164
165 }
166 }
+0
-180
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/ExceptionTable.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents the table of exceptions that are thrown by a
25 * method. This attribute may be used once per method. The name of
26 * this class is <em>ExceptionTable</em> for historical reasons; The
27 * Java Virtual Machine Specification, Second Edition defines this
28 * attribute using the name <em>Exceptions</em> (which is inconsistent
29 * with the other classes).
30 *
31 * @version $Id: ExceptionTable.java 386056 2006-03-15 11:31:56Z tcurdt $
32 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33 * @see Code
34 */
35 public final class ExceptionTable extends Attribute {
36
37 private int number_of_exceptions; // Table of indices into
38 private int[] exception_index_table; // constant pool
39
40
41 /**
42 * Initialize from another object. Note that both objects use the same
43 * references (shallow copy). Use copy() for a physical copy.
44 */
45 public ExceptionTable(ExceptionTable c) {
46 this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), c.getConstantPool());
47 }
48
49
50 /**
51 * @param name_index Index in constant pool
52 * @param length Content length in bytes
53 * @param exception_index_table Table of indices in constant pool
54 * @param constant_pool Array of constants
55 */
56 public ExceptionTable(int name_index, int length, int[] exception_index_table,
57 ConstantPool constant_pool) {
58 super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool);
59 setExceptionIndexTable(exception_index_table);
60 }
61
62
63 /**
64 * Construct object from file stream.
65 * @param name_index Index in constant pool
66 * @param length Content length in bytes
67 * @param file Input stream
68 * @param constant_pool Array of constants
69 * @throws IOException
70 */
71 ExceptionTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
72 throws IOException {
73 this(name_index, length, (int[]) null, constant_pool);
74 number_of_exceptions = file.readUnsignedShort();
75 exception_index_table = new int[number_of_exceptions];
76 for (int i = 0; i < number_of_exceptions; i++) {
77 exception_index_table[i] = file.readUnsignedShort();
78 }
79 }
80
81
82 /**
83 * Called by objects that are traversing the nodes of the tree implicitely
84 * defined by the contents of a Java class. I.e., the hierarchy of methods,
85 * fields, attributes, etc. spawns a tree of objects.
86 *
87 * @param v Visitor object
88 */
89 public void accept( Visitor v ) {
90 v.visitExceptionTable(this);
91 }
92
93
94 /**
95 * Dump exceptions attribute to file stream in binary format.
96 *
97 * @param file Output file stream
98 * @throws IOException
99 */
100 public final void dump( DataOutputStream file ) throws IOException {
101 super.dump(file);
102 file.writeShort(number_of_exceptions);
103 for (int i = 0; i < number_of_exceptions; i++) {
104 file.writeShort(exception_index_table[i]);
105 }
106 }
107
108
109 /**
110 * @return Array of indices into constant pool of thrown exceptions.
111 */
112 public final int[] getExceptionIndexTable() {
113 return exception_index_table;
114 }
115
116
117 /**
118 * @return Length of exception table.
119 */
120 public final int getNumberOfExceptions() {
121 return number_of_exceptions;
122 }
123
124
125 /**
126 * @return class names of thrown exceptions
127 */
128 public final String[] getExceptionNames() {
129 String[] names = new String[number_of_exceptions];
130 for (int i = 0; i < number_of_exceptions; i++) {
131 names[i] = constant_pool.getConstantString(exception_index_table[i],
132 Constants.CONSTANT_Class).replace('/', '.');
133 }
134 return names;
135 }
136
137
138 /**
139 * @param exception_index_table the list of exception indexes
140 * Also redefines number_of_exceptions according to table length.
141 */
142 public final void setExceptionIndexTable( int[] exception_index_table ) {
143 this.exception_index_table = exception_index_table;
144 number_of_exceptions = (exception_index_table == null) ? 0 : exception_index_table.length;
145 }
146
147
148 /**
149 * @return String representation, i.e., a list of thrown exceptions.
150 */
151 public final String toString() {
152 StringBuffer buf = new StringBuffer("");
153 String str;
154 for (int i = 0; i < number_of_exceptions; i++) {
155 str = constant_pool.getConstantString(exception_index_table[i],
156 Constants.CONSTANT_Class);
157 buf.append(Utility.compactClassName(str, false));
158 if (i < number_of_exceptions - 1) {
159 buf.append(", ");
160 }
161 }
162 return buf.toString();
163 }
164
165
166 /**
167 * @return deep copy of this attribute
168 */
169 public Attribute copy( ConstantPool _constant_pool ) {
170 ExceptionTable c = (ExceptionTable) clone();
171 if (exception_index_table != null) {
172 c.exception_index_table = new int[exception_index_table.length];
173 System.arraycopy(exception_index_table, 0, c.exception_index_table, 0,
174 exception_index_table.length);
175 }
176 c.constant_pool = _constant_pool;
177 return c;
178 }
179 }
+0
-190
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Field.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.generic.Type;
22 import org.apache.bcel.util.BCELComparator;
23
24 /**
25 * This class represents the field info structure, i.e., the representation
26 * for a variable in the class. See JVM specification for details.
27 *
28 * @version $Id: Field.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public final class Field extends FieldOrMethod {
32
33 private static BCELComparator _cmp = new BCELComparator() {
34
35 public boolean equals( Object o1, Object o2 ) {
36 Field THIS = (Field) o1;
37 Field THAT = (Field) o2;
38 return THIS.getName().equals(THAT.getName())
39 && THIS.getSignature().equals(THAT.getSignature());
40 }
41
42
43 public int hashCode( Object o ) {
44 Field THIS = (Field) o;
45 return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
46 }
47 };
48
49
50 /**
51 * Initialize from another object. Note that both objects use the same
52 * references (shallow copy). Use clone() for a physical copy.
53 */
54 public Field(Field c) {
55 super(c);
56 }
57
58
59 /**
60 * Construct object from file stream.
61 * @param file Input stream
62 */
63 Field(DataInputStream file, ConstantPool constant_pool) throws IOException,
64 ClassFormatException {
65 super(file, constant_pool);
66 }
67
68
69 /**
70 * @param access_flags Access rights of field
71 * @param name_index Points to field name in constant pool
72 * @param signature_index Points to encoded signature
73 * @param attributes Collection of attributes
74 * @param constant_pool Array of constants
75 */
76 public Field(int access_flags, int name_index, int signature_index, Attribute[] attributes,
77 ConstantPool constant_pool) {
78 super(access_flags, name_index, signature_index, attributes, constant_pool);
79 }
80
81
82 /**
83 * Called by objects that are traversing the nodes of the tree implicitely
84 * defined by the contents of a Java class. I.e., the hierarchy of methods,
85 * fields, attributes, etc. spawns a tree of objects.
86 *
87 * @param v Visitor object
88 */
89 public void accept( Visitor v ) {
90 v.visitField(this);
91 }
92
93
94 /**
95 * @return constant value associated with this field (may be null)
96 */
97 public final ConstantValue getConstantValue() {
98 for (int i = 0; i < attributes_count; i++) {
99 if (attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) {
100 return (ConstantValue) attributes[i];
101 }
102 }
103 return null;
104 }
105
106
107 /**
108 * Return string representation close to declaration format,
109 * `public static final short MAX = 100', e.g..
110 *
111 * @return String representation of field, including the signature.
112 */
113 public final String toString() {
114 String name, signature, access; // Short cuts to constant pool
115 // Get names from constant pool
116 access = Utility.accessToString(access_flags);
117 access = access.equals("") ? "" : (access + " ");
118 signature = Utility.signatureToString(getSignature());
119 name = getName();
120 StringBuffer buf = new StringBuffer(64);
121 buf.append(access).append(signature).append(" ").append(name);
122 ConstantValue cv = getConstantValue();
123 if (cv != null) {
124 buf.append(" = ").append(cv);
125 }
126 for (int i = 0; i < attributes_count; i++) {
127 Attribute a = attributes[i];
128 if (!(a instanceof ConstantValue)) {
129 buf.append(" [").append(a.toString()).append("]");
130 }
131 }
132 return buf.toString();
133 }
134
135
136 /**
137 * @return deep copy of this field
138 */
139 public final Field copy( ConstantPool _constant_pool ) {
140 return (Field) copy_(_constant_pool);
141 }
142
143
144 /**
145 * @return type of field
146 */
147 public Type getType() {
148 return Type.getReturnType(getSignature());
149 }
150
151
152 /**
153 * @return Comparison strategy object
154 */
155 public static BCELComparator getComparator() {
156 return _cmp;
157 }
158
159
160 /**
161 * @param comparator Comparison strategy object
162 */
163 public static void setComparator( BCELComparator comparator ) {
164 _cmp = comparator;
165 }
166
167
168 /**
169 * Return value as defined by given BCELComparator strategy.
170 * By default two Field objects are said to be equal when
171 * their names and signatures are equal.
172 *
173 * @see java.lang.Object#equals(java.lang.Object)
174 */
175 public boolean equals( Object obj ) {
176 return _cmp.equals(this, obj);
177 }
178
179
180 /**
181 * Return value as defined by given BCELComparator strategy.
182 * By default return the hashcode of the field's name XOR signature.
183 *
184 * @see java.lang.Object#hashCode()
185 */
186 public int hashCode() {
187 return _cmp.hashCode(this);
188 }
189 }
+0
-206
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/FieldOrMethod.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * Abstract super class for fields and methods.
25 *
26 * @version $Id: FieldOrMethod.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
30
31 protected int name_index; // Points to field name in constant pool
32 protected int signature_index; // Points to encoded signature
33 protected int attributes_count; // No. of attributes
34 protected Attribute[] attributes; // Collection of attributes
35 protected ConstantPool constant_pool;
36
37
38 FieldOrMethod() {
39 }
40
41
42 /**
43 * Initialize from another object. Note that both objects use the same
44 * references (shallow copy). Use clone() for a physical copy.
45 */
46 protected FieldOrMethod(FieldOrMethod c) {
47 this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(), c.getAttributes(), c
48 .getConstantPool());
49 }
50
51
52 /**
53 * Construct object from file stream.
54 * @param file Input stream
55 * @throws IOException
56 * @throws ClassFormatException
57 */
58 protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) throws IOException,
59 ClassFormatException {
60 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
61 constant_pool);
62 attributes_count = file.readUnsignedShort();
63 attributes = new Attribute[attributes_count];
64 for (int i = 0; i < attributes_count; i++) {
65 attributes[i] = Attribute.readAttribute(file, constant_pool);
66 }
67 }
68
69
70 /**
71 * @param access_flags Access rights of method
72 * @param name_index Points to field name in constant pool
73 * @param signature_index Points to encoded signature
74 * @param attributes Collection of attributes
75 * @param constant_pool Array of constants
76 */
77 protected FieldOrMethod(int access_flags, int name_index, int signature_index,
78 Attribute[] attributes, ConstantPool constant_pool) {
79 this.access_flags = access_flags;
80 this.name_index = name_index;
81 this.signature_index = signature_index;
82 this.constant_pool = constant_pool;
83 setAttributes(attributes);
84 }
85
86
87 /**
88 * Dump object to file stream on binary format.
89 *
90 * @param file Output file stream
91 * @throws IOException
92 */
93 public final void dump( DataOutputStream file ) throws IOException {
94 file.writeShort(access_flags);
95 file.writeShort(name_index);
96 file.writeShort(signature_index);
97 file.writeShort(attributes_count);
98 for (int i = 0; i < attributes_count; i++) {
99 attributes[i].dump(file);
100 }
101 }
102
103
104 /**
105 * @return Collection of object attributes.
106 */
107 public final Attribute[] getAttributes() {
108 return attributes;
109 }
110
111
112 /**
113 * @param attributes Collection of object attributes.
114 */
115 public final void setAttributes( Attribute[] attributes ) {
116 this.attributes = attributes;
117 attributes_count = (attributes == null) ? 0 : attributes.length;
118 }
119
120
121 /**
122 * @return Constant pool used by this object.
123 */
124 public final ConstantPool getConstantPool() {
125 return constant_pool;
126 }
127
128
129 /**
130 * @param constant_pool Constant pool to be used for this object.
131 */
132 public final void setConstantPool( ConstantPool constant_pool ) {
133 this.constant_pool = constant_pool;
134 }
135
136
137 /**
138 * @return Index in constant pool of object's name.
139 */
140 public final int getNameIndex() {
141 return name_index;
142 }
143
144
145 /**
146 * @param name_index Index in constant pool of object's name.
147 */
148 public final void setNameIndex( int name_index ) {
149 this.name_index = name_index;
150 }
151
152
153 /**
154 * @return Index in constant pool of field signature.
155 */
156 public final int getSignatureIndex() {
157 return signature_index;
158 }
159
160
161 /**
162 * @param signature_index Index in constant pool of field signature.
163 */
164 public final void setSignatureIndex( int signature_index ) {
165 this.signature_index = signature_index;
166 }
167
168
169 /**
170 * @return Name of object, i.e., method name or field name
171 */
172 public final String getName() {
173 ConstantUtf8 c;
174 c = (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
175 return c.getBytes();
176 }
177
178
179 /**
180 * @return String representation of object's type signature (java style)
181 */
182 public final String getSignature() {
183 ConstantUtf8 c;
184 c = (ConstantUtf8) constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8);
185 return c.getBytes();
186 }
187
188
189 /**
190 * @return deep copy of this field
191 */
192 protected FieldOrMethod copy_( ConstantPool _constant_pool ) {
193 try {
194 FieldOrMethod c = (FieldOrMethod) clone();
195 c.constant_pool = _constant_pool;
196 c.attributes = new Attribute[attributes_count];
197 for (int i = 0; i < attributes_count; i++) {
198 c.attributes[i] = attributes[i].copy(_constant_pool);
199 }
200 return c;
201 } catch (CloneNotSupportedException e) {
202 return null;
203 }
204 }
205 }
+0
-214
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/InnerClass.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import org.apache.bcel.Constants;
23
24 /**
25 * This class represents a inner class attribute, i.e., the class
26 * indices of the inner and outer classes, the name and the attributes
27 * of the inner class.
28 *
29 * @version $Id: InnerClass.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see InnerClasses
32 */
33 public final class InnerClass implements Cloneable, Node, Serializable {
34
35 private int inner_class_index;
36 private int outer_class_index;
37 private int inner_name_index;
38 private int inner_access_flags;
39
40
41 /**
42 * Initialize from another object.
43 */
44 public InnerClass(InnerClass c) {
45 this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), c
46 .getInnerAccessFlags());
47 }
48
49
50 /**
51 * Construct object from file stream.
52 * @param file Input stream
53 * @throws IOException
54 */
55 InnerClass(DataInputStream file) throws IOException {
56 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
57 .readUnsignedShort());
58 }
59
60
61 /**
62 * @param inner_class_index Class index in constant pool of inner class
63 * @param outer_class_index Class index in constant pool of outer class
64 * @param inner_name_index Name index in constant pool of inner class
65 * @param inner_access_flags Access flags of inner class
66 */
67 public InnerClass(int inner_class_index, int outer_class_index, int inner_name_index,
68 int inner_access_flags) {
69 this.inner_class_index = inner_class_index;
70 this.outer_class_index = outer_class_index;
71 this.inner_name_index = inner_name_index;
72 this.inner_access_flags = inner_access_flags;
73 }
74
75
76 /**
77 * Called by objects that are traversing the nodes of the tree implicitely
78 * defined by the contents of a Java class. I.e., the hierarchy of methods,
79 * fields, attributes, etc. spawns a tree of objects.
80 *
81 * @param v Visitor object
82 */
83 public void accept( Visitor v ) {
84 v.visitInnerClass(this);
85 }
86
87
88 /**
89 * Dump inner class attribute to file stream in binary format.
90 *
91 * @param file Output file stream
92 * @throws IOException
93 */
94 public final void dump( DataOutputStream file ) throws IOException {
95 file.writeShort(inner_class_index);
96 file.writeShort(outer_class_index);
97 file.writeShort(inner_name_index);
98 file.writeShort(inner_access_flags);
99 }
100
101
102 /**
103 * @return access flags of inner class.
104 */
105 public final int getInnerAccessFlags() {
106 return inner_access_flags;
107 }
108
109
110 /**
111 * @return class index of inner class.
112 */
113 public final int getInnerClassIndex() {
114 return inner_class_index;
115 }
116
117
118 /**
119 * @return name index of inner class.
120 */
121 public final int getInnerNameIndex() {
122 return inner_name_index;
123 }
124
125
126 /**
127 * @return class index of outer class.
128 */
129 public final int getOuterClassIndex() {
130 return outer_class_index;
131 }
132
133
134 /**
135 * @param inner_access_flags access flags for this inner class
136 */
137 public final void setInnerAccessFlags( int inner_access_flags ) {
138 this.inner_access_flags = inner_access_flags;
139 }
140
141
142 /**
143 * @param inner_class_index index into the constant pool for this class
144 */
145 public final void setInnerClassIndex( int inner_class_index ) {
146 this.inner_class_index = inner_class_index;
147 }
148
149
150 /**
151 * @param inner_name_index index into the constant pool for this class's name
152 */
153 public final void setInnerNameIndex( int inner_name_index ) {
154 this.inner_name_index = inner_name_index;
155 }
156
157
158 /**
159 * @param outer_class_index index into the constant pool for the owning class
160 */
161 public final void setOuterClassIndex( int outer_class_index ) {
162 this.outer_class_index = outer_class_index;
163 }
164
165
166 /**
167 * @return String representation.
168 */
169 public final String toString() {
170 return "InnerClass(" + inner_class_index + ", " + outer_class_index + ", "
171 + inner_name_index + ", " + inner_access_flags + ")";
172 }
173
174
175 /**
176 * @return Resolved string representation
177 */
178 public final String toString( ConstantPool constant_pool ) {
179 String inner_class_name, outer_class_name, inner_name, access;
180 inner_class_name = constant_pool.getConstantString(inner_class_index,
181 Constants.CONSTANT_Class);
182 inner_class_name = Utility.compactClassName(inner_class_name);
183 if (outer_class_index != 0) {
184 outer_class_name = constant_pool.getConstantString(outer_class_index,
185 Constants.CONSTANT_Class);
186 outer_class_name = Utility.compactClassName(outer_class_name);
187 } else {
188 outer_class_name = "<not a member>";
189 }
190 if (inner_name_index != 0) {
191 inner_name = ((ConstantUtf8) constant_pool.getConstant(inner_name_index,
192 Constants.CONSTANT_Utf8)).getBytes();
193 } else {
194 inner_name = "<anonymous>";
195 }
196 access = Utility.accessToString(inner_access_flags, true);
197 access = access.equals("") ? "" : (access + " ");
198 return "InnerClass:" + access + inner_class_name + "(\"" + outer_class_name + "\", \""
199 + inner_name + "\")";
200 }
201
202
203 /**
204 * @return deep copy of this object
205 */
206 public InnerClass copy() {
207 try {
208 return (InnerClass) clone();
209 } catch (CloneNotSupportedException e) {
210 }
211 return null;
212 }
213 }
+0
-150
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/InnerClasses.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and denotes that this class
25 * is an Inner class of another.
26 * to the source file of this class.
27 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
28 *
29 * @version $Id: InnerClasses.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see Attribute
32 */
33 public final class InnerClasses extends Attribute {
34
35 private InnerClass[] inner_classes;
36 private int number_of_classes;
37
38
39 /**
40 * Initialize from another object. Note that both objects use the same
41 * references (shallow copy). Use clone() for a physical copy.
42 */
43 public InnerClasses(InnerClasses c) {
44 this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), c.getConstantPool());
45 }
46
47
48 /**
49 * @param name_index Index in constant pool to CONSTANT_Utf8
50 * @param length Content length in bytes
51 * @param inner_classes array of inner classes attributes
52 * @param constant_pool Array of constants
53 */
54 public InnerClasses(int name_index, int length, InnerClass[] inner_classes,
55 ConstantPool constant_pool) {
56 super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool);
57 setInnerClasses(inner_classes);
58 }
59
60
61 /**
62 * Construct object from file stream.
63 *
64 * @param name_index Index in constant pool to CONSTANT_Utf8
65 * @param length Content length in bytes
66 * @param file Input stream
67 * @param constant_pool Array of constants
68 * @throws IOException
69 */
70 InnerClasses(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
71 throws IOException {
72 this(name_index, length, (InnerClass[]) null, constant_pool);
73 number_of_classes = file.readUnsignedShort();
74 inner_classes = new InnerClass[number_of_classes];
75 for (int i = 0; i < number_of_classes; i++) {
76 inner_classes[i] = new InnerClass(file);
77 }
78 }
79
80
81 /**
82 * Called by objects that are traversing the nodes of the tree implicitely
83 * defined by the contents of a Java class. I.e., the hierarchy of methods,
84 * fields, attributes, etc. spawns a tree of objects.
85 *
86 * @param v Visitor object
87 */
88 public void accept( Visitor v ) {
89 v.visitInnerClasses(this);
90 }
91
92
93 /**
94 * Dump source file attribute to file stream in binary format.
95 *
96 * @param file Output file stream
97 * @throws IOException
98 */
99 public final void dump( DataOutputStream file ) throws IOException {
100 super.dump(file);
101 file.writeShort(number_of_classes);
102 for (int i = 0; i < number_of_classes; i++) {
103 inner_classes[i].dump(file);
104 }
105 }
106
107
108 /**
109 * @return array of inner class "records"
110 */
111 public final InnerClass[] getInnerClasses() {
112 return inner_classes;
113 }
114
115
116 /**
117 * @param inner_classes the array of inner classes
118 */
119 public final void setInnerClasses( InnerClass[] inner_classes ) {
120 this.inner_classes = inner_classes;
121 number_of_classes = (inner_classes == null) ? 0 : inner_classes.length;
122 }
123
124
125 /**
126 * @return String representation.
127 */
128 public final String toString() {
129 StringBuffer buf = new StringBuffer();
130 for (int i = 0; i < number_of_classes; i++) {
131 buf.append(inner_classes[i].toString(constant_pool)).append("\n");
132 }
133 return buf.toString();
134 }
135
136
137 /**
138 * @return deep copy of this attribute
139 */
140 public Attribute copy( ConstantPool _constant_pool ) {
141 InnerClasses c = (InnerClasses) clone();
142 c.inner_classes = new InnerClass[number_of_classes];
143 for (int i = 0; i < number_of_classes; i++) {
144 c.inner_classes[i] = inner_classes[i].copy();
145 }
146 c.constant_pool = _constant_pool;
147 return c;
148 }
149 }
+0
-866
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/JavaClass.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.DataOutputStream;
20 import java.io.File;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.OutputStream;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.StringTokenizer;
28 import java.util.TreeSet;
29 import org.apache.bcel.Constants;
30 import org.apache.bcel.generic.Type;
31 import org.apache.bcel.util.BCELComparator;
32 import org.apache.bcel.util.ClassQueue;
33 import org.apache.bcel.util.SyntheticRepository;
34
35 /**
36 * Represents a Java class, i.e., the data structures, constant pool,
37 * fields, methods and commands contained in a Java .class file.
38 * See <a href="ftp://java.sun.com/docs/specs/">JVM specification</a> for details.
39 * The intent of this class is to represent a parsed or otherwise existing
40 * class file. Those interested in programatically generating classes
41 * should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
42
43 * @version $Id: JavaClass.java 386056 2006-03-15 11:31:56Z tcurdt $
44 * @see org.apache.bcel.generic.ClassGen
45 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
46 */
47 public class JavaClass extends AccessFlags implements Cloneable, Node, Comparable {
48
49 private String file_name;
50 private String package_name;
51 private String source_file_name = "<Unknown>";
52 private int class_name_index;
53 private int superclass_name_index;
54 private String class_name;
55 private String superclass_name;
56 private int major, minor; // Compiler version
57 private ConstantPool constant_pool; // Constant pool
58 private int[] interfaces; // implemented interfaces
59 private String[] interface_names;
60 private Field[] fields; // Fields, i.e., variables of class
61 private Method[] methods; // methods defined in the class
62 private Attribute[] attributes; // attributes defined in the class
63 private byte source = HEAP; // Generated in memory
64 public static final byte HEAP = 1;
65 public static final byte FILE = 2;
66 public static final byte ZIP = 3;
67 static boolean debug = false; // Debugging on/off
68 static char sep = '/'; // directory separator
69 private static BCELComparator _cmp = new BCELComparator() {
70
71 public boolean equals( Object o1, Object o2 ) {
72 JavaClass THIS = (JavaClass) o1;
73 JavaClass THAT = (JavaClass) o2;
74 return THIS.getClassName().equals(THAT.getClassName());
75 }
76
77
78 public int hashCode( Object o ) {
79 JavaClass THIS = (JavaClass) o;
80 return THIS.getClassName().hashCode();
81 }
82 };
83 /**
84 * In cases where we go ahead and create something,
85 * use the default SyntheticRepository, because we
86 * don't know any better.
87 */
88 private transient org.apache.bcel.util.Repository repository = SyntheticRepository
89 .getInstance();
90
91
92 /**
93 * Constructor gets all contents as arguments.
94 *
95 * @param class_name_index Index into constant pool referencing a
96 * ConstantClass that represents this class.
97 * @param superclass_name_index Index into constant pool referencing a
98 * ConstantClass that represents this class's superclass.
99 * @param file_name File name
100 * @param major Major compiler version
101 * @param minor Minor compiler version
102 * @param access_flags Access rights defined by bit flags
103 * @param constant_pool Array of constants
104 * @param interfaces Implemented interfaces
105 * @param fields Class fields
106 * @param methods Class methods
107 * @param attributes Class attributes
108 * @param source Read from file or generated in memory?
109 */
110 public JavaClass(int class_name_index, int superclass_name_index, String file_name, int major,
111 int minor, int access_flags, ConstantPool constant_pool, int[] interfaces,
112 Field[] fields, Method[] methods, Attribute[] attributes, byte source) {
113 if (interfaces == null) {
114 interfaces = new int[0];
115 }
116 if (attributes == null) {
117 attributes = new Attribute[0];
118 }
119 if (fields == null) {
120 fields = new Field[0];
121 }
122 if (methods == null) {
123 methods = new Method[0];
124 }
125 this.class_name_index = class_name_index;
126 this.superclass_name_index = superclass_name_index;
127 this.file_name = file_name;
128 this.major = major;
129 this.minor = minor;
130 this.access_flags = access_flags;
131 this.constant_pool = constant_pool;
132 this.interfaces = interfaces;
133 this.fields = fields;
134 this.methods = methods;
135 this.attributes = attributes;
136 this.source = source;
137 // Get source file name if available
138 for (int i = 0; i < attributes.length; i++) {
139 if (attributes[i] instanceof SourceFile) {
140 source_file_name = ((SourceFile) attributes[i]).getSourceFileName();
141 break;
142 }
143 }
144 /* According to the specification the following entries must be of type
145 * `ConstantClass' but we check that anyway via the
146 * `ConstPool.getConstant' method.
147 */
148 class_name = constant_pool.getConstantString(class_name_index, Constants.CONSTANT_Class);
149 class_name = Utility.compactClassName(class_name, false);
150 int index = class_name.lastIndexOf('.');
151 if (index < 0) {
152 package_name = "";
153 } else {
154 package_name = class_name.substring(0, index);
155 }
156 if (superclass_name_index > 0) {
157 // May be zero -> class is java.lang.Object
158 superclass_name = constant_pool.getConstantString(superclass_name_index,
159 Constants.CONSTANT_Class);
160 superclass_name = Utility.compactClassName(superclass_name, false);
161 } else {
162 superclass_name = "java.lang.Object";
163 }
164 interface_names = new String[interfaces.length];
165 for (int i = 0; i < interfaces.length; i++) {
166 String str = constant_pool.getConstantString(interfaces[i], Constants.CONSTANT_Class);
167 interface_names[i] = Utility.compactClassName(str, false);
168 }
169 }
170
171
172 /**
173 * Constructor gets all contents as arguments.
174 *
175 * @param class_name_index Class name
176 * @param superclass_name_index Superclass name
177 * @param file_name File name
178 * @param major Major compiler version
179 * @param minor Minor compiler version
180 * @param access_flags Access rights defined by bit flags
181 * @param constant_pool Array of constants
182 * @param interfaces Implemented interfaces
183 * @param fields Class fields
184 * @param methods Class methods
185 * @param attributes Class attributes
186 */
187 public JavaClass(int class_name_index, int superclass_name_index, String file_name, int major,
188 int minor, int access_flags, ConstantPool constant_pool, int[] interfaces,
189 Field[] fields, Method[] methods, Attribute[] attributes) {
190 this(class_name_index, superclass_name_index, file_name, major, minor, access_flags,
191 constant_pool, interfaces, fields, methods, attributes, HEAP);
192 }
193
194
195 /**
196 * Called by objects that are traversing the nodes of the tree implicitely
197 * defined by the contents of a Java class. I.e., the hierarchy of methods,
198 * fields, attributes, etc. spawns a tree of objects.
199 *
200 * @param v Visitor object
201 */
202 public void accept( Visitor v ) {
203 v.visitJavaClass(this);
204 }
205
206
207 /* Print debug information depending on `JavaClass.debug'
208 */
209 static final void Debug( String str ) {
210 if (debug) {
211 System.out.println(str);
212 }
213 }
214
215
216 /**
217 * Dump class to a file.
218 *
219 * @param file Output file
220 * @throws IOException
221 */
222 public void dump( File file ) throws IOException {
223 String parent = file.getParent();
224 if (parent != null) {
225 File dir = new File(parent);
226 dir.mkdirs();
227 }
228 DataOutputStream dos = null;
229 try {
230 dos = new DataOutputStream(new FileOutputStream(file));
231 dump(dos);
232 } finally {
233 if (dos != null) {
234 dos.close();
235 }
236 }
237 }
238
239
240 /**
241 * Dump class to a file named file_name.
242 *
243 * @param _file_name Output file name
244 * @exception IOException
245 */
246 public void dump( String _file_name ) throws IOException {
247 dump(new File(_file_name));
248 }
249
250
251 /**
252 * @return class in binary format
253 */
254 public byte[] getBytes() {
255 ByteArrayOutputStream s = new ByteArrayOutputStream();
256 DataOutputStream ds = new DataOutputStream(s);
257 try {
258 dump(ds);
259 } catch (IOException e) {
260 e.printStackTrace();
261 } finally {
262 try {
263 ds.close();
264 } catch (IOException e2) {
265 e2.printStackTrace();
266 }
267 }
268 return s.toByteArray();
269 }
270
271
272 /**
273 * Dump Java class to output stream in binary format.
274 *
275 * @param file Output stream
276 * @exception IOException
277 */
278 public void dump( OutputStream file ) throws IOException {
279 dump(new DataOutputStream(file));
280 }
281
282
283 /**
284 * Dump Java class to output stream in binary format.
285 *
286 * @param file Output stream
287 * @exception IOException
288 */
289 public void dump( DataOutputStream file ) throws IOException {
290 file.writeInt(0xcafebabe);
291 file.writeShort(minor);
292 file.writeShort(major);
293 constant_pool.dump(file);
294 file.writeShort(access_flags);
295 file.writeShort(class_name_index);
296 file.writeShort(superclass_name_index);
297 file.writeShort(interfaces.length);
298 for (int i = 0; i < interfaces.length; i++) {
299 file.writeShort(interfaces[i]);
300 }
301 file.writeShort(fields.length);
302 for (int i = 0; i < fields.length; i++) {
303 fields[i].dump(file);
304 }
305 file.writeShort(methods.length);
306 for (int i = 0; i < methods.length; i++) {
307 methods[i].dump(file);
308 }
309 if (attributes != null) {
310 file.writeShort(attributes.length);
311 for (int i = 0; i < attributes.length; i++) {
312 attributes[i].dump(file);
313 }
314 } else {
315 file.writeShort(0);
316 }
317 file.flush();
318 }
319
320
321 /**
322 * @return Attributes of the class.
323 */
324 public Attribute[] getAttributes() {
325 return attributes;
326 }
327
328
329 /**
330 * @return Class name.
331 */
332 public String getClassName() {
333 return class_name;
334 }
335
336
337 /**
338 * @return Package name.
339 */
340 public String getPackageName() {
341 return package_name;
342 }
343
344
345 /**
346 * @return Class name index.
347 */
348 public int getClassNameIndex() {
349 return class_name_index;
350 }
351
352
353 /**
354 * @return Constant pool.
355 */
356 public ConstantPool getConstantPool() {
357 return constant_pool;
358 }
359
360
361 /**
362 * @return Fields, i.e., variables of the class. Like the JVM spec
363 * mandates for the classfile format, these fields are those specific to
364 * this class, and not those of the superclass or superinterfaces.
365 */
366 public Field[] getFields() {
367 return fields;
368 }
369
370
371 /**
372 * @return File name of class, aka SourceFile attribute value
373 */
374 public String getFileName() {
375 return file_name;
376 }
377
378
379 /**
380 * @return Names of implemented interfaces.
381 */
382 public String[] getInterfaceNames() {
383 return interface_names;
384 }
385
386
387 /**
388 * @return Indices in constant pool of implemented interfaces.
389 */
390 public int[] getInterfaceIndices() {
391 return interfaces;
392 }
393
394
395 /**
396 * @return Major number of class file version.
397 */
398 public int getMajor() {
399 return major;
400 }
401
402
403 /**
404 * @return Methods of the class.
405 */
406 public Method[] getMethods() {
407 return methods;
408 }
409
410
411 /**
412 * @return A org.apache.bcel.classfile.Method corresponding to
413 * java.lang.reflect.Method if any
414 */
415 public Method getMethod( java.lang.reflect.Method m ) {
416 for (int i = 0; i < methods.length; i++) {
417 Method method = methods[i];
418 if (m.getName().equals(method.getName()) && (m.getModifiers() == method.getModifiers())
419 && Type.getSignature(m).equals(method.getSignature())) {
420 return method;
421 }
422 }
423 return null;
424 }
425
426
427 /**
428 * @return Minor number of class file version.
429 */
430 public int getMinor() {
431 return minor;
432 }
433
434
435 /**
436 * @return sbsolute path to file where this class was read from
437 */
438 public String getSourceFileName() {
439 return source_file_name;
440 }
441
442
443 /**
444 * @return Superclass name.
445 */
446 public String getSuperclassName() {
447 return superclass_name;
448 }
449
450
451 /**
452 * @return Class name index.
453 */
454 public int getSuperclassNameIndex() {
455 return superclass_name_index;
456 }
457
458 static {
459 // Debugging ... on/off
460 debug = Boolean.getBoolean("JavaClass.debug");
461 // Get path separator either / or \ usually
462 String _sep = System.getProperty("file.separator");
463 if (_sep != null) {
464 try {
465 JavaClass.sep = _sep.charAt(0);
466 } catch (StringIndexOutOfBoundsException e) {
467 } // Never reached
468 }
469 }
470
471
472 /**
473 * @param attributes .
474 */
475 public void setAttributes( Attribute[] attributes ) {
476 this.attributes = attributes;
477 }
478
479
480 /**
481 * @param class_name .
482 */
483 public void setClassName( String class_name ) {
484 this.class_name = class_name;
485 }
486
487
488 /**
489 * @param class_name_index .
490 */
491 public void setClassNameIndex( int class_name_index ) {
492 this.class_name_index = class_name_index;
493 }
494
495
496 /**
497 * @param constant_pool .
498 */
499 public void setConstantPool( ConstantPool constant_pool ) {
500 this.constant_pool = constant_pool;
501 }
502
503
504 /**
505 * @param fields .
506 */
507 public void setFields( Field[] fields ) {
508 this.fields = fields;
509 }
510
511
512 /**
513 * Set File name of class, aka SourceFile attribute value
514 */
515 public void setFileName( String file_name ) {
516 this.file_name = file_name;
517 }
518
519
520 /**
521 * @param interface_names .
522 */
523 public void setInterfaceNames( String[] interface_names ) {
524 this.interface_names = interface_names;
525 }
526
527
528 /**
529 * @param interfaces .
530 */
531 public void setInterfaces( int[] interfaces ) {
532 this.interfaces = interfaces;
533 }
534
535
536 /**
537 * @param major .
538 */
539 public void setMajor( int major ) {
540 this.major = major;
541 }
542
543
544 /**
545 * @param methods .
546 */
547 public void setMethods( Method[] methods ) {
548 this.methods = methods;
549 }
550
551
552 /**
553 * @param minor .
554 */
555 public void setMinor( int minor ) {
556 this.minor = minor;
557 }
558
559
560 /**
561 * Set absolute path to file this class was read from.
562 */
563 public void setSourceFileName( String source_file_name ) {
564 this.source_file_name = source_file_name;
565 }
566
567
568 /**
569 * @param superclass_name .
570 */
571 public void setSuperclassName( String superclass_name ) {
572 this.superclass_name = superclass_name;
573 }
574
575
576 /**
577 * @param superclass_name_index .
578 */
579 public void setSuperclassNameIndex( int superclass_name_index ) {
580 this.superclass_name_index = superclass_name_index;
581 }
582
583
584 /**
585 * @return String representing class contents.
586 */
587 public String toString() {
588 String access = Utility.accessToString(access_flags, true);
589 access = access.equals("") ? "" : (access + " ");
590 StringBuffer buf = new StringBuffer(128);
591 buf.append(access).append(Utility.classOrInterface(access_flags)).append(" ").append(
592 class_name).append(" extends ").append(
593 Utility.compactClassName(superclass_name, false)).append('\n');
594 int size = interfaces.length;
595 if (size > 0) {
596 buf.append("implements\t\t");
597 for (int i = 0; i < size; i++) {
598 buf.append(interface_names[i]);
599 if (i < size - 1) {
600 buf.append(", ");
601 }
602 }
603 buf.append('\n');
604 }
605 buf.append("filename\t\t").append(file_name).append('\n');
606 buf.append("compiled from\t\t").append(source_file_name).append('\n');
607 buf.append("compiler version\t").append(major).append(".").append(minor).append('\n');
608 buf.append("access flags\t\t").append(access_flags).append('\n');
609 buf.append("constant pool\t\t").append(constant_pool.getLength()).append(" entries\n");
610 buf.append("ACC_SUPER flag\t\t").append(isSuper()).append("\n");
611 if (attributes.length > 0) {
612 buf.append("\nAttribute(s):\n");
613 for (int i = 0; i < attributes.length; i++) {
614 buf.append(indent(attributes[i]));
615 }
616 }
617 if (fields.length > 0) {
618 buf.append("\n").append(fields.length).append(" fields:\n");
619 for (int i = 0; i < fields.length; i++) {
620 buf.append("\t").append(fields[i]).append('\n');
621 }
622 }
623 if (methods.length > 0) {
624 buf.append("\n").append(methods.length).append(" methods:\n");
625 for (int i = 0; i < methods.length; i++) {
626 buf.append("\t").append(methods[i]).append('\n');
627 }
628 }
629 return buf.toString();
630 }
631
632
633 private static final String indent( Object obj ) {
634 StringTokenizer tok = new StringTokenizer(obj.toString(), "\n");
635 StringBuffer buf = new StringBuffer();
636 while (tok.hasMoreTokens()) {
637 buf.append("\t").append(tok.nextToken()).append("\n");
638 }
639 return buf.toString();
640 }
641
642
643 /**
644 * @return deep copy of this class
645 */
646 public JavaClass copy() {
647 JavaClass c = null;
648 try {
649 c = (JavaClass) clone();
650 c.constant_pool = constant_pool.copy();
651 c.interfaces = (int[]) interfaces.clone();
652 c.interface_names = (String[]) interface_names.clone();
653 c.fields = new Field[fields.length];
654 for (int i = 0; i < fields.length; i++) {
655 c.fields[i] = fields[i].copy(c.constant_pool);
656 }
657 c.methods = new Method[methods.length];
658 for (int i = 0; i < methods.length; i++) {
659 c.methods[i] = methods[i].copy(c.constant_pool);
660 }
661 c.attributes = new Attribute[attributes.length];
662 for (int i = 0; i < attributes.length; i++) {
663 c.attributes[i] = attributes[i].copy(c.constant_pool);
664 }
665 } catch (CloneNotSupportedException e) {
666 }
667 return c;
668 }
669
670
671 public final boolean isSuper() {
672 return (access_flags & Constants.ACC_SUPER) != 0;
673 }
674
675
676 public final boolean isClass() {
677 return (access_flags & Constants.ACC_INTERFACE) == 0;
678 }
679
680
681 /** @return returns either HEAP (generated), FILE, or ZIP
682 */
683 public final byte getSource() {
684 return source;
685 }
686
687
688 /********************* New repository functionality *********************/
689 /**
690 * Gets the ClassRepository which holds its definition. By default
691 * this is the same as SyntheticRepository.getInstance();
692 */
693 public org.apache.bcel.util.Repository getRepository() {
694 return repository;
695 }
696
697
698 /**
699 * Sets the ClassRepository which loaded the JavaClass.
700 * Should be called immediately after parsing is done.
701 */
702 public void setRepository( org.apache.bcel.util.Repository repository ) {
703 this.repository = repository;
704 }
705
706
707 /** Equivalent to runtime "instanceof" operator.
708 *
709 * @return true if this JavaClass is derived from the super class
710 * @throws ClassNotFoundException if superclasses or superinterfaces
711 * of this object can't be found
712 */
713 public final boolean instanceOf( JavaClass super_class ) throws ClassNotFoundException {
714 if (this.equals(super_class)) {
715 return true;
716 }
717 JavaClass[] super_classes = getSuperClasses();
718 for (int i = 0; i < super_classes.length; i++) {
719 if (super_classes[i].equals(super_class)) {
720 return true;
721 }
722 }
723 if (super_class.isInterface()) {
724 return implementationOf(super_class);
725 }
726 return false;
727 }
728
729
730 /**
731 * @return true, if this class is an implementation of interface inter
732 * @throws ClassNotFoundException if superclasses or superinterfaces
733 * of this class can't be found
734 */
735 public boolean implementationOf( JavaClass inter ) throws ClassNotFoundException {
736 if (!inter.isInterface()) {
737 throw new IllegalArgumentException(inter.getClassName() + " is no interface");
738 }
739 if (this.equals(inter)) {
740 return true;
741 }
742 JavaClass[] super_interfaces = getAllInterfaces();
743 for (int i = 0; i < super_interfaces.length; i++) {
744 if (super_interfaces[i].equals(inter)) {
745 return true;
746 }
747 }
748 return false;
749 }
750
751
752 /**
753 * @return the superclass for this JavaClass object, or null if this
754 * is java.lang.Object
755 * @throws ClassNotFoundException if the superclass can't be found
756 */
757 public JavaClass getSuperClass() throws ClassNotFoundException {
758 if ("java.lang.Object".equals(getClassName())) {
759 return null;
760 }
761 return repository.loadClass(getSuperclassName());
762 }
763
764
765 /**
766 * @return list of super classes of this class in ascending order, i.e.,
767 * java.lang.Object is always the last element
768 * @throws ClassNotFoundException if any of the superclasses can't be found
769 */
770 public JavaClass[] getSuperClasses() throws ClassNotFoundException {
771 JavaClass clazz = this;
772 List allSuperClasses = new ArrayList();
773 for (clazz = clazz.getSuperClass(); clazz != null; clazz = clazz.getSuperClass()) {
774 allSuperClasses.add(clazz);
775 }
776 return (JavaClass[]) allSuperClasses.toArray(new JavaClass[allSuperClasses.size()]);
777 }
778
779
780 /**
781 * Get interfaces directly implemented by this JavaClass.
782 */
783 public JavaClass[] getInterfaces() throws ClassNotFoundException {
784 String[] _interfaces = getInterfaceNames();
785 JavaClass[] classes = new JavaClass[_interfaces.length];
786 for (int i = 0; i < _interfaces.length; i++) {
787 classes[i] = repository.loadClass(_interfaces[i]);
788 }
789 return classes;
790 }
791
792
793 /**
794 * Get all interfaces implemented by this JavaClass (transitively).
795 */
796 public JavaClass[] getAllInterfaces() throws ClassNotFoundException {
797 ClassQueue queue = new ClassQueue();
798 Set allInterfaces = new TreeSet();
799 queue.enqueue(this);
800 while (!queue.empty()) {
801 JavaClass clazz = queue.dequeue();
802 JavaClass souper = clazz.getSuperClass();
803 JavaClass[] _interfaces = clazz.getInterfaces();
804 if (clazz.isInterface()) {
805 allInterfaces.add(clazz);
806 } else {
807 if (souper != null) {
808 queue.enqueue(souper);
809 }
810 }
811 for (int i = 0; i < _interfaces.length; i++) {
812 queue.enqueue(_interfaces[i]);
813 }
814 }
815 return (JavaClass[]) allInterfaces.toArray(new JavaClass[allInterfaces.size()]);
816 }
817
818
819 /**
820 * @return Comparison strategy object
821 */
822 public static BCELComparator getComparator() {
823 return _cmp;
824 }
825
826
827 /**
828 * @param comparator Comparison strategy object
829 */
830 public static void setComparator( BCELComparator comparator ) {
831 _cmp = comparator;
832 }
833
834
835 /**
836 * Return value as defined by given BCELComparator strategy.
837 * By default two JavaClass objects are said to be equal when
838 * their class names are equal.
839 *
840 * @see java.lang.Object#equals(java.lang.Object)
841 */
842 public boolean equals( Object obj ) {
843 return _cmp.equals(this, obj);
844 }
845
846
847 /**
848 * Return the natural ordering of two JavaClasses.
849 * This ordering is based on the class name
850 */
851 public int compareTo( Object obj ) {
852 return getClassName().compareTo(((JavaClass) obj).getClassName());
853 }
854
855
856 /**
857 * Return value as defined by given BCELComparator strategy.
858 * By default return the hashcode of the class name.
859 *
860 * @see java.lang.Object#hashCode()
861 */
862 public int hashCode() {
863 return _cmp.hashCode(this);
864 }
865 }
+0
-141
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/LineNumber.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22
23 /**
24 * This class represents a (PC offset, line number) pair, i.e., a line number in
25 * the source that corresponds to a relative address in the byte code. This
26 * is used for debugging purposes.
27 *
28 * @version $Id: LineNumber.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see LineNumberTable
31 */
32 public final class LineNumber implements Cloneable, Node, Serializable {
33
34 private short start_pc; // Program Counter (PC) corresponds to line
35 private short line_number; // number in source file
36
37
38 /**
39 * Initialize from another object.
40 */
41 public LineNumber(LineNumber c) {
42 this(c.getStartPC(), c.getLineNumber());
43 }
44
45
46 /**
47 * Construct object from file stream.
48 * @param file Input stream
49 * @throws IOException
50 */
51 LineNumber(DataInputStream file) throws IOException {
52 this(file.readUnsignedShort(), file.readUnsignedShort());
53 }
54
55
56 /**
57 * @param start_pc Program Counter (PC) corresponds to
58 * @param line_number line number in source file
59 */
60 public LineNumber(int start_pc, int line_number) {
61 this.start_pc = (short) start_pc;
62 this.line_number = (short)line_number;
63 }
64
65
66 /**
67 * Called by objects that are traversing the nodes of the tree implicitely
68 * defined by the contents of a Java class. I.e., the hierarchy of methods,
69 * fields, attributes, etc. spawns a tree of objects.
70 *
71 * @param v Visitor object
72 */
73 public void accept( Visitor v ) {
74 v.visitLineNumber(this);
75 }
76
77
78 /**
79 * Dump line number/pc pair to file stream in binary format.
80 *
81 * @param file Output file stream
82 * @throws IOException
83 */
84 public final void dump( DataOutputStream file ) throws IOException {
85 file.writeShort(start_pc);
86 file.writeShort(line_number);
87 }
88
89
90 /**
91 * @return Corresponding source line
92 */
93 public final int getLineNumber() {
94 return 0xffff & line_number;
95 }
96
97
98 /**
99 * @return PC in code
100 */
101 public final int getStartPC() {
102 return 0xffff & start_pc;
103 }
104
105
106 /**
107 * @param line_number the source line number
108 */
109 public final void setLineNumber( int line_number ) {
110 this.line_number = (short) line_number;
111 }
112
113
114 /**
115 * @param start_pc the pc for this line number
116 */
117 public final void setStartPC( int start_pc ) {
118 this.start_pc = (short) start_pc;
119 }
120
121
122 /**
123 * @return String representation
124 */
125 public final String toString() {
126 return "LineNumber(" + start_pc + ", " + line_number + ")";
127 }
128
129
130 /**
131 * @return deep copy of this object
132 */
133 public LineNumber copy() {
134 try {
135 return (LineNumber) clone();
136 } catch (CloneNotSupportedException e) {
137 }
138 return null;
139 }
140 }
+0
-208
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/LineNumberTable.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents a table of line numbers for debugging
25 * purposes. This attribute is used by the <em>Code</em> attribute. It
26 * contains pairs of PCs and line numbers.
27 *
28 * @version $Id: LineNumberTable.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Code
31 * @see LineNumber
32 */
33 public final class LineNumberTable extends Attribute {
34
35 private int line_number_table_length;
36 private LineNumber[] line_number_table; // Table of line/numbers pairs
37
38
39 /*
40 * Initialize from another object. Note that both objects use the same
41 * references (shallow copy). Use copy() for a physical copy.
42 */
43 public LineNumberTable(LineNumberTable c) {
44 this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool());
45 }
46
47
48 /*
49 * @param name_index Index of name
50 * @param length Content length in bytes
51 * @param line_number_table Table of line/numbers pairs
52 * @param constant_pool Array of constants
53 */
54 public LineNumberTable(int name_index, int length, LineNumber[] line_number_table,
55 ConstantPool constant_pool) {
56 super(Constants.ATTR_LINE_NUMBER_TABLE, name_index, length, constant_pool);
57 setLineNumberTable(line_number_table);
58 }
59
60
61 /**
62 * Construct object from file stream.
63 * @param name_index Index of name
64 * @param length Content length in bytes
65 * @param file Input stream
66 * @param constant_pool Array of constants
67 * @throws IOException
68 */
69 LineNumberTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
70 throws IOException {
71 this(name_index, length, (LineNumber[]) null, constant_pool);
72 line_number_table_length = (file.readUnsignedShort());
73 line_number_table = new LineNumber[line_number_table_length];
74 for (int i = 0; i < line_number_table_length; i++) {
75 line_number_table[i] = new LineNumber(file);
76 }
77 }
78
79
80 /**
81 * Called by objects that are traversing the nodes of the tree implicitely
82 * defined by the contents of a Java class. I.e., the hierarchy of methods,
83 * fields, attributes, etc. spawns a tree of objects.
84 *
85 * @param v Visitor object
86 */
87 public void accept( Visitor v ) {
88 v.visitLineNumberTable(this);
89 }
90
91
92 /**
93 * Dump line number table attribute to file stream in binary format.
94 *
95 * @param file Output file stream
96 * @throws IOException
97 */
98 public final void dump( DataOutputStream file ) throws IOException {
99 super.dump(file);
100 file.writeShort(line_number_table_length);
101 for (int i = 0; i < line_number_table_length; i++) {
102 line_number_table[i].dump(file);
103 }
104 }
105
106
107 /**
108 * @return Array of (pc offset, line number) pairs.
109 */
110 public final LineNumber[] getLineNumberTable() {
111 return line_number_table;
112 }
113
114
115 /**
116 * @param line_number_table the line number entries for this table
117 */
118 public final void setLineNumberTable( LineNumber[] line_number_table ) {
119 this.line_number_table = line_number_table;
120 line_number_table_length = (line_number_table == null) ? 0 : line_number_table.length;
121 }
122
123
124 /**
125 * @return String representation.
126 */
127 public final String toString() {
128 StringBuffer buf = new StringBuffer();
129 StringBuffer line = new StringBuffer();
130 String newLine = System.getProperty("line.separator", "\n");
131 for (int i = 0; i < line_number_table_length; i++) {
132 line.append(line_number_table[i].toString());
133 if (i < line_number_table_length - 1) {
134 line.append(", ");
135 }
136 if (line.length() > 72) {
137 line.append(newLine);
138 buf.append(line.toString());
139 line.setLength(0);
140 }
141 }
142 buf.append(line);
143 return buf.toString();
144 }
145
146
147 /**
148 * Map byte code positions to source code lines.
149 *
150 * @param pos byte code offset
151 * @return corresponding line in source code
152 */
153 public int getSourceLine( int pos ) {
154 int l = 0, r = line_number_table_length - 1;
155 if (r < 0) {
156 return -1;
157 }
158 int min_index = -1, min = -1;
159 /* Do a binary search since the array is ordered.
160 */
161 do {
162 int i = (l + r) / 2;
163 int j = line_number_table[i].getStartPC();
164 if (j == pos) {
165 return line_number_table[i].getLineNumber();
166 } else if (pos < j) {
167 r = i - 1;
168 } else {
169 l = i + 1;
170 }
171 /* If exact match can't be found (which is the most common case)
172 * return the line number that corresponds to the greatest index less
173 * than pos.
174 */
175 if (j < pos && j > min) {
176 min = j;
177 min_index = i;
178 }
179 } while (l <= r);
180 /* It's possible that we did not find any valid entry for the bytecode
181 * offset we were looking for.
182 */
183 if (min_index < 0) {
184 return -1;
185 }
186 return line_number_table[min_index].getLineNumber();
187 }
188
189
190 /**
191 * @return deep copy of this attribute
192 */
193 public Attribute copy( ConstantPool _constant_pool ) {
194 LineNumberTable c = (LineNumberTable) clone();
195 c.line_number_table = new LineNumber[line_number_table_length];
196 for (int i = 0; i < line_number_table_length; i++) {
197 c.line_number_table[i] = line_number_table[i].copy();
198 }
199 c.constant_pool = _constant_pool;
200 return c;
201 }
202
203
204 public final int getTableLength() {
205 return line_number_table_length;
206 }
207 }
+0
-248
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/LocalVariable.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import org.apache.bcel.Constants;
23
24 /**
25 * This class represents a local variable within a method. It contains its
26 * scope, name, signature and index on the method's frame.
27 *
28 * @version $Id: LocalVariable.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see LocalVariableTable
31 */
32 public final class LocalVariable implements Constants, Cloneable, Node, Serializable {
33
34 private int start_pc; // Range in which the variable is valid
35 private int length;
36 private int name_index; // Index in constant pool of variable name
37 private int signature_index; // Index of variable signature
38 private int index; /* Variable is `index'th local variable on
39 * this method's frame.
40 */
41 private ConstantPool constant_pool;
42
43
44 /**
45 * Initialize from another object. Note that both objects use the same
46 * references (shallow copy). Use copy() for a physical copy.
47 */
48 public LocalVariable(LocalVariable c) {
49 this(c.getStartPC(), c.getLength(), c.getNameIndex(), c.getSignatureIndex(), c.getIndex(),
50 c.getConstantPool());
51 }
52
53
54 /**
55 * Construct object from file stream.
56 * @param file Input stream
57 * @throws IOException
58 */
59 LocalVariable(DataInputStream file, ConstantPool constant_pool) throws IOException {
60 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
61 .readUnsignedShort(), file.readUnsignedShort(), constant_pool);
62 }
63
64
65 /**
66 * @param start_pc Range in which the variable
67 * @param length ... is valid
68 * @param name_index Index in constant pool of variable name
69 * @param signature_index Index of variable's signature
70 * @param index Variable is `index'th local variable on the method's frame
71 * @param constant_pool Array of constants
72 */
73 public LocalVariable(int start_pc, int length, int name_index, int signature_index, int index,
74 ConstantPool constant_pool) {
75 this.start_pc = start_pc;
76 this.length = length;
77 this.name_index = name_index;
78 this.signature_index = signature_index;
79 this.index = index;
80 this.constant_pool = constant_pool;
81 }
82
83
84 /**
85 * Called by objects that are traversing the nodes of the tree implicitely
86 * defined by the contents of a Java class. I.e., the hierarchy of methods,
87 * fields, attributes, etc. spawns a tree of objects.
88 *
89 * @param v Visitor object
90 */
91 public void accept( Visitor v ) {
92 v.visitLocalVariable(this);
93 }
94
95
96 /**
97 * Dump local variable to file stream in binary format.
98 *
99 * @param file Output file stream
100 * @throws IOException
101 */
102 public final void dump( DataOutputStream file ) throws IOException {
103 file.writeShort(start_pc);
104 file.writeShort(length);
105 file.writeShort(name_index);
106 file.writeShort(signature_index);
107 file.writeShort(index);
108 }
109
110
111 /**
112 * @return Constant pool used by this object.
113 */
114 public final ConstantPool getConstantPool() {
115 return constant_pool;
116 }
117
118
119 /**
120 * @return Variable is valid within getStartPC() .. getStartPC()+getLength()
121 */
122 public final int getLength() {
123 return length;
124 }
125
126
127 /**
128 * @return Variable name.
129 */
130 public final String getName() {
131 ConstantUtf8 c;
132 c = (ConstantUtf8) constant_pool.getConstant(name_index, CONSTANT_Utf8);
133 return c.getBytes();
134 }
135
136
137 /**
138 * @return Index in constant pool of variable name.
139 */
140 public final int getNameIndex() {
141 return name_index;
142 }
143
144
145 /**
146 * @return Signature.
147 */
148 public final String getSignature() {
149 ConstantUtf8 c;
150 c = (ConstantUtf8) constant_pool.getConstant(signature_index, CONSTANT_Utf8);
151 return c.getBytes();
152 }
153
154
155 /**
156 * @return Index in constant pool of variable signature.
157 */
158 public final int getSignatureIndex() {
159 return signature_index;
160 }
161
162
163 /**
164 * @return index of register where variable is stored
165 */
166 public final int getIndex() {
167 return index;
168 }
169
170
171 /**
172 * @return Start of range where he variable is valid
173 */
174 public final int getStartPC() {
175 return start_pc;
176 }
177
178
179 /**
180 * @param constant_pool Constant pool to be used for this object.
181 */
182 public final void setConstantPool( ConstantPool constant_pool ) {
183 this.constant_pool = constant_pool;
184 }
185
186
187 /**
188 * @param length the length of this local variable
189 */
190 public final void setLength( int length ) {
191 this.length = length;
192 }
193
194
195 /**
196 * @param name_index the index into the constant pool for the name of this variable
197 */
198 public final void setNameIndex( int name_index ) {
199 this.name_index = name_index;
200 }
201
202
203 /**
204 * @param signature_index the index into the constant pool for the signature of this variable
205 */
206 public final void setSignatureIndex( int signature_index ) {
207 this.signature_index = signature_index;
208 }
209
210
211 /**
212 * @param index the index in the local variable table of this variable
213 */
214 public final void setIndex( int index ) {
215 this.index = index;
216 }
217
218
219 /**
220 * @param start_pc Specify range where the local variable is valid.
221 */
222 public final void setStartPC( int start_pc ) {
223 this.start_pc = start_pc;
224 }
225
226
227 /**
228 * @return string representation.
229 */
230 public final String toString() {
231 String name = getName(), signature = Utility.signatureToString(getSignature());
232 return "LocalVariable(start_pc = " + start_pc + ", length = " + length + ", index = "
233 + index + ":" + signature + " " + name + ")";
234 }
235
236
237 /**
238 * @return deep copy of this object
239 */
240 public LocalVariable copy() {
241 try {
242 return (LocalVariable) clone();
243 } catch (CloneNotSupportedException e) {
244 }
245 return null;
246 }
247 }
+0
-80
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/LocalVariableTable.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents colection of local variables in a
25 * method. This attribute is contained in the <em>Code</em> attribute.
26 *
27 * @version $Id: LocalVariableTable.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see Code
30 * @see LocalVariable
31 */
32 public class LocalVariableTable extends AbstractLocalVariableTable {
33
34 /**
35 * Initialize from another object. Note that both objects use the same
36 * references (shallow copy). Use copy() for a physical copy.
37 */
38 public LocalVariableTable(LocalVariableTable c) {
39 this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(), c.getConstantPool());
40 }
41
42
43 /**
44 * @param name_index Index in constant pool to `LocalVariableTable'
45 * @param length Content length in bytes
46 * @param local_variable_table Table of local variables
47 * @param constant_pool Array of constants
48 */
49 public LocalVariableTable(int name_index, int length, LocalVariable[] local_variable_table,
50 ConstantPool constant_pool) {
51 super(name_index,length, local_variable_table, constant_pool);
52 }
53
54
55 /**
56 * Construct object from file stream.
57 * @param name_index Index in constant pool
58 * @param length Content length in bytes
59 * @param file Input stream
60 * @param constant_pool Array of constants
61 * @throws IOException
62 */
63 LocalVariableTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
64 throws IOException {
65 super(name_index,length, file, constant_pool);
66 }
67
68
69 /**
70 * Called by objects that are traversing the nodes of the tree implicitely
71 * defined by the contents of a Java class. I.e., the hierarchy of methods,
72 * fields, attributes, etc. spawns a tree of objects.
73 *
74 * @param v Visitor object
75 */
76 public void accept( Visitor v ) {
77 v.visitLocalVariableTable(this);
78 }
79 }
+0
-22
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/LocalVariableTypeTable.java less more
0 package org.apache.bcel.classfile;
1
2 import java.io.DataInputStream;
3 import java.io.IOException;
4
5 public class LocalVariableTypeTable extends AbstractLocalVariableTable {
6
7 public LocalVariableTypeTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
8 super(name_index, length, file, constant_pool);
9 }
10
11 /**
12 * Called by objects that are traversing the nodes of the tree implicitely
13 * defined by the contents of a Java class. I.e., the hierarchy of methods,
14 * fields, attributes, etc. spawns a tree of objects.
15 *
16 * @param v Visitor object
17 */
18 public void accept( Visitor v ) {
19 v.visitLocalVariableTypeTable(this);
20 }
21 }
+0
-254
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Method.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.generic.Type;
22 import org.apache.bcel.util.BCELComparator;
23
24 /**
25 * This class represents the method info structure, i.e., the representation
26 * for a method in the class. See JVM specification for details.
27 * A method has access flags, a name, a signature and a number of attributes.
28 *
29 * @version $Id: Method.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 */
32 public final class Method extends FieldOrMethod {
33
34 private static BCELComparator _cmp = new BCELComparator() {
35
36 public boolean equals( Object o1, Object o2 ) {
37 Method THIS = (Method) o1;
38 Method THAT = (Method) o2;
39 return THIS.getName().equals(THAT.getName())
40 && THIS.getSignature().equals(THAT.getSignature());
41 }
42
43
44 public int hashCode( Object o ) {
45 Method THIS = (Method) o;
46 return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
47 }
48 };
49
50
51 /**
52 * Empty constructor, all attributes have to be defined via `setXXX'
53 * methods. Use at your own risk.
54 */
55 public Method() {
56 }
57
58
59 /**
60 * Initialize from another object. Note that both objects use the same
61 * references (shallow copy). Use clone() for a physical copy.
62 */
63 public Method(Method c) {
64 super(c);
65 }
66
67
68 /**
69 * Construct object from file stream.
70 * @param file Input stream
71 * @throws IOException
72 * @throws ClassFormatException
73 */
74 Method(DataInputStream file, ConstantPool constant_pool) throws IOException,
75 ClassFormatException {
76 super(file, constant_pool);
77 }
78
79
80 /**
81 * @param access_flags Access rights of method
82 * @param name_index Points to field name in constant pool
83 * @param signature_index Points to encoded signature
84 * @param attributes Collection of attributes
85 * @param constant_pool Array of constants
86 */
87 public Method(int access_flags, int name_index, int signature_index, Attribute[] attributes,
88 ConstantPool constant_pool) {
89 super(access_flags, name_index, signature_index, attributes, constant_pool);
90 }
91
92
93 /**
94 * Called by objects that are traversing the nodes of the tree implicitely
95 * defined by the contents of a Java class. I.e., the hierarchy of methods,
96 * fields, attributes, etc. spawns a tree of objects.
97 *
98 * @param v Visitor object
99 */
100 public void accept( Visitor v ) {
101 v.visitMethod(this);
102 }
103
104
105 /**
106 * @return Code attribute of method, if any
107 */
108 public final Code getCode() {
109 for (int i = 0; i < attributes_count; i++) {
110 if (attributes[i] instanceof Code) {
111 return (Code) attributes[i];
112 }
113 }
114 return null;
115 }
116
117
118 /**
119 * @return ExceptionTable attribute of method, if any, i.e., list all
120 * exceptions the method may throw not exception handlers!
121 */
122 public final ExceptionTable getExceptionTable() {
123 for (int i = 0; i < attributes_count; i++) {
124 if (attributes[i] instanceof ExceptionTable) {
125 return (ExceptionTable) attributes[i];
126 }
127 }
128 return null;
129 }
130
131
132 /** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded
133 * to the Code atribute.
134 */
135 public final LocalVariableTable getLocalVariableTable() {
136 Code code = getCode();
137 if (code == null) {
138 return null;
139 }
140 return code.getLocalVariableTable();
141 }
142
143
144 /** @return LineNumberTable of code attribute if any, i.e. the call is forwarded
145 * to the Code atribute.
146 */
147 public final LineNumberTable getLineNumberTable() {
148 Code code = getCode();
149 if (code == null) {
150 return null;
151 }
152 return code.getLineNumberTable();
153 }
154
155
156 /**
157 * Return string representation close to declaration format,
158 * `public static void main(String[] args) throws IOException', e.g.
159 *
160 * @return String representation of the method.
161 */
162 public final String toString() {
163 ConstantUtf8 c;
164 String name, signature, access; // Short cuts to constant pool
165 StringBuffer buf;
166 access = Utility.accessToString(access_flags);
167 // Get name and signature from constant pool
168 c = (ConstantUtf8) constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8);
169 signature = c.getBytes();
170 c = (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
171 name = c.getBytes();
172 signature = Utility.methodSignatureToString(signature, name, access, true,
173 getLocalVariableTable());
174 buf = new StringBuffer(signature);
175 for (int i = 0; i < attributes_count; i++) {
176 Attribute a = attributes[i];
177 if (!((a instanceof Code) || (a instanceof ExceptionTable))) {
178 buf.append(" [").append(a.toString()).append("]");
179 }
180 }
181 ExceptionTable e = getExceptionTable();
182 if (e != null) {
183 String str = e.toString();
184 if (!str.equals("")) {
185 buf.append("\n\t\tthrows ").append(str);
186 }
187 }
188 return buf.toString();
189 }
190
191
192 /**
193 * @return deep copy of this method
194 */
195 public final Method copy( ConstantPool _constant_pool ) {
196 return (Method) copy_(_constant_pool);
197 }
198
199
200 /**
201 * @return return type of method
202 */
203 public Type getReturnType() {
204 return Type.getReturnType(getSignature());
205 }
206
207
208 /**
209 * @return array of method argument types
210 */
211 public Type[] getArgumentTypes() {
212 return Type.getArgumentTypes(getSignature());
213 }
214
215
216 /**
217 * @return Comparison strategy object
218 */
219 public static BCELComparator getComparator() {
220 return _cmp;
221 }
222
223
224 /**
225 * @param comparator Comparison strategy object
226 */
227 public static void setComparator( BCELComparator comparator ) {
228 _cmp = comparator;
229 }
230
231
232 /**
233 * Return value as defined by given BCELComparator strategy.
234 * By default two method objects are said to be equal when
235 * their names and signatures are equal.
236 *
237 * @see java.lang.Object#equals(java.lang.Object)
238 */
239 public boolean equals( Object obj ) {
240 return _cmp.equals(this, obj);
241 }
242
243
244 /**
245 * Return value as defined by given BCELComparator strategy.
246 * By default return the hashcode of the method's name XOR signature.
247 *
248 * @see java.lang.Object#hashCode()
249 */
250 public int hashCode() {
251 return _cmp.hashCode(this);
252 }
253 }
+0
-28
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Node.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * Denote class to have an accept method();
20 *
21 * @version $Id: Node.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public interface Node {
25
26 public void accept( Visitor obj );
27 }
+0
-167
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/PMGClass.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and represents a reference
25 * to a PMG attribute.
26 *
27 * @version $Id: PMGClass.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see Attribute
30 */
31 public final class PMGClass extends Attribute {
32
33 private int pmg_class_index, pmg_index;
34
35
36 /**
37 * Initialize from another object. Note that both objects use the same
38 * references (shallow copy). Use clone() for a physical copy.
39 */
40 public PMGClass(PMGClass c) {
41 this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), c
42 .getConstantPool());
43 }
44
45
46 /**
47 * Construct object from file stream.
48 * @param name_index Index in constant pool to CONSTANT_Utf8
49 * @param length Content length in bytes
50 * @param file Input stream
51 * @param constant_pool Array of constants
52 * @throws IOException
53 */
54 PMGClass(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
55 throws IOException {
56 this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
57 }
58
59
60 /**
61 * @param name_index Index in constant pool to CONSTANT_Utf8
62 * @param length Content length in bytes
63 * @param pmg_index index in constant pool for source file name
64 * @param pmg_class_index Index in constant pool to CONSTANT_Utf8
65 * @param constant_pool Array of constants
66 */
67 public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index,
68 ConstantPool constant_pool) {
69 super(Constants.ATTR_PMG, name_index, length, constant_pool);
70 this.pmg_index = pmg_index;
71 this.pmg_class_index = pmg_class_index;
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 public void accept( Visitor v ) {
83 System.err.println("Visiting non-standard PMGClass object");
84 }
85
86
87 /**
88 * Dump source file attribute to file stream in binary format.
89 *
90 * @param file Output file stream
91 * @throws IOException
92 */
93 public final void dump( DataOutputStream file ) throws IOException {
94 super.dump(file);
95 file.writeShort(pmg_index);
96 file.writeShort(pmg_class_index);
97 }
98
99
100 /**
101 * @return Index in constant pool of source file name.
102 */
103 public final int getPMGClassIndex() {
104 return pmg_class_index;
105 }
106
107
108 /**
109 * @param pmg_class_index
110 */
111 public final void setPMGClassIndex( int pmg_class_index ) {
112 this.pmg_class_index = pmg_class_index;
113 }
114
115
116 /**
117 * @return Index in constant pool of source file name.
118 */
119 public final int getPMGIndex() {
120 return pmg_index;
121 }
122
123
124 /**
125 * @param pmg_index
126 */
127 public final void setPMGIndex( int pmg_index ) {
128 this.pmg_index = pmg_index;
129 }
130
131
132 /**
133 * @return PMG name.
134 */
135 public final String getPMGName() {
136 ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(pmg_index,
137 Constants.CONSTANT_Utf8);
138 return c.getBytes();
139 }
140
141
142 /**
143 * @return PMG class name.
144 */
145 public final String getPMGClassName() {
146 ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(pmg_class_index,
147 Constants.CONSTANT_Utf8);
148 return c.getBytes();
149 }
150
151
152 /**
153 * @return String representation
154 */
155 public final String toString() {
156 return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")";
157 }
158
159
160 /**
161 * @return deep copy of this attribute
162 */
163 public Attribute copy( ConstantPool _constant_pool ) {
164 return (PMGClass) clone();
165 }
166 }
+0
-273
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Signature.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.DataInputStream;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22 import org.apache.bcel.Constants;
23
24 /**
25 * This class is derived from <em>Attribute</em> and represents a reference
26 * to a GJ attribute.
27 *
28 * @version $Id: Signature.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see Attribute
31 */
32 public final class Signature extends Attribute {
33
34 private int signature_index;
35
36
37 /**
38 * Initialize from another object. Note that both objects use the same
39 * references (shallow copy). Use clone() for a physical copy.
40 */
41 public Signature(Signature c) {
42 this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool());
43 }
44
45
46 /**
47 * Construct object from file stream.
48 * @param name_index Index in constant pool to CONSTANT_Utf8
49 * @param length Content length in bytes
50 * @param file Input stream
51 * @param constant_pool Array of constants
52 * @throws IOException
53 */
54 Signature(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
55 throws IOException {
56 this(name_index, length, file.readUnsignedShort(), constant_pool);
57 }
58
59
60 /**
61 * @param name_index Index in constant pool to CONSTANT_Utf8
62 * @param length Content length in bytes
63 * @param signature_index Index in constant pool to CONSTANT_Utf8
64 * @param constant_pool Array of constants
65 */
66 public Signature(int name_index, int length, int signature_index, ConstantPool constant_pool) {
67 super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool);
68 this.signature_index = signature_index;
69 }
70
71
72 /**
73 * Called by objects that are traversing the nodes of the tree implicitely
74 * defined by the contents of a Java class. I.e., the hierarchy of methods,
75 * fields, attributes, etc. spawns a tree of objects.
76 *
77 * @param v Visitor object
78 */
79 public void accept( Visitor v ) {
80 //System.err.println("Visiting non-standard Signature object");
81 v.visitSignature(this);
82 }
83
84
85 /**
86 * Dump source file attribute to file stream in binary format.
87 *
88 * @param file Output file stream
89 * @throws IOException
90 */
91 public final void dump( DataOutputStream file ) throws IOException {
92 super.dump(file);
93 file.writeShort(signature_index);
94 }
95
96
97 /**
98 * @return Index in constant pool of source file name.
99 */
100 public final int getSignatureIndex() {
101 return signature_index;
102 }
103
104
105 /**
106 * @param signature_index the index info the constant pool of this signature
107 */
108 public final void setSignatureIndex( int signature_index ) {
109 this.signature_index = signature_index;
110 }
111
112
113 /**
114 * @return GJ signature.
115 */
116 public final String getSignature() {
117 ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(signature_index,
118 Constants.CONSTANT_Utf8);
119 return c.getBytes();
120 }
121
122 /**
123 * Extends ByteArrayInputStream to make 'unreading' chars possible.
124 */
125 private static final class MyByteArrayInputStream extends ByteArrayInputStream {
126
127 MyByteArrayInputStream(String data) {
128 super(data.getBytes());
129 }
130
131
132 final int mark() {
133 return pos;
134 }
135
136
137 final String getData() {
138 return new String(buf);
139 }
140
141
142 final void reset( int p ) {
143 pos = p;
144 }
145
146
147 final void unread() {
148 if (pos > 0) {
149 pos--;
150 }
151 }
152 }
153
154
155 private static boolean identStart( int ch ) {
156 return ch == 'T' || ch == 'L';
157 }
158
159
160 private static final void matchIdent( MyByteArrayInputStream in, StringBuffer buf ) {
161 int ch;
162 if ((ch = in.read()) == -1) {
163 throw new RuntimeException("Illegal signature: " + in.getData()
164 + " no ident, reaching EOF");
165 }
166 //System.out.println("return from ident:" + (char)ch);
167 if (!identStart(ch)) {
168 StringBuffer buf2 = new StringBuffer();
169 int count = 1;
170 while (Character.isJavaIdentifierPart((char) ch)) {
171 buf2.append((char) ch);
172 count++;
173 ch = in.read();
174 }
175 if (ch == ':') { // Ok, formal parameter
176 in.skip("Ljava/lang/Object".length());
177 buf.append(buf2);
178 ch = in.read();
179 in.unread();
180 //System.out.println("so far:" + buf2 + ":next:" +(char)ch);
181 } else {
182 for (int i = 0; i < count; i++) {
183 in.unread();
184 }
185 }
186 return;
187 }
188 StringBuffer buf2 = new StringBuffer();
189 ch = in.read();
190 do {
191 buf2.append((char) ch);
192 ch = in.read();
193 //System.out.println("within ident:"+ (char)ch);
194 } while ((ch != -1) && (Character.isJavaIdentifierPart((char) ch) || (ch == '/')));
195 buf.append(buf2.toString().replace('/', '.'));
196 //System.out.println("regular return ident:"+ (char)ch + ":" + buf2);
197 if (ch != -1) {
198 in.unread();
199 }
200 }
201
202
203 private static final void matchGJIdent( MyByteArrayInputStream in, StringBuffer buf ) {
204 int ch;
205 matchIdent(in, buf);
206 ch = in.read();
207 if ((ch == '<') || ch == '(') { // Parameterized or method
208 //System.out.println("Enter <");
209 buf.append((char) ch);
210 matchGJIdent(in, buf);
211 while (((ch = in.read()) != '>') && (ch != ')')) { // List of parameters
212 if (ch == -1) {
213 throw new RuntimeException("Illegal signature: " + in.getData()
214 + " reaching EOF");
215 }
216 //System.out.println("Still no >");
217 buf.append(", ");
218 in.unread();
219 matchGJIdent(in, buf); // Recursive call
220 }
221 //System.out.println("Exit >");
222 buf.append((char) ch);
223 } else {
224 in.unread();
225 }
226 ch = in.read();
227 if (identStart(ch)) {
228 in.unread();
229 matchGJIdent(in, buf);
230 } else if (ch == ')') {
231 in.unread();
232 return;
233 } else if (ch != ';') {
234 throw new RuntimeException("Illegal signature: " + in.getData() + " read " + (char) ch);
235 }
236 }
237
238
239 public static String translate( String s ) {
240 //System.out.println("Sig:" + s);
241 StringBuffer buf = new StringBuffer();
242 matchGJIdent(new MyByteArrayInputStream(s), buf);
243 return buf.toString();
244 }
245
246
247 public static final boolean isFormalParameterList( String s ) {
248 return s.startsWith("<") && (s.indexOf(':') > 0);
249 }
250
251
252 public static final boolean isActualParameterList( String s ) {
253 return s.startsWith("L") && s.endsWith(">;");
254 }
255
256
257 /**
258 * @return String representation
259 */
260 public final String toString() {
261 String s = getSignature();
262 return "Signature(" + s + ")";
263 }
264
265
266 /**
267 * @return deep copy of this attribute
268 */
269 public Attribute copy( ConstantPool _constant_pool ) {
270 return (Signature) clone();
271 }
272 }
+0
-145
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/SourceFile.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and represents a reference
25 * to the source file of this class. At most one SourceFile attribute
26 * should appear per classfile. The intention of this class is that it is
27 * instantiated from the <em>Attribute.readAttribute()</em> method.
28 *
29 * @version $Id: SourceFile.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see Attribute
32 */
33 public final class SourceFile extends Attribute {
34
35 private int sourcefile_index;
36
37
38 /**
39 * Initialize from another object. Note that both objects use the same
40 * references (shallow copy). Use clone() for a physical copy.
41 */
42 public SourceFile(SourceFile c) {
43 this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), c.getConstantPool());
44 }
45
46
47 /**
48 * Construct object from file stream.
49 * @param name_index Index in constant pool to CONSTANT_Utf8
50 * @param length Content length in bytes
51 * @param file Input stream
52 * @param constant_pool Array of constants
53 * @throws IOException
54 */
55 SourceFile(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
56 throws IOException {
57 this(name_index, length, file.readUnsignedShort(), constant_pool);
58 }
59
60
61 /**
62 * @param name_index Index in constant pool to CONSTANT_Utf8, which
63 * should represent the string "SourceFile".
64 * @param length Content length in bytes, the value should be 2.
65 * @param constant_pool The constant pool that this attribute is
66 * associated with.
67 * @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This
68 * string will be interpreted as the name of the file from which this
69 * class was compiled. It will not be interpreted as indicating the name
70 * of the directory contqining the file or an absolute path; this
71 * information has to be supplied the consumer of this attribute - in
72 * many cases, the JVM.
73 */
74 public SourceFile(int name_index, int length, int sourcefile_index, ConstantPool constant_pool) {
75 super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool);
76 this.sourcefile_index = sourcefile_index;
77 }
78
79
80 /**
81 * Called by objects that are traversing the nodes of the tree implicitely
82 * defined by the contents of a Java class. I.e., the hierarchy of methods,
83 * fields, attributes, etc. spawns a tree of objects.
84 *
85 * @param v Visitor object
86 */
87 public void accept( Visitor v ) {
88 v.visitSourceFile(this);
89 }
90
91
92 /**
93 * Dump source file attribute to file stream in binary format.
94 *
95 * @param file Output file stream
96 * @throws IOException
97 */
98 public final void dump( DataOutputStream file ) throws IOException {
99 super.dump(file);
100 file.writeShort(sourcefile_index);
101 }
102
103
104 /**
105 * @return Index in constant pool of source file name.
106 */
107 public final int getSourceFileIndex() {
108 return sourcefile_index;
109 }
110
111
112 /**
113 * @param sourcefile_index
114 */
115 public final void setSourceFileIndex( int sourcefile_index ) {
116 this.sourcefile_index = sourcefile_index;
117 }
118
119
120 /**
121 * @return Source file name.
122 */
123 public final String getSourceFileName() {
124 ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(sourcefile_index,
125 Constants.CONSTANT_Utf8);
126 return c.getBytes();
127 }
128
129
130 /**
131 * @return String representation
132 */
133 public final String toString() {
134 return "SourceFile(" + getSourceFileName() + ")";
135 }
136
137
138 /**
139 * @return deep copy of this attribute
140 */
141 public Attribute copy( ConstantPool _constant_pool ) {
142 return (SourceFile) clone();
143 }
144 }
+0
-153
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/StackMap.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents a stack map attribute used for
25 * preverification of Java classes for the <a
26 * href="http://java.sun.com/j2me/"> Java 2 Micro Edition</a>
27 * (J2ME). This attribute is used by the <a
28 * href="http://java.sun.com/products/cldc/">KVM</a> and contained
29 * within the Code attribute of a method. See CLDC specification
30 * §5.3.1.2
31 *
32 * @version $Id: StackMap.java 386056 2006-03-15 11:31:56Z tcurdt $
33 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34 * @see Code
35 * @see StackMapEntry
36 * @see StackMapType
37 */
38 public final class StackMap extends Attribute implements Node {
39
40 private int map_length;
41 private StackMapEntry[] map; // Table of stack map entries
42
43
44 /*
45 * @param name_index Index of name
46 * @param length Content length in bytes
47 * @param map Table of stack map entries
48 * @param constant_pool Array of constants
49 */
50 public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) {
51 super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
52 setStackMap(map);
53 }
54
55
56 /**
57 * Construct object from file stream.
58 * @param name_index Index of name
59 * @param length Content length in bytes
60 * @param file Input stream
61 * @param constant_pool Array of constants
62 * @throws IOException
63 */
64 StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
65 throws IOException {
66 this(name_index, length, (StackMapEntry[]) null, constant_pool);
67 map_length = file.readUnsignedShort();
68 map = new StackMapEntry[map_length];
69 for (int i = 0; i < map_length; i++) {
70 map[i] = new StackMapEntry(file, constant_pool);
71 }
72 }
73
74
75 /**
76 * Dump line number table attribute to file stream in binary format.
77 *
78 * @param file Output file stream
79 * @throws IOException
80 */
81 public final void dump( DataOutputStream file ) throws IOException {
82 super.dump(file);
83 file.writeShort(map_length);
84 for (int i = 0; i < map_length; i++) {
85 map[i].dump(file);
86 }
87 }
88
89
90 /**
91 * @return Array of stack map entries
92 */
93 public final StackMapEntry[] getStackMap() {
94 return map;
95 }
96
97
98 /**
99 * @param map Array of stack map entries
100 */
101 public final void setStackMap( StackMapEntry[] map ) {
102 this.map = map;
103 map_length = (map == null) ? 0 : map.length;
104 }
105
106
107 /**
108 * @return String representation.
109 */
110 public final String toString() {
111 StringBuffer buf = new StringBuffer("StackMap(");
112 for (int i = 0; i < map_length; i++) {
113 buf.append(map[i].toString());
114 if (i < map_length - 1) {
115 buf.append(", ");
116 }
117 }
118 buf.append(')');
119 return buf.toString();
120 }
121
122
123 /**
124 * @return deep copy of this attribute
125 */
126 public Attribute copy( ConstantPool _constant_pool ) {
127 StackMap c = (StackMap) clone();
128 c.map = new StackMapEntry[map_length];
129 for (int i = 0; i < map_length; i++) {
130 c.map[i] = map[i].copy();
131 }
132 c.constant_pool = _constant_pool;
133 return c;
134 }
135
136
137 /**
138 * Called by objects that are traversing the nodes of the tree implicitely
139 * defined by the contents of a Java class. I.e., the hierarchy of methods,
140 * fields, attributes, etc. spawns a tree of objects.
141 *
142 * @param v Visitor object
143 */
144 public void accept( Visitor v ) {
145 v.visitStackMap(this);
146 }
147
148
149 public final int getMapLength() {
150 return map_length;
151 }
152 }
+0
-212
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/StackMapEntry.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 /**
23 * This class represents a stack map entry recording the types of
24 * local variables and the the of stack items at a given byte code offset.
25 * See CLDC specification §5.3.1.2
26 *
27 * @version $Id: StackMapEntry.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see StackMap
30 * @see StackMapType
31 */
32 public final class StackMapEntry implements Cloneable {
33
34 private int byte_code_offset;
35 private int number_of_locals;
36 private StackMapType[] types_of_locals;
37 private int number_of_stack_items;
38 private StackMapType[] types_of_stack_items;
39 private ConstantPool constant_pool;
40
41
42 /**
43 * Construct object from file stream.
44 * @param file Input stream
45 * @throws IOException
46 */
47 StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
48 this(file.readShort(), file.readShort(), null, -1, null, constant_pool);
49 types_of_locals = new StackMapType[number_of_locals];
50 for (int i = 0; i < number_of_locals; i++) {
51 types_of_locals[i] = new StackMapType(file, constant_pool);
52 }
53 number_of_stack_items = file.readShort();
54 types_of_stack_items = new StackMapType[number_of_stack_items];
55 for (int i = 0; i < number_of_stack_items; i++) {
56 types_of_stack_items[i] = new StackMapType(file, constant_pool);
57 }
58 }
59
60
61 public StackMapEntry(int byte_code_offset, int number_of_locals,
62 StackMapType[] types_of_locals, int number_of_stack_items,
63 StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
64 this.byte_code_offset = byte_code_offset;
65 this.number_of_locals = number_of_locals;
66 this.types_of_locals = types_of_locals;
67 this.number_of_stack_items = number_of_stack_items;
68 this.types_of_stack_items = types_of_stack_items;
69 this.constant_pool = constant_pool;
70 }
71
72
73 /**
74 * Dump stack map entry
75 *
76 * @param file Output file stream
77 * @throws IOException
78 */
79 public final void dump( DataOutputStream file ) throws IOException {
80 file.writeShort(byte_code_offset);
81 file.writeShort(number_of_locals);
82 for (int i = 0; i < number_of_locals; i++) {
83 types_of_locals[i].dump(file);
84 }
85 file.writeShort(number_of_stack_items);
86 for (int i = 0; i < number_of_stack_items; i++) {
87 types_of_stack_items[i].dump(file);
88 }
89 }
90
91
92 /**
93 * @return String representation.
94 */
95 public final String toString() {
96 StringBuffer buf = new StringBuffer(64);
97 buf.append("(offset=").append(byte_code_offset);
98 if (number_of_locals > 0) {
99 buf.append(", locals={");
100 for (int i = 0; i < number_of_locals; i++) {
101 buf.append(types_of_locals[i]);
102 if (i < number_of_locals - 1) {
103 buf.append(", ");
104 }
105 }
106 buf.append("}");
107 }
108 if (number_of_stack_items > 0) {
109 buf.append(", stack items={");
110 for (int i = 0; i < number_of_stack_items; i++) {
111 buf.append(types_of_stack_items[i]);
112 if (i < number_of_stack_items - 1) {
113 buf.append(", ");
114 }
115 }
116 buf.append("}");
117 }
118 buf.append(")");
119 return buf.toString();
120 }
121
122
123 public void setByteCodeOffset( int b ) {
124 byte_code_offset = b;
125 }
126
127
128 public int getByteCodeOffset() {
129 return byte_code_offset;
130 }
131
132
133 public void setNumberOfLocals( int n ) {
134 number_of_locals = n;
135 }
136
137
138 public int getNumberOfLocals() {
139 return number_of_locals;
140 }
141
142
143 public void setTypesOfLocals( StackMapType[] t ) {
144 types_of_locals = t;
145 }
146
147
148 public StackMapType[] getTypesOfLocals() {
149 return types_of_locals;
150 }
151
152
153 public void setNumberOfStackItems( int n ) {
154 number_of_stack_items = n;
155 }
156
157
158 public int getNumberOfStackItems() {
159 return number_of_stack_items;
160 }
161
162
163 public void setTypesOfStackItems( StackMapType[] t ) {
164 types_of_stack_items = t;
165 }
166
167
168 public StackMapType[] getTypesOfStackItems() {
169 return types_of_stack_items;
170 }
171
172
173 /**
174 * @return deep copy of this object
175 */
176 public StackMapEntry copy() {
177 try {
178 return (StackMapEntry) clone();
179 } catch (CloneNotSupportedException e) {
180 }
181 return null;
182 }
183
184
185 /**
186 * Called by objects that are traversing the nodes of the tree implicitely
187 * defined by the contents of a Java class. I.e., the hierarchy of methods,
188 * fields, attributes, etc. spawns a tree of objects.
189 *
190 * @param v Visitor object
191 */
192 public void accept( Visitor v ) {
193 v.visitStackMapEntry(this);
194 }
195
196
197 /**
198 * @return Constant pool used by this object.
199 */
200 public final ConstantPool getConstantPool() {
201 return constant_pool;
202 }
203
204
205 /**
206 * @param constant_pool Constant pool to be used for this object.
207 */
208 public final void setConstantPool( ConstantPool constant_pool ) {
209 this.constant_pool = constant_pool;
210 }
211 }
+0
-161
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/StackMapType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class represents the type of a local variable or item on stack
25 * used in the StackMap entries.
26 *
27 * @version $Id: StackMapType.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see StackMapEntry
30 * @see StackMap
31 * @see Constants
32 */
33 public final class StackMapType implements Cloneable {
34
35 private byte type;
36 private int index = -1; // Index to CONSTANT_Class or offset
37 private ConstantPool constant_pool;
38
39
40 /**
41 * Construct object from file stream.
42 * @param file Input stream
43 * @throws IOException
44 */
45 StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException {
46 this(file.readByte(), -1, constant_pool);
47 if (hasIndex()) {
48 setIndex(file.readShort());
49 }
50 setConstantPool(constant_pool);
51 }
52
53
54 /**
55 * @param type type tag as defined in the Constants interface
56 * @param index index to constant pool, or byte code offset
57 */
58 public StackMapType(byte type, int index, ConstantPool constant_pool) {
59 setType(type);
60 setIndex(index);
61 setConstantPool(constant_pool);
62 }
63
64
65 public void setType( byte t ) {
66 if ((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) {
67 throw new RuntimeException("Illegal type for StackMapType: " + t);
68 }
69 type = t;
70 }
71
72
73 public byte getType() {
74 return type;
75 }
76
77
78 public void setIndex( int t ) {
79 index = t;
80 }
81
82
83 /** @return index to constant pool if type == ITEM_Object, or offset
84 * in byte code, if type == ITEM_NewObject, and -1 otherwise
85 */
86 public int getIndex() {
87 return index;
88 }
89
90
91 /**
92 * Dump type entries to file.
93 *
94 * @param file Output file stream
95 * @throws IOException
96 */
97 public final void dump( DataOutputStream file ) throws IOException {
98 file.writeByte(type);
99 if (hasIndex()) {
100 file.writeShort(getIndex());
101 }
102 }
103
104
105 /** @return true, if type is either ITEM_Object or ITEM_NewObject
106 */
107 public final boolean hasIndex() {
108 return ((type == Constants.ITEM_Object) || (type == Constants.ITEM_NewObject));
109 }
110
111
112 private String printIndex() {
113 if (type == Constants.ITEM_Object) {
114 if (index < 0) {
115 return ", class=<unknown>";
116 }
117 return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class);
118 } else if (type == Constants.ITEM_NewObject) {
119 return ", offset=" + index;
120 } else {
121 return "";
122 }
123 }
124
125
126 /**
127 * @return String representation
128 */
129 public final String toString() {
130 return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")";
131 }
132
133
134 /**
135 * @return deep copy of this object
136 */
137 public StackMapType copy() {
138 try {
139 return (StackMapType) clone();
140 } catch (CloneNotSupportedException e) {
141 }
142 return null;
143 }
144
145
146 /**
147 * @return Constant pool used by this object.
148 */
149 public final ConstantPool getConstantPool() {
150 return constant_pool;
151 }
152
153
154 /**
155 * @param constant_pool Constant pool to be used for this object.
156 */
157 public final void setConstantPool( ConstantPool constant_pool ) {
158 this.constant_pool = constant_pool;
159 }
160 }
+0
-150
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Synthetic.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import org.apache.bcel.Constants;
22
23 /**
24 * This class is derived from <em>Attribute</em> and declares this class as
25 * `synthetic', i.e., it needs special handling. The JVM specification
26 * states "A class member that does not appear in the source code must be
27 * marked using a Synthetic attribute." It may appear in the ClassFile
28 * attribute table, a field_info table or a method_info table. This class
29 * is intended to be instantiated from the
30 * <em>Attribute.readAttribute()</em> method.
31 *
32 * @version $Id: Synthetic.java 386056 2006-03-15 11:31:56Z tcurdt $
33 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34 * @see Attribute
35 */
36 public final class Synthetic extends Attribute {
37
38 private byte[] bytes;
39
40
41 /**
42 * Initialize from another object. Note that both objects use the same
43 * references (shallow copy). Use copy() for a physical copy.
44 */
45 public Synthetic(Synthetic c) {
46 this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
47 }
48
49
50 /**
51 * @param name_index Index in constant pool to CONSTANT_Utf8, which
52 * should represent the string "Synthetic".
53 * @param length Content length in bytes - should be zero.
54 * @param bytes Attribute contents
55 * @param constant_pool The constant pool this attribute is associated
56 * with.
57 */
58 public Synthetic(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
59 super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool);
60 this.bytes = bytes;
61 }
62
63
64 /**
65 * Construct object from file stream.
66 * @param name_index Index in constant pool to CONSTANT_Utf8
67 * @param length Content length in bytes
68 * @param file Input stream
69 * @param constant_pool Array of constants
70 * @throws IOException
71 */
72 Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
73 throws IOException {
74 this(name_index, length, (byte[]) null, constant_pool);
75 if (length > 0) {
76 bytes = new byte[length];
77 file.readFully(bytes);
78 System.err.println("Synthetic attribute with length > 0");
79 }
80 }
81
82
83 /**
84 * Called by objects that are traversing the nodes of the tree implicitely
85 * defined by the contents of a Java class. I.e., the hierarchy of methods,
86 * fields, attributes, etc. spawns a tree of objects.
87 *
88 * @param v Visitor object
89 */
90 public void accept( Visitor v ) {
91 v.visitSynthetic(this);
92 }
93
94
95 /**
96 * Dump source file attribute to file stream in binary format.
97 *
98 * @param file Output file stream
99 * @throws IOException
100 */
101 public final void dump( DataOutputStream file ) throws IOException {
102 super.dump(file);
103 if (length > 0) {
104 file.write(bytes, 0, length);
105 }
106 }
107
108
109 /**
110 * @return data bytes.
111 */
112 public final byte[] getBytes() {
113 return bytes;
114 }
115
116
117 /**
118 * @param bytes
119 */
120 public final void setBytes( byte[] bytes ) {
121 this.bytes = bytes;
122 }
123
124
125 /**
126 * @return String representation.
127 */
128 public final String toString() {
129 StringBuffer buf = new StringBuffer("Synthetic");
130 if (length > 0) {
131 buf.append(" ").append(Utility.toHexString(bytes));
132 }
133 return buf.toString();
134 }
135
136
137 /**
138 * @return deep copy of this attribute
139 */
140 public Attribute copy( ConstantPool _constant_pool ) {
141 Synthetic c = (Synthetic) clone();
142 if (bytes != null) {
143 c.bytes = new byte[bytes.length];
144 System.arraycopy(bytes, 0, c.bytes, 0, bytes.length);
145 }
146 c.constant_pool = _constant_pool;
147 return c;
148 }
149 }
+0
-188
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Unknown.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24 import org.apache.bcel.Constants;
25
26 /**
27 * This class represents a reference to an unknown (i.e.,
28 * application-specific) attribute of a class. It is instantiated from the
29 * <em>Attribute.readAttribute()</em> method. Applications that need to
30 * read in application-specific attributes should create an <a
31 * href="./AttributeReader.html">AttributeReader</a> implementation and
32 * attach it via <a
33 * href="./Attribute.html#addAttributeReader(java.lang.String,
34 * org.apache.bcel.classfile.AttributeReader)">Attribute.addAttributeReader</a>.
35
36 *
37 * @version $Id: Unknown.java 386056 2006-03-15 11:31:56Z tcurdt $
38 * @see org.apache.bcel.classfile.Attribute
39 * @see org.apache.bcel.classfile.AttributeReader
40 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
41 */
42 public final class Unknown extends Attribute {
43
44 private byte[] bytes;
45 private String name;
46 private static Map unknown_attributes = new HashMap();
47
48
49 /** @return array of unknown attributes, but just one for each kind.
50 */
51 static Unknown[] getUnknownAttributes() {
52 Unknown[] unknowns = new Unknown[unknown_attributes.size()];
53 Iterator entries = unknown_attributes.values().iterator();
54 for (int i = 0; entries.hasNext(); i++) {
55 unknowns[i] = (Unknown) entries.next();
56 }
57 unknown_attributes.clear();
58 return unknowns;
59 }
60
61
62 /**
63 * Initialize from another object. Note that both objects use the same
64 * references (shallow copy). Use clone() for a physical copy.
65 */
66 public Unknown(Unknown c) {
67 this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
68 }
69
70
71 /**
72 * Create a non-standard attribute.
73 *
74 * @param name_index Index in constant pool
75 * @param length Content length in bytes
76 * @param bytes Attribute contents
77 * @param constant_pool Array of constants
78 */
79 public Unknown(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
80 super(Constants.ATTR_UNKNOWN, name_index, length, constant_pool);
81 this.bytes = bytes;
82 name = ((ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8))
83 .getBytes();
84 unknown_attributes.put(name, this);
85 }
86
87
88 /**
89 * Construct object from file stream.
90 * @param name_index Index in constant pool
91 * @param length Content length in bytes
92 * @param file Input stream
93 * @param constant_pool Array of constants
94 * @throws IOException
95 */
96 Unknown(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
97 throws IOException {
98 this(name_index, length, (byte[]) null, constant_pool);
99 if (length > 0) {
100 bytes = new byte[length];
101 file.readFully(bytes);
102 }
103 }
104
105
106 /**
107 * Called by objects that are traversing the nodes of the tree implicitely
108 * defined by the contents of a Java class. I.e., the hierarchy of methods,
109 * fields, attributes, etc. spawns a tree of objects.
110 *
111 * @param v Visitor object
112 */
113 public void accept( Visitor v ) {
114 v.visitUnknown(this);
115 }
116
117
118 /**
119 * Dump unknown bytes to file stream.
120 *
121 * @param file Output file stream
122 * @throws IOException
123 */
124 public final void dump( DataOutputStream file ) throws IOException {
125 super.dump(file);
126 if (length > 0) {
127 file.write(bytes, 0, length);
128 }
129 }
130
131
132 /**
133 * @return data bytes.
134 */
135 public final byte[] getBytes() {
136 return bytes;
137 }
138
139
140 /**
141 * @return name of attribute.
142 */
143 public final String getName() {
144 return name;
145 }
146
147
148 /**
149 * @param bytes the bytes to set
150 */
151 public final void setBytes( byte[] bytes ) {
152 this.bytes = bytes;
153 }
154
155
156 /**
157 * @return String representation.
158 */
159 public final String toString() {
160 if (length == 0 || bytes == null) {
161 return "(Unknown attribute " + name + ")";
162 }
163 String hex;
164 if (length > 10) {
165 byte[] tmp = new byte[10];
166 System.arraycopy(bytes, 0, tmp, 0, 10);
167 hex = Utility.toHexString(tmp) + "... (truncated)";
168 } else {
169 hex = Utility.toHexString(bytes);
170 }
171 return "(Unknown attribute " + name + ": " + hex + ")";
172 }
173
174
175 /**
176 * @return deep copy of this attribute
177 */
178 public Attribute copy( ConstantPool _constant_pool ) {
179 Unknown c = (Unknown) clone();
180 if (bytes != null) {
181 c.bytes = new byte[bytes.length];
182 System.arraycopy(bytes, 0, c.bytes, 0, bytes.length);
183 }
184 c.constant_pool = _constant_pool;
185 return c;
186 }
187 }
+0
-1342
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Utility.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.CharArrayReader;
21 import java.io.CharArrayWriter;
22 import java.io.FilterReader;
23 import java.io.FilterWriter;
24 import java.io.IOException;
25 import java.io.PrintStream;
26 import java.io.PrintWriter;
27 import java.io.Reader;
28 import java.io.Writer;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Locale;
32 import java.util.zip.GZIPInputStream;
33 import java.util.zip.GZIPOutputStream;
34 import org.apache.bcel.Constants;
35 import org.apache.bcel.util.ByteSequence;
36
37 /**
38 * Utility functions that do not really belong to any class in particular.
39 *
40 * @version $Id: Utility.java 386056 2006-03-15 11:31:56Z tcurdt $
41 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
42 */
43 public abstract class Utility {
44
45 private static int unwrap( ThreadLocal tl ) {
46 return ((Integer) tl.get()).intValue();
47 }
48
49
50 private static void wrap( ThreadLocal tl, int value ) {
51 tl.set(new Integer(value));
52 }
53
54 private static ThreadLocal consumed_chars = new ThreadLocal() {
55
56 protected Object initialValue() {
57 return new Integer(0);
58 }
59 };/* How many chars have been consumed
60 * during parsing in signatureToString().
61 * Read by methodSignatureToString().
62 * Set by side effect,but only internally.
63 */
64 private static boolean wide = false; /* The `WIDE' instruction is used in the
65 * byte code to allow 16-bit wide indices
66 * for local variables. This opcode
67 * precedes an `ILOAD', e.g.. The opcode
68 * immediately following takes an extra
69 * byte which is combined with the
70 * following byte to form a
71 * 16-bit value.
72 */
73
74
75 /**
76 * Convert bit field of flags into string such as `static final'.
77 *
78 * @param access_flags Access flags
79 * @return String representation of flags
80 */
81 public static final String accessToString( int access_flags ) {
82 return accessToString(access_flags, false);
83 }
84
85
86 /**
87 * Convert bit field of flags into string such as `static final'.
88 *
89 * Special case: Classes compiled with new compilers and with the
90 * `ACC_SUPER' flag would be said to be "synchronized". This is
91 * because SUN used the same value for the flags `ACC_SUPER' and
92 * `ACC_SYNCHRONIZED'.
93 *
94 * @param access_flags Access flags
95 * @param for_class access flags are for class qualifiers ?
96 * @return String representation of flags
97 */
98 public static final String accessToString( int access_flags, boolean for_class ) {
99 StringBuffer buf = new StringBuffer();
100 int p = 0;
101 for (int i = 0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags
102 p = pow2(i);
103 if ((access_flags & p) != 0) {
104 /* Special case: Classes compiled with new compilers and with the
105 * `ACC_SUPER' flag would be said to be "synchronized". This is
106 * because SUN used the same value for the flags `ACC_SUPER' and
107 * `ACC_SYNCHRONIZED'.
108 */
109 if (for_class && ((p == Constants.ACC_SUPER) || (p == Constants.ACC_INTERFACE))) {
110 continue;
111 }
112 buf.append(Constants.ACCESS_NAMES[i]).append(" ");
113 }
114 }
115 return buf.toString().trim();
116 }
117
118
119 /**
120 * @return "class" or "interface", depending on the ACC_INTERFACE flag
121 */
122 public static final String classOrInterface( int access_flags ) {
123 return ((access_flags & Constants.ACC_INTERFACE) != 0) ? "interface" : "class";
124 }
125
126
127 /**
128 * Disassemble a byte array of JVM byte codes starting from code line
129 * `index' and return the disassembled string representation. Decode only
130 * `num' opcodes (including their operands), use -1 if you want to
131 * decompile everything.
132 *
133 * @param code byte code array
134 * @param constant_pool Array of constants
135 * @param index offset in `code' array
136 * <EM>(number of opcodes, not bytes!)</EM>
137 * @param length number of opcodes to decompile, -1 for all
138 * @param verbose be verbose, e.g. print constant pool index
139 * @return String representation of byte codes
140 */
141 public static final String codeToString( byte[] code, ConstantPool constant_pool, int index,
142 int length, boolean verbose ) {
143 StringBuffer buf = new StringBuffer(code.length * 20); // Should be sufficient
144 ByteSequence stream = new ByteSequence(code);
145 try {
146 for (int i = 0; i < index; i++) {
147 codeToString(stream, constant_pool, verbose);
148 }
149 for (int i = 0; stream.available() > 0; i++) {
150 if ((length < 0) || (i < length)) {
151 String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
152 buf.append(indices).append(codeToString(stream, constant_pool, verbose))
153 .append('\n');
154 }
155 }
156 } catch (IOException e) {
157 System.out.println(buf.toString());
158 e.printStackTrace();
159 throw new ClassFormatException("Byte code error: " + e);
160 }
161 return buf.toString();
162 }
163
164
165 public static final String codeToString( byte[] code, ConstantPool constant_pool, int index,
166 int length ) {
167 return codeToString(code, constant_pool, index, length, true);
168 }
169
170
171 /**
172 * Disassemble a stream of byte codes and return the
173 * string representation.
174 *
175 * @param bytes stream of bytes
176 * @param constant_pool Array of constants
177 * @param verbose be verbose, e.g. print constant pool index
178 * @return String representation of byte code
179 */
180 public static final String codeToString( ByteSequence bytes, ConstantPool constant_pool,
181 boolean verbose ) throws IOException {
182 short opcode = (short) bytes.readUnsignedByte();
183 int default_offset = 0, low, high, npairs;
184 int index, vindex, constant;
185 int[] match, jump_table;
186 int no_pad_bytes = 0, offset;
187 StringBuffer buf = new StringBuffer(Constants.OPCODE_NAMES[opcode]);
188 /* Special case: Skip (0-3) padding bytes, i.e., the
189 * following bytes are 4-byte-aligned
190 */
191 if ((opcode == Constants.TABLESWITCH) || (opcode == Constants.LOOKUPSWITCH)) {
192 int remainder = bytes.getIndex() % 4;
193 no_pad_bytes = (remainder == 0) ? 0 : 4 - remainder;
194 for (int i = 0; i < no_pad_bytes; i++) {
195 byte b;
196 if ((b = bytes.readByte()) != 0) {
197 System.err.println("Warning: Padding byte != 0 in "
198 + Constants.OPCODE_NAMES[opcode] + ":" + b);
199 }
200 }
201 // Both cases have a field default_offset in common
202 default_offset = bytes.readInt();
203 }
204 switch (opcode) {
205 /* Table switch has variable length arguments.
206 */
207 case Constants.TABLESWITCH:
208 low = bytes.readInt();
209 high = bytes.readInt();
210 offset = bytes.getIndex() - 12 - no_pad_bytes - 1;
211 default_offset += offset;
212 buf.append("\tdefault = ").append(default_offset).append(", low = ").append(low)
213 .append(", high = ").append(high).append("(");
214 jump_table = new int[high - low + 1];
215 for (int i = 0; i < jump_table.length; i++) {
216 jump_table[i] = offset + bytes.readInt();
217 buf.append(jump_table[i]);
218 if (i < jump_table.length - 1) {
219 buf.append(", ");
220 }
221 }
222 buf.append(")");
223 break;
224 /* Lookup switch has variable length arguments.
225 */
226 case Constants.LOOKUPSWITCH: {
227 npairs = bytes.readInt();
228 offset = bytes.getIndex() - 8 - no_pad_bytes - 1;
229 match = new int[npairs];
230 jump_table = new int[npairs];
231 default_offset += offset;
232 buf.append("\tdefault = ").append(default_offset).append(", npairs = ").append(
233 npairs).append(" (");
234 for (int i = 0; i < npairs; i++) {
235 match[i] = bytes.readInt();
236 jump_table[i] = offset + bytes.readInt();
237 buf.append("(").append(match[i]).append(", ").append(jump_table[i]).append(")");
238 if (i < npairs - 1) {
239 buf.append(", ");
240 }
241 }
242 buf.append(")");
243 }
244 break;
245 /* Two address bytes + offset from start of byte stream form the
246 * jump target
247 */
248 case Constants.GOTO:
249 case Constants.IFEQ:
250 case Constants.IFGE:
251 case Constants.IFGT:
252 case Constants.IFLE:
253 case Constants.IFLT:
254 case Constants.JSR:
255 case Constants.IFNE:
256 case Constants.IFNONNULL:
257 case Constants.IFNULL:
258 case Constants.IF_ACMPEQ:
259 case Constants.IF_ACMPNE:
260 case Constants.IF_ICMPEQ:
261 case Constants.IF_ICMPGE:
262 case Constants.IF_ICMPGT:
263 case Constants.IF_ICMPLE:
264 case Constants.IF_ICMPLT:
265 case Constants.IF_ICMPNE:
266 buf.append("\t\t#").append((bytes.getIndex() - 1) + bytes.readShort());
267 break;
268 /* 32-bit wide jumps
269 */
270 case Constants.GOTO_W:
271 case Constants.JSR_W:
272 buf.append("\t\t#").append(((bytes.getIndex() - 1) + bytes.readInt()));
273 break;
274 /* Index byte references local variable (register)
275 */
276 case Constants.ALOAD:
277 case Constants.ASTORE:
278 case Constants.DLOAD:
279 case Constants.DSTORE:
280 case Constants.FLOAD:
281 case Constants.FSTORE:
282 case Constants.ILOAD:
283 case Constants.ISTORE:
284 case Constants.LLOAD:
285 case Constants.LSTORE:
286 case Constants.RET:
287 if (wide) {
288 vindex = bytes.readUnsignedShort();
289 wide = false; // Clear flag
290 } else {
291 vindex = bytes.readUnsignedByte();
292 }
293 buf.append("\t\t%").append(vindex);
294 break;
295 /*
296 * Remember wide byte which is used to form a 16-bit address in the
297 * following instruction. Relies on that the method is called again with
298 * the following opcode.
299 */
300 case Constants.WIDE:
301 wide = true;
302 buf.append("\t(wide)");
303 break;
304 /* Array of basic type.
305 */
306 case Constants.NEWARRAY:
307 buf.append("\t\t<").append(Constants.TYPE_NAMES[bytes.readByte()]).append(">");
308 break;
309 /* Access object/class fields.
310 */
311 case Constants.GETFIELD:
312 case Constants.GETSTATIC:
313 case Constants.PUTFIELD:
314 case Constants.PUTSTATIC:
315 index = bytes.readUnsignedShort();
316 buf.append("\t\t").append(
317 constant_pool.constantToString(index, Constants.CONSTANT_Fieldref)).append(
318 (verbose ? " (" + index + ")" : ""));
319 break;
320 /* Operands are references to classes in constant pool
321 */
322 case Constants.NEW:
323 case Constants.CHECKCAST:
324 buf.append("\t");
325 case Constants.INSTANCEOF:
326 index = bytes.readUnsignedShort();
327 buf.append("\t<").append(
328 constant_pool.constantToString(index, Constants.CONSTANT_Class))
329 .append(">").append((verbose ? " (" + index + ")" : ""));
330 break;
331 /* Operands are references to methods in constant pool
332 */
333 case Constants.INVOKESPECIAL:
334 case Constants.INVOKESTATIC:
335 case Constants.INVOKEVIRTUAL:
336 index = bytes.readUnsignedShort();
337 buf.append("\t").append(
338 constant_pool.constantToString(index, Constants.CONSTANT_Methodref))
339 .append((verbose ? " (" + index + ")" : ""));
340 break;
341 case Constants.INVOKEINTERFACE:
342 index = bytes.readUnsignedShort();
343 int nargs = bytes.readUnsignedByte(); // historical, redundant
344 buf.append("\t").append(
345 constant_pool
346 .constantToString(index, Constants.CONSTANT_InterfaceMethodref))
347 .append(verbose ? " (" + index + ")\t" : "").append(nargs).append("\t")
348 .append(bytes.readUnsignedByte()); // Last byte is a reserved space
349 break;
350 /* Operands are references to items in constant pool
351 */
352 case Constants.LDC_W:
353 case Constants.LDC2_W:
354 index = bytes.readUnsignedShort();
355 buf.append("\t\t").append(
356 constant_pool.constantToString(index, constant_pool.getConstant(index)
357 .getTag())).append((verbose ? " (" + index + ")" : ""));
358 break;
359 case Constants.LDC:
360 index = bytes.readUnsignedByte();
361 buf.append("\t\t").append(
362 constant_pool.constantToString(index, constant_pool.getConstant(index)
363 .getTag())).append((verbose ? " (" + index + ")" : ""));
364 break;
365 /* Array of references.
366 */
367 case Constants.ANEWARRAY:
368 index = bytes.readUnsignedShort();
369 buf.append("\t\t<").append(
370 compactClassName(constant_pool.getConstantString(index,
371 Constants.CONSTANT_Class), false)).append(">").append(
372 (verbose ? " (" + index + ")" : ""));
373 break;
374 /* Multidimensional array of references.
375 */
376 case Constants.MULTIANEWARRAY: {
377 index = bytes.readUnsignedShort();
378 int dimensions = bytes.readUnsignedByte();
379 buf.append("\t<").append(
380 compactClassName(constant_pool.getConstantString(index,
381 Constants.CONSTANT_Class), false)).append(">\t").append(dimensions)
382 .append((verbose ? " (" + index + ")" : ""));
383 }
384 break;
385 /* Increment local variable.
386 */
387 case Constants.IINC:
388 if (wide) {
389 vindex = bytes.readUnsignedShort();
390 constant = bytes.readShort();
391 wide = false;
392 } else {
393 vindex = bytes.readUnsignedByte();
394 constant = bytes.readByte();
395 }
396 buf.append("\t\t%").append(vindex).append("\t").append(constant);
397 break;
398 default:
399 if (Constants.NO_OF_OPERANDS[opcode] > 0) {
400 for (int i = 0; i < Constants.TYPE_OF_OPERANDS[opcode].length; i++) {
401 buf.append("\t\t");
402 switch (Constants.TYPE_OF_OPERANDS[opcode][i]) {
403 case Constants.T_BYTE:
404 buf.append(bytes.readByte());
405 break;
406 case Constants.T_SHORT:
407 buf.append(bytes.readShort());
408 break;
409 case Constants.T_INT:
410 buf.append(bytes.readInt());
411 break;
412 default: // Never reached
413 System.err.println("Unreachable default case reached!");
414 System.exit(-1);
415 }
416 }
417 }
418 }
419 return buf.toString();
420 }
421
422
423 public static final String codeToString( ByteSequence bytes, ConstantPool constant_pool )
424 throws IOException {
425 return codeToString(bytes, constant_pool, true);
426 }
427
428
429 /**
430 * Shorten long class names, <em>java/lang/String</em> becomes
431 * <em>String</em>.
432 *
433 * @param str The long class name
434 * @return Compacted class name
435 */
436 public static final String compactClassName( String str ) {
437 return compactClassName(str, true);
438 }
439
440
441 /**
442 * Shorten long class name <em>str</em>, i.e., chop off the <em>prefix</em>,
443 * if the
444 * class name starts with this string and the flag <em>chopit</em> is true.
445 * Slashes <em>/</em> are converted to dots <em>.</em>.
446 *
447 * @param str The long class name
448 * @param prefix The prefix the get rid off
449 * @param chopit Flag that determines whether chopping is executed or not
450 * @return Compacted class name
451 */
452 public static final String compactClassName( String str, String prefix, boolean chopit ) {
453 int len = prefix.length();
454 str = str.replace('/', '.'); // Is `/' on all systems, even DOS
455 if (chopit) {
456 // If string starts with `prefix' and contains no further dots
457 if (str.startsWith(prefix) && (str.substring(len).indexOf('.') == -1)) {
458 str = str.substring(len);
459 }
460 }
461 return str;
462 }
463
464
465 /**
466 * Shorten long class names, <em>java/lang/String</em> becomes
467 * <em>java.lang.String</em>,
468 * e.g.. If <em>chopit</em> is <em>true</em> the prefix <em>java.lang</em>
469 * is also removed.
470 *
471 * @param str The long class name
472 * @param chopit Flag that determines whether chopping is executed or not
473 * @return Compacted class name
474 */
475 public static final String compactClassName( String str, boolean chopit ) {
476 return compactClassName(str, "java.lang.", chopit);
477 }
478
479
480 /**
481 * @return `flag' with bit `i' set to 1
482 */
483 public static final int setBit( int flag, int i ) {
484 return flag | pow2(i);
485 }
486
487
488 /**
489 * @return `flag' with bit `i' set to 0
490 */
491 public static final int clearBit( int flag, int i ) {
492 int bit = pow2(i);
493 return (flag & bit) == 0 ? flag : flag ^ bit;
494 }
495
496
497 /**
498 * @return true, if bit `i' in `flag' is set
499 */
500 public static final boolean isSet( int flag, int i ) {
501 return (flag & pow2(i)) != 0;
502 }
503
504
505 /**
506 * Converts string containing the method return and argument types
507 * to a byte code method signature.
508 *
509 * @param ret Return type of method
510 * @param argv Types of method arguments
511 * @return Byte code representation of method signature
512 */
513 public final static String methodTypeToSignature( String ret, String[] argv )
514 throws ClassFormatException {
515 StringBuffer buf = new StringBuffer("(");
516 String str;
517 if (argv != null) {
518 for (int i = 0; i < argv.length; i++) {
519 str = getSignature(argv[i]);
520 if (str.endsWith("V")) {
521 throw new ClassFormatException("Invalid type: " + argv[i]);
522 }
523 buf.append(str);
524 }
525 }
526 str = getSignature(ret);
527 buf.append(")").append(str);
528 return buf.toString();
529 }
530
531
532 /**
533 * @param signature Method signature
534 * @return Array of argument types
535 * @throws ClassFormatException
536 */
537 public static final String[] methodSignatureArgumentTypes( String signature )
538 throws ClassFormatException {
539 return methodSignatureArgumentTypes(signature, true);
540 }
541
542
543 /**
544 * @param signature Method signature
545 * @param chopit Shorten class names ?
546 * @return Array of argument types
547 * @throws ClassFormatException
548 */
549 public static final String[] methodSignatureArgumentTypes( String signature, boolean chopit )
550 throws ClassFormatException {
551 List vec = new ArrayList();
552 int index;
553 try { // Read all declarations between for `(' and `)'
554 if (signature.charAt(0) != '(') {
555 throw new ClassFormatException("Invalid method signature: " + signature);
556 }
557 index = 1; // current string position
558 while (signature.charAt(index) != ')') {
559 vec.add(signatureToString(signature.substring(index), chopit));
560 //corrected concurrent private static field acess
561 index += unwrap(consumed_chars); // update position
562 }
563 } catch (StringIndexOutOfBoundsException e) { // Should never occur
564 throw new ClassFormatException("Invalid method signature: " + signature);
565 }
566 return (String[]) vec.toArray(new String[vec.size()]);
567 }
568
569
570 /**
571 * @param signature Method signature
572 * @return return type of method
573 * @throws ClassFormatException
574 */
575 public static final String methodSignatureReturnType( String signature )
576 throws ClassFormatException {
577 return methodSignatureReturnType(signature, true);
578 }
579
580
581 /**
582 * @param signature Method signature
583 * @param chopit Shorten class names ?
584 * @return return type of method
585 * @throws ClassFormatException
586 */
587 public static final String methodSignatureReturnType( String signature, boolean chopit )
588 throws ClassFormatException {
589 int index;
590 String type;
591 try {
592 // Read return type after `)'
593 index = signature.lastIndexOf(')') + 1;
594 type = signatureToString(signature.substring(index), chopit);
595 } catch (StringIndexOutOfBoundsException e) { // Should never occur
596 throw new ClassFormatException("Invalid method signature: " + signature);
597 }
598 return type;
599 }
600
601
602 /**
603 * Converts method signature to string with all class names compacted.
604 *
605 * @param signature to convert
606 * @param name of method
607 * @param access flags of method
608 * @return Human readable signature
609 */
610 public static final String methodSignatureToString( String signature, String name, String access ) {
611 return methodSignatureToString(signature, name, access, true);
612 }
613
614
615 public static final String methodSignatureToString( String signature, String name,
616 String access, boolean chopit ) {
617 return methodSignatureToString(signature, name, access, chopit, null);
618 }
619
620
621 /**
622 * A return­type signature represents the return value from a method.
623 * It is a series of bytes in the following grammar:
624 *
625 * <return_signature> ::= <field_type> | V
626 *
627 * The character V indicates that the method returns no value. Otherwise, the
628 * signature indicates the type of the return value.
629 * An argument signature represents an argument passed to a method:
630 *
631 * <argument_signature> ::= <field_type>
632 *
633 * A method signature represents the arguments that the method expects, and
634 * the value that it returns.
635 * <method_signature> ::= (<arguments_signature>) <return_signature>
636 * <arguments_signature>::= <argument_signature>*
637 *
638 * This method converts such a string into a Java type declaration like
639 * `void main(String[])' and throws a `ClassFormatException' when the parsed
640 * type is invalid.
641 *
642 * @param signature Method signature
643 * @param name Method name
644 * @param access Method access rights
645 * @return Java type declaration
646 * @throws ClassFormatException
647 */
648 public static final String methodSignatureToString( String signature, String name,
649 String access, boolean chopit, LocalVariableTable vars ) throws ClassFormatException {
650 StringBuffer buf = new StringBuffer("(");
651 String type;
652 int index;
653 int var_index = (access.indexOf("static") >= 0) ? 0 : 1;
654 try { // Read all declarations between for `(' and `)'
655 if (signature.charAt(0) != '(') {
656 throw new ClassFormatException("Invalid method signature: " + signature);
657 }
658 index = 1; // current string position
659 while (signature.charAt(index) != ')') {
660 String param_type = signatureToString(signature.substring(index), chopit);
661 buf.append(param_type);
662 if (vars != null) {
663 LocalVariable l = vars.getLocalVariable(var_index);
664 if (l != null) {
665 buf.append(" ").append(l.getName());
666 }
667 } else {
668 buf.append(" arg").append(var_index);
669 }
670 if ("double".equals(param_type) || "long".equals(param_type)) {
671 var_index += 2;
672 } else {
673 var_index++;
674 }
675 buf.append(", ");
676 //corrected concurrent private static field acess
677 index += unwrap(consumed_chars); // update position
678 }
679 index++; // update position
680 // Read return type after `)'
681 type = signatureToString(signature.substring(index), chopit);
682 } catch (StringIndexOutOfBoundsException e) { // Should never occur
683 throw new ClassFormatException("Invalid method signature: " + signature);
684 }
685 if (buf.length() > 1) {
686 buf.setLength(buf.length() - 2);
687 }
688 buf.append(")");
689 return access + ((access.length() > 0) ? " " : "") + // May be an empty string
690 type + " " + name + buf.toString();
691 }
692
693
694 // Guess what this does
695 private static final int pow2( int n ) {
696 return 1 << n;
697 }
698
699
700 /**
701 * Replace all occurences of <em>old</em> in <em>str</em> with <em>new</em>.
702 *
703 * @param str String to permute
704 * @param old String to be replaced
705 * @param new_ Replacement string
706 * @return new String object
707 */
708 public static final String replace( String str, String old, String new_ ) {
709 int index, old_index;
710 StringBuffer buf = new StringBuffer();
711 try {
712 if ((index = str.indexOf(old)) != -1) { // `old' found in str
713 old_index = 0; // String start offset
714 // While we have something to replace
715 while ((index = str.indexOf(old, old_index)) != -1) {
716 buf.append(str.substring(old_index, index)); // append prefix
717 buf.append(new_); // append replacement
718 old_index = index + old.length(); // Skip `old'.length chars
719 }
720 buf.append(str.substring(old_index)); // append rest of string
721 str = buf.toString();
722 }
723 } catch (StringIndexOutOfBoundsException e) { // Should not occur
724 System.err.println(e);
725 }
726 return str;
727 }
728
729
730 /**
731 * Converts signature to string with all class names compacted.
732 *
733 * @param signature to convert
734 * @return Human readable signature
735 */
736 public static final String signatureToString( String signature ) {
737 return signatureToString(signature, true);
738 }
739
740
741 /**
742 * The field signature represents the value of an argument to a function or
743 * the value of a variable. It is a series of bytes generated by the
744 * following grammar:
745 *
746 * <PRE>
747 * <field_signature> ::= <field_type>
748 * <field_type> ::= <base_type>|<object_type>|<array_type>
749 * <base_type> ::= B|C|D|F|I|J|S|Z
750 * <object_type> ::= L<fullclassname>;
751 * <array_type> ::= [<field_type>
752 *
753 * The meaning of the base types is as follows:
754 * B byte signed byte
755 * C char character
756 * D double double precision IEEE float
757 * F float single precision IEEE float
758 * I int integer
759 * J long long integer
760 * L<fullclassname>; ... an object of the given class
761 * S short signed short
762 * Z boolean true or false
763 * [<field sig> ... array
764 * </PRE>
765 *
766 * This method converts this string into a Java type declaration such as
767 * `String[]' and throws a `ClassFormatException' when the parsed type is
768 * invalid.
769 *
770 * @param signature Class signature
771 * @param chopit Flag that determines whether chopping is executed or not
772 * @return Java type declaration
773 * @throws ClassFormatException
774 */
775 public static final String signatureToString( String signature, boolean chopit ) {
776 //corrected concurrent private static field acess
777 wrap(consumed_chars, 1); // This is the default, read just one char like `B'
778 try {
779 switch (signature.charAt(0)) {
780 case 'B':
781 return "byte";
782 case 'C':
783 return "char";
784 case 'D':
785 return "double";
786 case 'F':
787 return "float";
788 case 'I':
789 return "int";
790 case 'J':
791 return "long";
792 case 'L': { // Full class name
793 int index = signature.indexOf(';'); // Look for closing `;'
794 if (index < 0) {
795 throw new ClassFormatException("Invalid signature: " + signature);
796 }
797 //corrected concurrent private static field acess
798 wrap(consumed_chars, index + 1); // "Lblabla;" `L' and `;' are removed
799 return compactClassName(signature.substring(1, index), chopit);
800 }
801 case 'S':
802 return "short";
803 case 'Z':
804 return "boolean";
805 case '[': { // Array declaration
806 int n;
807 StringBuffer brackets;
808 String type;
809 int consumed_chars; // Shadows global var
810 brackets = new StringBuffer(); // Accumulate []'s
811 // Count opening brackets and look for optional size argument
812 for (n = 0; signature.charAt(n) == '['; n++) {
813 brackets.append("[]");
814 }
815 consumed_chars = n; // Remember value
816 // The rest of the string denotes a `<field_type>'
817 type = signatureToString(signature.substring(n), chopit);
818 //corrected concurrent private static field acess
819 //Utility.consumed_chars += consumed_chars; is replaced by:
820 int _temp = unwrap(Utility.consumed_chars) + consumed_chars;
821 wrap(Utility.consumed_chars, _temp);
822 return type + brackets.toString();
823 }
824 case 'V':
825 return "void";
826 default:
827 throw new ClassFormatException("Invalid signature: `" + signature + "'");
828 }
829 } catch (StringIndexOutOfBoundsException e) { // Should never occur
830 throw new ClassFormatException("Invalid signature: " + e + ":" + signature);
831 }
832 }
833
834
835 /** Parse Java type such as "char", or "java.lang.String[]" and return the
836 * signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
837 *
838 * @param type Java type
839 * @return byte code signature
840 */
841 public static String getSignature( String type ) {
842 StringBuffer buf = new StringBuffer();
843 char[] chars = type.toCharArray();
844 boolean char_found = false, delim = false;
845 int index = -1;
846 loop: for (int i = 0; i < chars.length; i++) {
847 switch (chars[i]) {
848 case ' ':
849 case '\t':
850 case '\n':
851 case '\r':
852 case '\f':
853 if (char_found) {
854 delim = true;
855 }
856 break;
857 case '[':
858 if (!char_found) {
859 throw new RuntimeException("Illegal type: " + type);
860 }
861 index = i;
862 break loop;
863 default:
864 char_found = true;
865 if (!delim) {
866 buf.append(chars[i]);
867 }
868 }
869 }
870 int brackets = 0;
871 if (index > 0) {
872 brackets = countBrackets(type.substring(index));
873 }
874 type = buf.toString();
875 buf.setLength(0);
876 for (int i = 0; i < brackets; i++) {
877 buf.append('[');
878 }
879 boolean found = false;
880 for (int i = Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) {
881 if (Constants.TYPE_NAMES[i].equals(type)) {
882 found = true;
883 buf.append(Constants.SHORT_TYPE_NAMES[i]);
884 }
885 }
886 if (!found) {
887 buf.append('L').append(type.replace('.', '/')).append(';');
888 }
889 return buf.toString();
890 }
891
892
893 private static int countBrackets( String brackets ) {
894 char[] chars = brackets.toCharArray();
895 int count = 0;
896 boolean open = false;
897 for (int i = 0; i < chars.length; i++) {
898 switch (chars[i]) {
899 case '[':
900 if (open) {
901 throw new RuntimeException("Illegally nested brackets:" + brackets);
902 }
903 open = true;
904 break;
905 case ']':
906 if (!open) {
907 throw new RuntimeException("Illegally nested brackets:" + brackets);
908 }
909 open = false;
910 count++;
911 break;
912 default:
913 // Don't care
914 }
915 }
916 if (open) {
917 throw new RuntimeException("Illegally nested brackets:" + brackets);
918 }
919 return count;
920 }
921
922
923 /**
924 * Return type of method signature as a byte value as defined in <em>Constants</em>
925 *
926 * @param signature in format described above
927 * @return type of method signature
928 * @see Constants
929 */
930 public static final byte typeOfMethodSignature( String signature ) throws ClassFormatException {
931 int index;
932 try {
933 if (signature.charAt(0) != '(') {
934 throw new ClassFormatException("Invalid method signature: " + signature);
935 }
936 index = signature.lastIndexOf(')') + 1;
937 return typeOfSignature(signature.substring(index));
938 } catch (StringIndexOutOfBoundsException e) {
939 throw new ClassFormatException("Invalid method signature: " + signature);
940 }
941 }
942
943
944 /**
945 * Return type of signature as a byte value as defined in <em>Constants</em>
946 *
947 * @param signature in format described above
948 * @return type of signature
949 * @see Constants
950 */
951 public static final byte typeOfSignature( String signature ) throws ClassFormatException {
952 try {
953 switch (signature.charAt(0)) {
954 case 'B':
955 return Constants.T_BYTE;
956 case 'C':
957 return Constants.T_CHAR;
958 case 'D':
959 return Constants.T_DOUBLE;
960 case 'F':
961 return Constants.T_FLOAT;
962 case 'I':
963 return Constants.T_INT;
964 case 'J':
965 return Constants.T_LONG;
966 case 'L':
967 return Constants.T_REFERENCE;
968 case '[':
969 return Constants.T_ARRAY;
970 case 'V':
971 return Constants.T_VOID;
972 case 'Z':
973 return Constants.T_BOOLEAN;
974 case 'S':
975 return Constants.T_SHORT;
976 default:
977 throw new ClassFormatException("Invalid method signature: " + signature);
978 }
979 } catch (StringIndexOutOfBoundsException e) {
980 throw new ClassFormatException("Invalid method signature: " + signature);
981 }
982 }
983
984
985 /** Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload"
986 */
987 public static short searchOpcode( String name ) {
988 name = name.toLowerCase(Locale.ENGLISH);
989 for (short i = 0; i < Constants.OPCODE_NAMES.length; i++) {
990 if (Constants.OPCODE_NAMES[i].equals(name)) {
991 return i;
992 }
993 }
994 return -1;
995 }
996
997
998 /**
999 * Convert (signed) byte to (unsigned) short value, i.e., all negative
1000 * values become positive.
1001 */
1002 private static final short byteToShort( byte b ) {
1003 return (b < 0) ? (short) (256 + b) : (short) b;
1004 }
1005
1006
1007 /** Convert bytes into hexidecimal string
1008 *
1009 * @return bytes as hexidecimal string, e.g. 00 FA 12 ...
1010 */
1011 public static final String toHexString( byte[] bytes ) {
1012 StringBuffer buf = new StringBuffer();
1013 for (int i = 0; i < bytes.length; i++) {
1014 short b = byteToShort(bytes[i]);
1015 String hex = Integer.toString(b, 0x10);
1016 if (b < 0x10) {
1017 buf.append('0');
1018 }
1019 buf.append(hex);
1020 if (i < bytes.length - 1) {
1021 buf.append(' ');
1022 }
1023 }
1024 return buf.toString();
1025 }
1026
1027
1028 /**
1029 * Return a string for an integer justified left or right and filled up with
1030 * `fill' characters if necessary.
1031 *
1032 * @param i integer to format
1033 * @param length length of desired string
1034 * @param left_justify format left or right
1035 * @param fill fill character
1036 * @return formatted int
1037 */
1038 public static final String format( int i, int length, boolean left_justify, char fill ) {
1039 return fillup(Integer.toString(i), length, left_justify, fill);
1040 }
1041
1042
1043 /**
1044 * Fillup char with up to length characters with char `fill' and justify it left or right.
1045 *
1046 * @param str string to format
1047 * @param length length of desired string
1048 * @param left_justify format left or right
1049 * @param fill fill character
1050 * @return formatted string
1051 */
1052 public static final String fillup( String str, int length, boolean left_justify, char fill ) {
1053 int len = length - str.length();
1054 char[] buf = new char[(len < 0) ? 0 : len];
1055 for (int j = 0; j < buf.length; j++) {
1056 buf[j] = fill;
1057 }
1058 if (left_justify) {
1059 return str + new String(buf);
1060 }
1061 return new String(buf) + str;
1062 }
1063
1064
1065 static final boolean equals( byte[] a, byte[] b ) {
1066 int size;
1067 if ((size = a.length) != b.length) {
1068 return false;
1069 }
1070 for (int i = 0; i < size; i++) {
1071 if (a[i] != b[i]) {
1072 return false;
1073 }
1074 }
1075 return true;
1076 }
1077
1078
1079 public static final void printArray( PrintStream out, Object[] obj ) {
1080 out.println(printArray(obj, true));
1081 }
1082
1083
1084 public static final void printArray( PrintWriter out, Object[] obj ) {
1085 out.println(printArray(obj, true));
1086 }
1087
1088
1089 public static final String printArray( Object[] obj ) {
1090 return printArray(obj, true);
1091 }
1092
1093
1094 public static final String printArray( Object[] obj, boolean braces ) {
1095 return printArray(obj, braces, false);
1096 }
1097
1098
1099 public static final String printArray( Object[] obj, boolean braces, boolean quote ) {
1100 if (obj == null) {
1101 return null;
1102 }
1103 StringBuffer buf = new StringBuffer();
1104 if (braces) {
1105 buf.append('{');
1106 }
1107 for (int i = 0; i < obj.length; i++) {
1108 if (obj[i] != null) {
1109 buf.append((quote ? "\"" : "")).append(obj[i].toString()).append(
1110 (quote ? "\"" : ""));
1111 } else {
1112 buf.append("null");
1113 }
1114 if (i < obj.length - 1) {
1115 buf.append(", ");
1116 }
1117 }
1118 if (braces) {
1119 buf.append('}');
1120 }
1121 return buf.toString();
1122 }
1123
1124
1125 /** @return true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _)
1126 */
1127 public static boolean isJavaIdentifierPart( char ch ) {
1128 return ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))
1129 || ((ch >= '0') && (ch <= '9')) || (ch == '_');
1130 }
1131
1132
1133 /** Encode byte array it into Java identifier string, i.e., a string
1134 * that only contains the following characters: (a, ... z, A, ... Z,
1135 * 0, ... 9, _, $). The encoding algorithm itself is not too
1136 * clever: if the current byte's ASCII value already is a valid Java
1137 * identifier part, leave it as it is. Otherwise it writes the
1138 * escape character($) followed by <p><ul><li> the ASCII value as a
1139 * hexadecimal string, if the value is not in the range
1140 * 200..247</li> <li>a Java identifier char not used in a lowercase
1141 * hexadecimal string, if the value is in the range
1142 * 200..247</li><ul></p>
1143 *
1144 * <p>This operation inflates the original byte array by roughly 40-50%</p>
1145 *
1146 * @param bytes the byte array to convert
1147 * @param compress use gzip to minimize string
1148 */
1149 public static String encode( byte[] bytes, boolean compress ) throws IOException {
1150 if (compress) {
1151 ByteArrayOutputStream baos = new ByteArrayOutputStream();
1152 GZIPOutputStream gos = new GZIPOutputStream(baos);
1153 gos.write(bytes, 0, bytes.length);
1154 gos.close();
1155 baos.close();
1156 bytes = baos.toByteArray();
1157 }
1158 CharArrayWriter caw = new CharArrayWriter();
1159 JavaWriter jw = new JavaWriter(caw);
1160 for (int i = 0; i < bytes.length; i++) {
1161 int in = bytes[i] & 0x000000ff; // Normalize to unsigned
1162 jw.write(in);
1163 }
1164 return caw.toString();
1165 }
1166
1167
1168 /** Decode a string back to a byte array.
1169 *
1170 * @param s the string to convert
1171 * @param uncompress use gzip to uncompress the stream of bytes
1172 */
1173 public static byte[] decode( String s, boolean uncompress ) throws IOException {
1174 char[] chars = s.toCharArray();
1175 CharArrayReader car = new CharArrayReader(chars);
1176 JavaReader jr = new JavaReader(car);
1177 ByteArrayOutputStream bos = new ByteArrayOutputStream();
1178 int ch;
1179 while ((ch = jr.read()) >= 0) {
1180 bos.write(ch);
1181 }
1182 bos.close();
1183 car.close();
1184 jr.close();
1185 byte[] bytes = bos.toByteArray();
1186 if (uncompress) {
1187 GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
1188 byte[] tmp = new byte[bytes.length * 3]; // Rough estimate
1189 int count = 0;
1190 int b;
1191 while ((b = gis.read()) >= 0) {
1192 tmp[count++] = (byte) b;
1193 }
1194 bytes = new byte[count];
1195 System.arraycopy(tmp, 0, bytes, 0, count);
1196 }
1197 return bytes;
1198 }
1199
1200 // A-Z, g-z, _, $
1201 private static final int FREE_CHARS = 48;
1202 static int[] CHAR_MAP = new int[FREE_CHARS];
1203 static int[] MAP_CHAR = new int[256]; // Reverse map
1204 private static final char ESCAPE_CHAR = '$';
1205 static {
1206 int j = 0;
1207 for (int i = 'A'; i <= 'Z'; i++) {
1208 CHAR_MAP[j] = i;
1209 MAP_CHAR[i] = j;
1210 j++;
1211 }
1212 for (int i = 'g'; i <= 'z'; i++) {
1213 CHAR_MAP[j] = i;
1214 MAP_CHAR[i] = j;
1215 j++;
1216 }
1217 CHAR_MAP[j] = '$';
1218 MAP_CHAR['$'] = j;
1219 j++;
1220 CHAR_MAP[j] = '_';
1221 MAP_CHAR['_'] = j;
1222 }
1223
1224 /** Decode characters into bytes.
1225 * Used by <a href="Utility.html#decode(java.lang.String, boolean)">decode()</a>
1226 */
1227 private static class JavaReader extends FilterReader {
1228
1229 public JavaReader(Reader in) {
1230 super(in);
1231 }
1232
1233
1234 public int read() throws IOException {
1235 int b = in.read();
1236 if (b != ESCAPE_CHAR) {
1237 return b;
1238 }
1239 int i = in.read();
1240 if (i < 0) {
1241 return -1;
1242 }
1243 if (((i >= '0') && (i <= '9')) || ((i >= 'a') && (i <= 'f'))) { // Normal escape
1244 int j = in.read();
1245 if (j < 0) {
1246 return -1;
1247 }
1248 char[] tmp = {
1249 (char) i, (char) j
1250 };
1251 int s = Integer.parseInt(new String(tmp), 16);
1252 return s;
1253 }
1254 return MAP_CHAR[i];
1255 }
1256
1257
1258 public int read( char[] cbuf, int off, int len ) throws IOException {
1259 for (int i = 0; i < len; i++) {
1260 cbuf[off + i] = (char) read();
1261 }
1262 return len;
1263 }
1264 }
1265
1266 /** Encode bytes into valid java identifier characters.
1267 * Used by <a href="Utility.html#encode(byte[], boolean)">encode()</a>
1268 */
1269 private static class JavaWriter extends FilterWriter {
1270
1271 public JavaWriter(Writer out) {
1272 super(out);
1273 }
1274
1275
1276 public void write( int b ) throws IOException {
1277 if (isJavaIdentifierPart((char) b) && (b != ESCAPE_CHAR)) {
1278 out.write(b);
1279 } else {
1280 out.write(ESCAPE_CHAR); // Escape character
1281 // Special escape
1282 if (b >= 0 && b < FREE_CHARS) {
1283 out.write(CHAR_MAP[b]);
1284 } else { // Normal escape
1285 char[] tmp = Integer.toHexString(b).toCharArray();
1286 if (tmp.length == 1) {
1287 out.write('0');
1288 out.write(tmp[0]);
1289 } else {
1290 out.write(tmp[0]);
1291 out.write(tmp[1]);
1292 }
1293 }
1294 }
1295 }
1296
1297
1298 public void write( char[] cbuf, int off, int len ) throws IOException {
1299 for (int i = 0; i < len; i++) {
1300 write(cbuf[off + i]);
1301 }
1302 }
1303
1304
1305 public void write( String str, int off, int len ) throws IOException {
1306 write(str.toCharArray(), off, len);
1307 }
1308 }
1309
1310
1311 /**
1312 * Escape all occurences of newline chars '\n', quotes \", etc.
1313 */
1314 public static final String convertString( String label ) {
1315 char[] ch = label.toCharArray();
1316 StringBuffer buf = new StringBuffer();
1317 for (int i = 0; i < ch.length; i++) {
1318 switch (ch[i]) {
1319 case '\n':
1320 buf.append("\\n");
1321 break;
1322 case '\r':
1323 buf.append("\\r");
1324 break;
1325 case '\"':
1326 buf.append("\\\"");
1327 break;
1328 case '\'':
1329 buf.append("\\'");
1330 break;
1331 case '\\':
1332 buf.append("\\\\");
1333 break;
1334 default:
1335 buf.append(ch[i]);
1336 break;
1337 }
1338 }
1339 return buf.toString();
1340 }
1341 }
+0
-128
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/Visitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.classfile;
17
18 /**
19 * Interface to make use of the Visitor pattern programming style.
20 * I.e. a class that implements this interface can traverse the contents of
21 * a Java class just by calling the `accept' method which all classes have.
22 *
23 * @version $Id: Visitor.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public interface Visitor {
27
28 //public void visitAnnotation(Annotations obj);
29 //public void visitParameterAnnotation(ParameterAnnotations obj);
30 //public void visitAnnotationEntry(AnnotationEntry obj);
31 //public void visitAnnotationDefault(AnnotationDefault obj);
32 public void visitCode( Code obj );
33
34
35 public void visitCodeException( CodeException obj );
36
37
38 public void visitConstantClass( ConstantClass obj );
39
40
41 public void visitConstantDouble( ConstantDouble obj );
42
43
44 public void visitConstantFieldref( ConstantFieldref obj );
45
46
47 public void visitConstantFloat( ConstantFloat obj );
48
49
50 public void visitConstantInteger( ConstantInteger obj );
51
52
53 public void visitConstantInterfaceMethodref( ConstantInterfaceMethodref obj );
54
55
56 public void visitConstantLong( ConstantLong obj );
57
58
59 public void visitConstantMethodref( ConstantMethodref obj );
60
61
62 public void visitConstantNameAndType( ConstantNameAndType obj );
63
64
65 public void visitConstantPool( ConstantPool obj );
66
67
68 public void visitConstantString( ConstantString obj );
69
70
71 public void visitConstantUtf8( ConstantUtf8 obj );
72
73
74 public void visitConstantValue( ConstantValue obj );
75
76
77 public void visitDeprecated( Deprecated obj );
78
79
80 public void visitExceptionTable( ExceptionTable obj );
81
82
83 public void visitField( Field obj );
84
85
86 public void visitInnerClass( InnerClass obj );
87
88
89 public void visitInnerClasses( InnerClasses obj );
90
91
92 public void visitJavaClass( JavaClass obj );
93
94
95 public void visitLineNumber( LineNumber obj );
96
97
98 public void visitLineNumberTable( LineNumberTable obj );
99
100
101 public void visitLocalVariable( LocalVariable obj );
102
103
104 public void visitLocalVariableTable( LocalVariableTable obj );
105 public void visitLocalVariableTypeTable( LocalVariableTypeTable obj );
106
107
108 public void visitMethod( Method obj );
109
110
111 public void visitSignature( Signature obj );
112
113
114 public void visitSourceFile( SourceFile obj );
115
116
117 public void visitSynthetic( Synthetic obj );
118
119
120 public void visitUnknown( Unknown obj );
121
122
123 public void visitStackMap( StackMap obj );
124
125
126 public void visitStackMapEntry( StackMapEntry obj );
127 }
+0
-14
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/classfile/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 152690 2001-10-29 19:59:54Z jvanzyl $
5 -->
6 </head>
7 <body bgcolor="white">
8 <p>
9 This package contains the classes that describe the structure of a
10 Java class file and a class file parser.
11 </p>
12 </body>
13 </html>
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/AALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * AALOAD - Load reference from array
20 * <PRE>Stack: ..., arrayref, index -&gt; value</PRE>
21 *
22 * @version $Id: AALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class AALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load reference from array
28 */
29 public AALOAD() {
30 super(org.apache.bcel.Constants.AALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitAALOAD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/AASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * AASTORE - Store into reference array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: AASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class AASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store into reference array
28 */
29 public AASTORE() {
30 super(org.apache.bcel.Constants.AASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitAASTORE(this);
48 }
49 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ACONST_NULL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ACONST_NULL - Push null reference
20 * <PRE>Stack: ... -&gt; ..., null</PRE>
21 *
22 * @version $Id: ACONST_NULL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ACONST_NULL extends Instruction implements PushInstruction, TypedInstruction {
26
27 /**
28 * Push null reference
29 */
30 public ACONST_NULL() {
31 super(org.apache.bcel.Constants.ACONST_NULL, (short) 1);
32 }
33
34
35 /** @return Type.NULL
36 */
37 public Type getType( ConstantPoolGen cp ) {
38 return Type.NULL;
39 }
40
41
42 /**
43 * Call corresponding visitor method(s). The order is:
44 * Call visitor methods of implemented interfaces first, then
45 * call methods according to the class hierarchy in descending order,
46 * i.e., the most specific visitXXX() call comes last.
47 *
48 * @param v Visitor object
49 */
50 public void accept( Visitor v ) {
51 v.visitStackProducer(this);
52 v.visitPushInstruction(this);
53 v.visitTypedInstruction(this);
54 v.visitACONST_NULL(this);
55 }
56 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ALOAD - Load reference from local variable
20 * <PRE>Stack: ... -&gt; ..., objectref</PRE>
21 *
22 * @version $Id: ALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ALOAD extends LoadInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 ALOAD() {
32 super(org.apache.bcel.Constants.ALOAD, org.apache.bcel.Constants.ALOAD_0);
33 }
34
35
36 /** Load reference from local variable
37 * @param n index of local variable
38 */
39 public ALOAD(int n) {
40 super(org.apache.bcel.Constants.ALOAD, org.apache.bcel.Constants.ALOAD_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitALOAD(this);
55 }
56 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ANEWARRAY.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.ExceptionConstants;
19
20 /**
21 * ANEWARRAY - Create new array of references
22 * <PRE>Stack: ..., count -&gt; ..., arrayref</PRE>
23 *
24 * @version $Id: ANEWARRAY.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class ANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction,
28 ExceptionThrower, StackConsumer, StackProducer {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 ANEWARRAY() {
35 }
36
37
38 public ANEWARRAY(int index) {
39 super(org.apache.bcel.Constants.ANEWARRAY, index);
40 }
41
42
43 public Class[] getExceptions() {
44 Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
45 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, cs, 0,
46 ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
47 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
48 return cs;
49 }
50
51
52 /**
53 * Call corresponding visitor method(s). The order is:
54 * Call visitor methods of implemented interfaces first, then
55 * call methods according to the class hierarchy in descending order,
56 * i.e., the most specific visitXXX() call comes last.
57 *
58 * @param v Visitor object
59 */
60 public void accept( Visitor v ) {
61 v.visitLoadClass(this);
62 v.visitAllocationInstruction(this);
63 v.visitExceptionThrower(this);
64 v.visitStackProducer(this);
65 v.visitTypedInstruction(this);
66 v.visitCPInstruction(this);
67 v.visitANEWARRAY(this);
68 }
69
70
71 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
72 Type t = getType(cpg);
73 if (t instanceof ArrayType) {
74 t = ((ArrayType) t).getBasicType();
75 }
76 return (t instanceof ObjectType) ? (ObjectType) t : null;
77 }
78 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ARETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ARETURN - Return reference from method
20 * <PRE>Stack: ..., objectref -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: ARETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ARETURN extends ReturnInstruction {
26
27 /**
28 * Return reference from method
29 */
30 public ARETURN() {
31 super(org.apache.bcel.Constants.ARETURN);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitStackConsumer(this);
47 v.visitReturnInstruction(this);
48 v.visitARETURN(this);
49 }
50 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ARRAYLENGTH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ARRAYLENGTH - Get length of array
20 * <PRE>Stack: ..., arrayref -&gt; ..., length</PRE>
21 *
22 * @version $Id: ARRAYLENGTH.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ARRAYLENGTH extends Instruction implements ExceptionThrower, StackProducer {
26
27 /** Get length of array
28 */
29 public ARRAYLENGTH() {
30 super(org.apache.bcel.Constants.ARRAYLENGTH, (short) 1);
31 }
32
33
34 /** @return exceptions this instruction may cause
35 */
36 public Class[] getExceptions() {
37 return new Class[] {
38 org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION
39 };
40 }
41
42
43 /**
44 * Call corresponding visitor method(s). The order is:
45 * Call visitor methods of implemented interfaces first, then
46 * call methods according to the class hierarchy in descending order,
47 * i.e., the most specific visitXXX() call comes last.
48 *
49 * @param v Visitor object
50 */
51 public void accept( Visitor v ) {
52 v.visitExceptionThrower(this);
53 v.visitStackProducer(this);
54 v.visitARRAYLENGTH(this);
55 }
56 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ASTORE - Store reference into local variable
20 * <PRE>Stack ..., objectref -&gt; ... </PRE>
21 *
22 * @version $Id: ASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ASTORE extends StoreInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 ASTORE() {
32 super(org.apache.bcel.Constants.ASTORE, org.apache.bcel.Constants.ASTORE_0);
33 }
34
35
36 /** Store reference into local variable
37 * @param n index of local variable
38 */
39 public ASTORE(int n) {
40 super(org.apache.bcel.Constants.ASTORE, org.apache.bcel.Constants.ASTORE_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitASTORE(this);
55 }
56 }
+0
-58
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ATHROW.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ATHROW - Throw exception
20 * <PRE>Stack: ..., objectref -&gt; objectref</PRE>
21 *
22 * @version $Id: ATHROW.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower {
26
27 /**
28 * Throw exception
29 */
30 public ATHROW() {
31 super(org.apache.bcel.Constants.ATHROW, (short) 1);
32 }
33
34
35 /** @return exceptions this instruction may cause
36 */
37 public Class[] getExceptions() {
38 return new Class[] {
39 org.apache.bcel.ExceptionConstants.THROWABLE
40 };
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 v.visitUnconditionalBranch(this);
54 v.visitExceptionThrower(this);
55 v.visitATHROW(this);
56 }
57 }
+0
-26
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/AllocationInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote family of instructions that allocates space in the heap.
20 *
21 * @version $Id: AllocationInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public interface AllocationInstruction {
25 }
+0
-94
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ArithmeticInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Super class for the family of arithmetic instructions.
22 *
23 * @version $Id: ArithmeticInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public abstract class ArithmeticInstruction extends Instruction implements TypedInstruction,
27 StackProducer, StackConsumer {
28
29 /**
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 ArithmeticInstruction() {
34 }
35
36
37 /**
38 * @param opcode of instruction
39 */
40 protected ArithmeticInstruction(short opcode) {
41 super(opcode, (short) 1);
42 }
43
44
45 /** @return type associated with the instruction
46 */
47 public Type getType( ConstantPoolGen cp ) {
48 switch (opcode) {
49 case Constants.DADD:
50 case Constants.DDIV:
51 case Constants.DMUL:
52 case Constants.DNEG:
53 case Constants.DREM:
54 case Constants.DSUB:
55 return Type.DOUBLE;
56 case Constants.FADD:
57 case Constants.FDIV:
58 case Constants.FMUL:
59 case Constants.FNEG:
60 case Constants.FREM:
61 case Constants.FSUB:
62 return Type.FLOAT;
63 case Constants.IADD:
64 case Constants.IAND:
65 case Constants.IDIV:
66 case Constants.IMUL:
67 case Constants.INEG:
68 case Constants.IOR:
69 case Constants.IREM:
70 case Constants.ISHL:
71 case Constants.ISHR:
72 case Constants.ISUB:
73 case Constants.IUSHR:
74 case Constants.IXOR:
75 return Type.INT;
76 case Constants.LADD:
77 case Constants.LAND:
78 case Constants.LDIV:
79 case Constants.LMUL:
80 case Constants.LNEG:
81 case Constants.LOR:
82 case Constants.LREM:
83 case Constants.LSHL:
84 case Constants.LSHR:
85 case Constants.LSUB:
86 case Constants.LUSHR:
87 case Constants.LXOR:
88 return Type.LONG;
89 default: // Never reached
90 throw new ClassGenException("Unknown type " + opcode);
91 }
92 }
93 }
+0
-81
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ArrayInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Super class for instructions dealing with array access such as IALOAD.
20 *
21 * @version $Id: ArrayInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class ArrayInstruction extends Instruction implements ExceptionThrower,
25 TypedInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 ArrayInstruction() {
32 }
33
34
35 /**
36 * @param opcode of instruction
37 */
38 protected ArrayInstruction(short opcode) {
39 super(opcode, (short) 1);
40 }
41
42
43 public Class[] getExceptions() {
44 return org.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION;
45 }
46
47
48 /** @return type associated with the instruction
49 */
50 public Type getType( ConstantPoolGen cp ) {
51 switch (opcode) {
52 case org.apache.bcel.Constants.IALOAD:
53 case org.apache.bcel.Constants.IASTORE:
54 return Type.INT;
55 case org.apache.bcel.Constants.CALOAD:
56 case org.apache.bcel.Constants.CASTORE:
57 return Type.CHAR;
58 case org.apache.bcel.Constants.BALOAD:
59 case org.apache.bcel.Constants.BASTORE:
60 return Type.BYTE;
61 case org.apache.bcel.Constants.SALOAD:
62 case org.apache.bcel.Constants.SASTORE:
63 return Type.SHORT;
64 case org.apache.bcel.Constants.LALOAD:
65 case org.apache.bcel.Constants.LASTORE:
66 return Type.LONG;
67 case org.apache.bcel.Constants.DALOAD:
68 case org.apache.bcel.Constants.DASTORE:
69 return Type.DOUBLE;
70 case org.apache.bcel.Constants.FALOAD:
71 case org.apache.bcel.Constants.FASTORE:
72 return Type.FLOAT;
73 case org.apache.bcel.Constants.AALOAD:
74 case org.apache.bcel.Constants.AASTORE:
75 return Type.OBJECT;
76 default:
77 throw new ClassGenException("Oops: unknown case in switch" + opcode);
78 }
79 }
80 }
+0
-127
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ArrayType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Denotes array type, such as int[][]
22 *
23 * @version $Id: ArrayType.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public final class ArrayType extends ReferenceType {
27
28 private int dimensions;
29 private Type basic_type;
30
31
32 /**
33 * Convenience constructor for array type, e.g. int[]
34 *
35 * @param type array type, e.g. T_INT
36 */
37 public ArrayType(byte type, int dimensions) {
38 this(BasicType.getType(type), dimensions);
39 }
40
41
42 /**
43 * Convenience constructor for reference array type, e.g. Object[]
44 *
45 * @param class_name complete name of class (java.lang.String, e.g.)
46 */
47 public ArrayType(String class_name, int dimensions) {
48 this(ObjectType.getInstance(class_name), dimensions);
49 }
50
51
52 /**
53 * Constructor for array of given type
54 *
55 * @param type type of array (may be an array itself)
56 */
57 public ArrayType(Type type, int dimensions) {
58 super(Constants.T_ARRAY, "<dummy>");
59 if ((dimensions < 1) || (dimensions > Constants.MAX_BYTE)) {
60 throw new ClassGenException("Invalid number of dimensions: " + dimensions);
61 }
62 switch (type.getType()) {
63 case Constants.T_ARRAY:
64 ArrayType array = (ArrayType) type;
65 this.dimensions = dimensions + array.dimensions;
66 basic_type = array.basic_type;
67 break;
68 case Constants.T_VOID:
69 throw new ClassGenException("Invalid type: void[]");
70 default: // Basic type or reference
71 this.dimensions = dimensions;
72 basic_type = type;
73 break;
74 }
75 StringBuffer buf = new StringBuffer();
76 for (int i = 0; i < this.dimensions; i++) {
77 buf.append('[');
78 }
79 buf.append(basic_type.getSignature());
80 signature = buf.toString();
81 }
82
83
84 /**
85 * @return basic type of array, i.e., for int[][][] the basic type is int
86 */
87 public Type getBasicType() {
88 return basic_type;
89 }
90
91
92 /**
93 * @return element type of array, i.e., for int[][][] the element type is int[][]
94 */
95 public Type getElementType() {
96 if (dimensions == 1) {
97 return basic_type;
98 }
99 return new ArrayType(basic_type, dimensions - 1);
100 }
101
102
103 /** @return number of dimensions of array
104 */
105 public int getDimensions() {
106 return dimensions;
107 }
108
109
110 /** @return a hash code value for the object.
111 */
112 public int hashCode() {
113 return basic_type.hashCode() ^ dimensions;
114 }
115
116
117 /** @return true if both type objects refer to the same array type.
118 */
119 public boolean equals( Object _type ) {
120 if (_type instanceof ArrayType) {
121 ArrayType array = (ArrayType) _type;
122 return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);
123 }
124 return false;
125 }
126 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * BALOAD - Load byte or boolean from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
21 *
22 * @version $Id: BALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class BALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load byte or boolean from array
28 */
29 public BALOAD() {
30 super(org.apache.bcel.Constants.BALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitBALOAD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * BASTORE - Store into byte or boolean array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: BASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class BASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store byte or boolean into array
28 */
29 public BASTORE() {
30 super(org.apache.bcel.Constants.BASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitBASTORE(this);
48 }
49 }
+0
-105
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BIPUSH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * BIPUSH - Push byte on stack
24 *
25 * <PRE>Stack: ... -&gt; ..., value</PRE>
26 *
27 * @version $Id: BIPUSH.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class BIPUSH extends Instruction implements ConstantPushInstruction {
31
32 private byte b;
33
34
35 /**
36 * Empty constructor needed for the Class.newInstance() statement in
37 * Instruction.readInstruction(). Not to be used otherwise.
38 */
39 BIPUSH() {
40 }
41
42
43 /** Push byte on stack
44 */
45 public BIPUSH(byte b) {
46 super(org.apache.bcel.Constants.BIPUSH, (short) 2);
47 this.b = b;
48 }
49
50
51 /**
52 * Dump instruction as byte code to stream out.
53 */
54 public void dump( DataOutputStream out ) throws IOException {
55 super.dump(out);
56 out.writeByte(b);
57 }
58
59
60 /**
61 * @return mnemonic for instruction
62 */
63 public String toString( boolean verbose ) {
64 return super.toString(verbose) + " " + b;
65 }
66
67
68 /**
69 * Read needed data (e.g. index) from file.
70 */
71 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
72 length = 2;
73 b = bytes.readByte();
74 }
75
76
77 public Number getValue() {
78 return new Integer(b);
79 }
80
81
82 /** @return Type.BYTE
83 */
84 public Type getType( ConstantPoolGen cp ) {
85 return Type.BYTE;
86 }
87
88
89 /**
90 * Call corresponding visitor method(s). The order is:
91 * Call visitor methods of implemented interfaces first, then
92 * call methods according to the class hierarchy in descending order,
93 * i.e., the most specific visitXXX() call comes last.
94 *
95 * @param v Visitor object
96 */
97 public void accept( Visitor v ) {
98 v.visitPushInstruction(this);
99 v.visitStackProducer(this);
100 v.visitTypedInstruction(this);
101 v.visitConstantPushInstruction(this);
102 v.visitBIPUSH(this);
103 }
104 }
+0
-43
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BREAKPOINT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * BREAKPOINT, JVM dependent, ignored by default
20 *
21 * @version $Id: BREAKPOINT.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public class BREAKPOINT extends Instruction {
25
26 public BREAKPOINT() {
27 super(org.apache.bcel.Constants.BREAKPOINT, (short) 1);
28 }
29
30
31 /**
32 * Call corresponding visitor method(s). The order is:
33 * Call visitor methods of implemented interfaces first, then
34 * call methods according to the class hierarchy in descending order,
35 * i.e., the most specific visitXXX() call comes last.
36 *
37 * @param v Visitor object
38 */
39 public void accept( Visitor v ) {
40 v.visitBREAKPOINT(this);
41 }
42 }
+0
-81
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BasicType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Denotes basic type such as int.
22 *
23 * @version $Id: BasicType.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public final class BasicType extends Type {
27
28 /**
29 * Constructor for basic types such as int, long, `void'
30 *
31 * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
32 * @see org.apache.bcel.Constants
33 */
34 BasicType(byte type) {
35 super(type, Constants.SHORT_TYPE_NAMES[type]);
36 if ((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) {
37 throw new ClassGenException("Invalid type: " + type);
38 }
39 }
40
41
42 public static final BasicType getType( byte type ) {
43 switch (type) {
44 case Constants.T_VOID:
45 return VOID;
46 case Constants.T_BOOLEAN:
47 return BOOLEAN;
48 case Constants.T_BYTE:
49 return BYTE;
50 case Constants.T_SHORT:
51 return SHORT;
52 case Constants.T_CHAR:
53 return CHAR;
54 case Constants.T_INT:
55 return INT;
56 case Constants.T_LONG:
57 return LONG;
58 case Constants.T_DOUBLE:
59 return DOUBLE;
60 case Constants.T_FLOAT:
61 return FLOAT;
62 default:
63 throw new ClassGenException("Invalid type: " + type);
64 }
65 }
66
67
68 /** @return a hash code value for the object.
69 */
70 public int hashCode() {
71 return type;
72 }
73
74
75 /** @return true if both type objects refer to the same type
76 */
77 public boolean equals( Object _type ) {
78 return (_type instanceof BasicType) ? ((BasicType) _type).type == this.type : false;
79 }
80 }
+0
-121
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BranchHandle.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * BranchHandle is returned by specialized InstructionList.append() whenever a
20 * BranchInstruction is appended. This is useful when the target of this
21 * instruction is not known at time of creation and must be set later
22 * via setTarget().
23 *
24 * @see InstructionHandle
25 * @see Instruction
26 * @see InstructionList
27 * @version $Id: BranchHandle.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public final class BranchHandle extends InstructionHandle {
31
32 private BranchInstruction bi; // An alias in fact, but saves lots of casts
33
34
35 private BranchHandle(BranchInstruction i) {
36 super(i);
37 bi = i;
38 }
39
40 /** Factory methods.
41 */
42 private static BranchHandle bh_list = null; // List of reusable handles
43
44
45 static final BranchHandle getBranchHandle( BranchInstruction i ) {
46 if (bh_list == null) {
47 return new BranchHandle(i);
48 }
49 BranchHandle bh = bh_list;
50 bh_list = (BranchHandle) bh.next;
51 bh.setInstruction(i);
52 return bh;
53 }
54
55
56 /** Handle adds itself to the list of resuable handles.
57 */
58 protected void addHandle() {
59 next = bh_list;
60 bh_list = this;
61 }
62
63
64 /* Override InstructionHandle methods: delegate to branch instruction.
65 * Through this overriding all access to the private i_position field should
66 * be prevented.
67 */
68 public int getPosition() {
69 return bi.position;
70 }
71
72
73 void setPosition( int pos ) {
74 i_position = bi.position = pos;
75 }
76
77
78 protected int updatePosition( int offset, int max_offset ) {
79 int x = bi.updatePosition(offset, max_offset);
80 i_position = bi.position;
81 return x;
82 }
83
84
85 /**
86 * Pass new target to instruction.
87 */
88 public void setTarget( InstructionHandle ih ) {
89 bi.setTarget(ih);
90 }
91
92
93 /**
94 * Update target of instruction.
95 */
96 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
97 bi.updateTarget(old_ih, new_ih);
98 }
99
100
101 /**
102 * @return target of instruction.
103 */
104 public InstructionHandle getTarget() {
105 return bi.getTarget();
106 }
107
108
109 /**
110 * Set new contents. Old instruction is disposed and may not be used anymore.
111 */
112 public void setInstruction( Instruction i ) {
113 super.setInstruction(i);
114 if (!(i instanceof BranchInstruction)) {
115 throw new ClassGenException("Assigning " + i
116 + " to branch handle which is not a branch instruction");
117 }
118 bi = (BranchInstruction) i;
119 }
120 }
+0
-230
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/BranchInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * Abstract super class for branching instructions like GOTO, IFEQ, etc..
24 * Branch instructions may have a variable length, namely GOTO, JSR,
25 * LOOKUPSWITCH and TABLESWITCH.
26 *
27 * @see InstructionList
28 * @version $Id: BranchInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public abstract class BranchInstruction extends Instruction implements InstructionTargeter {
32
33 protected int index; // Branch target relative to this instruction
34 protected InstructionHandle target; // Target object in instruction list
35 protected int position; // Byte code offset
36
37
38 /**
39 * Empty constructor needed for the Class.newInstance() statement in
40 * Instruction.readInstruction(). Not to be used otherwise.
41 */
42 BranchInstruction() {
43 }
44
45
46 /** Common super constructor
47 * @param opcode Instruction opcode
48 * @param target instruction to branch to
49 */
50 protected BranchInstruction(short opcode, InstructionHandle target) {
51 super(opcode, (short) 3);
52 setTarget(target);
53 }
54
55
56 /**
57 * Dump instruction as byte code to stream out.
58 * @param out Output stream
59 */
60 public void dump( DataOutputStream out ) throws IOException {
61 out.writeByte(opcode);
62 index = getTargetOffset();
63 if (Math.abs(index) >= 32767) {
64 throw new ClassGenException("Branch target offset too large for short");
65 }
66 out.writeShort(index); // May be negative, i.e., point backwards
67 }
68
69
70 /**
71 * @param _target branch target
72 * @return the offset to `target' relative to this instruction
73 */
74 protected int getTargetOffset( InstructionHandle _target ) {
75 if (_target == null) {
76 throw new ClassGenException("Target of " + super.toString(true)
77 + " is invalid null handle");
78 }
79 int t = _target.getPosition();
80 if (t < 0) {
81 throw new ClassGenException("Invalid branch target position offset for "
82 + super.toString(true) + ":" + t + ":" + _target);
83 }
84 return t - position;
85 }
86
87
88 /**
89 * @return the offset to this instruction's target
90 */
91 protected int getTargetOffset() {
92 return getTargetOffset(target);
93 }
94
95
96 /**
97 * Called by InstructionList.setPositions when setting the position for every
98 * instruction. In the presence of variable length instructions `setPositions'
99 * performs multiple passes over the instruction list to calculate the
100 * correct (byte) positions and offsets by calling this function.
101 *
102 * @param offset additional offset caused by preceding (variable length) instructions
103 * @param max_offset the maximum offset that may be caused by these instructions
104 * @return additional offset caused by possible change of this instruction's length
105 */
106 protected int updatePosition( int offset, int max_offset ) {
107 position += offset;
108 return 0;
109 }
110
111
112 /**
113 * Long output format:
114 *
115 * &lt;position in byte code&gt;
116 * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
117 * "("&lt;length of instruction&gt;")"
118 * "&lt;"&lt;target instruction&gt;"&gt;" "@"&lt;branch target offset&gt;
119 *
120 * @param verbose long/short format switch
121 * @return mnemonic for instruction
122 */
123 public String toString( boolean verbose ) {
124 String s = super.toString(verbose);
125 String t = "null";
126 if (verbose) {
127 if (target != null) {
128 if (target.getInstruction() == this) {
129 t = "<points to itself>";
130 } else if (target.getInstruction() == null) {
131 t = "<null instruction!!!?>";
132 } else {
133 t = target.getInstruction().toString(false); // Avoid circles
134 }
135 }
136 } else {
137 if (target != null) {
138 index = getTargetOffset();
139 t = "" + (index + position);
140 }
141 }
142 return s + " -> " + t;
143 }
144
145
146 /**
147 * Read needed data (e.g. index) from file. Conversion to a InstructionHandle
148 * is done in InstructionList(byte[]).
149 *
150 * @param bytes input stream
151 * @param wide wide prefix?
152 * @see InstructionList
153 */
154 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
155 length = 3;
156 index = bytes.readShort();
157 }
158
159
160 /**
161 * @return target offset in byte code
162 */
163 public final int getIndex() {
164 return index;
165 }
166
167
168 /**
169 * @return target of branch instruction
170 */
171 public InstructionHandle getTarget() {
172 return target;
173 }
174
175
176 /**
177 * Set branch target
178 * @param target branch target
179 */
180 public void setTarget( InstructionHandle target ) {
181 notifyTarget(this.target, target, this);
182 this.target = target;
183 }
184
185
186 /**
187 * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen
188 */
189 static final void notifyTarget( InstructionHandle old_ih, InstructionHandle new_ih,
190 InstructionTargeter t ) {
191 if (old_ih != null) {
192 old_ih.removeTargeter(t);
193 }
194 if (new_ih != null) {
195 new_ih.addTargeter(t);
196 }
197 }
198
199
200 /**
201 * @param old_ih old target
202 * @param new_ih new target
203 */
204 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
205 if (target == old_ih) {
206 setTarget(new_ih);
207 } else {
208 throw new ClassGenException("Not targeting " + old_ih + ", but " + target);
209 }
210 }
211
212
213 /**
214 * @return true, if ih is target of this instruction
215 */
216 public boolean containsTarget( InstructionHandle ih ) {
217 return (target == ih);
218 }
219
220
221 /**
222 * Inform target that it's not targeted anymore.
223 */
224 void dispose() {
225 setTarget(null);
226 index = -1;
227 position = -1;
228 }
229 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * CALOAD - Load char from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
21 *
22 * @version $Id: CALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class CALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load char from array
28 */
29 public CALOAD() {
30 super(org.apache.bcel.Constants.CALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitCALOAD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * CASTORE - Store into char array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: CASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class CASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store char into array
28 */
29 public CASTORE() {
30 super(org.apache.bcel.Constants.CASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitCASTORE(this);
48 }
49 }
+0
-84
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CHECKCAST.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.ExceptionConstants;
19
20 /**
21 * CHECKCAST - Check whether object is of given type
22 * <PRE>Stack: ..., objectref -&gt; ..., objectref</PRE>
23 *
24 * @version $Id: CHECKCAST.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class CHECKCAST extends CPInstruction implements LoadClass, ExceptionThrower, StackProducer,
28 StackConsumer {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 CHECKCAST() {
35 }
36
37
38 /** Check whether object is of given type
39 * @param index index to class in constant pool
40 */
41 public CHECKCAST(int index) {
42 super(org.apache.bcel.Constants.CHECKCAST, index);
43 }
44
45
46 /** @return exceptions this instruction may cause
47 */
48 public Class[] getExceptions() {
49 Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
50 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, cs, 0,
51 ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
52 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.CLASS_CAST_EXCEPTION;
53 return cs;
54 }
55
56
57 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
58 Type t = getType(cpg);
59 if (t instanceof ArrayType) {
60 t = ((ArrayType) t).getBasicType();
61 }
62 return (t instanceof ObjectType) ? (ObjectType) t : null;
63 }
64
65
66 /**
67 * Call corresponding visitor method(s). The order is:
68 * Call visitor methods of implemented interfaces first, then
69 * call methods according to the class hierarchy in descending order,
70 * i.e., the most specific visitXXX() call comes last.
71 *
72 * @param v Visitor object
73 */
74 public void accept( Visitor v ) {
75 v.visitLoadClass(this);
76 v.visitExceptionThrower(this);
77 v.visitStackProducer(this);
78 v.visitStackConsumer(this);
79 v.visitTypedInstruction(this);
80 v.visitCPInstruction(this);
81 v.visitCHECKCAST(this);
82 }
83 }
+0
-138
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CPInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.classfile.Constant;
21 import org.apache.bcel.classfile.ConstantClass;
22 import org.apache.bcel.classfile.ConstantPool;
23 import org.apache.bcel.util.ByteSequence;
24
25 /**
26 * Abstract super class for instructions that use an index into the
27 * constant pool such as LDC, INVOKEVIRTUAL, etc.
28 *
29 * @see ConstantPoolGen
30 * @see LDC
31 * @see INVOKEVIRTUAL
32 *
33 * @version $Id: CPInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
34 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35 */
36 public abstract class CPInstruction extends Instruction implements TypedInstruction,
37 IndexedInstruction {
38
39 protected int index; // index to constant pool
40
41
42 /**
43 * Empty constructor needed for the Class.newInstance() statement in
44 * Instruction.readInstruction(). Not to be used otherwise.
45 */
46 CPInstruction() {
47 }
48
49
50 /**
51 * @param index to constant pool
52 */
53 protected CPInstruction(short opcode, int index) {
54 super(opcode, (short) 3);
55 setIndex(index);
56 }
57
58
59 /**
60 * Dump instruction as byte code to stream out.
61 * @param out Output stream
62 */
63 public void dump( DataOutputStream out ) throws IOException {
64 out.writeByte(opcode);
65 out.writeShort(index);
66 }
67
68
69 /**
70 * Long output format:
71 *
72 * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
73 * "("&lt;length of instruction&gt;")" "&lt;"&lt; constant pool index&gt;"&gt;"
74 *
75 * @param verbose long/short format switch
76 * @return mnemonic for instruction
77 */
78 public String toString( boolean verbose ) {
79 return super.toString(verbose) + " " + index;
80 }
81
82
83 /**
84 * @return mnemonic for instruction with symbolic references resolved
85 */
86 public String toString( ConstantPool cp ) {
87 Constant c = cp.getConstant(index);
88 String str = cp.constantToString(c);
89 if (c instanceof ConstantClass) {
90 str = str.replace('.', '/');
91 }
92 return org.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str;
93 }
94
95
96 /**
97 * Read needed data (i.e., index) from file.
98 * @param bytes input stream
99 * @param wide wide prefix?
100 */
101 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
102 setIndex(bytes.readUnsignedShort());
103 length = 3;
104 }
105
106
107 /**
108 * @return index in constant pool referred by this instruction.
109 */
110 public final int getIndex() {
111 return index;
112 }
113
114
115 /**
116 * Set the index to constant pool.
117 * @param index in constant pool.
118 */
119 public void setIndex( int index ) {
120 if (index < 0) {
121 throw new ClassGenException("Negative index value: " + index);
122 }
123 this.index = index;
124 }
125
126
127 /** @return type related with this instruction.
128 */
129 public Type getType( ConstantPoolGen cpg ) {
130 ConstantPool cp = cpg.getConstantPool();
131 String name = cp.getConstantString(index, org.apache.bcel.Constants.CONSTANT_Class);
132 if (!name.startsWith("[")) {
133 name = "L" + name + ";";
134 }
135 return Type.getType(name);
136 }
137 }
+0
-541
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ClassGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import org.apache.bcel.Constants;
22 import org.apache.bcel.classfile.AccessFlags;
23 import org.apache.bcel.classfile.Attribute;
24 import org.apache.bcel.classfile.ConstantPool;
25 import org.apache.bcel.classfile.Field;
26 import org.apache.bcel.classfile.JavaClass;
27 import org.apache.bcel.classfile.Method;
28 import org.apache.bcel.classfile.SourceFile;
29 import org.apache.bcel.util.BCELComparator;
30
31 /**
32 * Template class for building up a java class. May be initialized with an
33 * existing java class (file).
34 *
35 * @see JavaClass
36 * @version $Id: ClassGen.java 386056 2006-03-15 11:31:56Z tcurdt $
37 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
38 */
39 public class ClassGen extends AccessFlags implements Cloneable {
40
41 /* Corresponds to the fields found in a JavaClass object.
42 */
43 private String class_name, super_class_name, file_name;
44 private int class_name_index = -1, superclass_name_index = -1;
45 private int major = Constants.MAJOR_1_1, minor = Constants.MINOR_1_1;
46 private ConstantPoolGen cp; // Template for building up constant pool
47 // ArrayLists instead of arrays to gather fields, methods, etc.
48 private List field_vec = new ArrayList();
49 private List method_vec = new ArrayList();
50 private List attribute_vec = new ArrayList();
51 private List interface_vec = new ArrayList();
52 private static BCELComparator _cmp = new BCELComparator() {
53
54 public boolean equals( Object o1, Object o2 ) {
55 ClassGen THIS = (ClassGen) o1;
56 ClassGen THAT = (ClassGen) o2;
57 return THIS.getClassName().equals(THAT.getClassName());
58 }
59
60
61 public int hashCode( Object o ) {
62 ClassGen THIS = (ClassGen) o;
63 return THIS.getClassName().hashCode();
64 }
65 };
66
67
68 /** Convenience constructor to set up some important values initially.
69 *
70 * @param class_name fully qualified class name
71 * @param super_class_name fully qualified superclass name
72 * @param file_name source file name
73 * @param access_flags access qualifiers
74 * @param interfaces implemented interfaces
75 * @param cp constant pool to use
76 */
77 public ClassGen(String class_name, String super_class_name, String file_name, int access_flags,
78 String[] interfaces, ConstantPoolGen cp) {
79 this.class_name = class_name;
80 this.super_class_name = super_class_name;
81 this.file_name = file_name;
82 this.access_flags = access_flags;
83 this.cp = cp;
84 // Put everything needed by default into the constant pool and the vectors
85 if (file_name != null) {
86 addAttribute(new SourceFile(cp.addUtf8("SourceFile"), 2, cp.addUtf8(file_name), cp
87 .getConstantPool()));
88 }
89 class_name_index = cp.addClass(class_name);
90 superclass_name_index = cp.addClass(super_class_name);
91 if (interfaces != null) {
92 for (int i = 0; i < interfaces.length; i++) {
93 addInterface(interfaces[i]);
94 }
95 }
96 }
97
98
99 /** Convenience constructor to set up some important values initially.
100 *
101 * @param class_name fully qualified class name
102 * @param super_class_name fully qualified superclass name
103 * @param file_name source file name
104 * @param access_flags access qualifiers
105 * @param interfaces implemented interfaces
106 */
107 public ClassGen(String class_name, String super_class_name, String file_name, int access_flags,
108 String[] interfaces) {
109 this(class_name, super_class_name, file_name, access_flags, interfaces,
110 new ConstantPoolGen());
111 }
112
113
114 /**
115 * Initialize with existing class.
116 * @param clazz JavaClass object (e.g. read from file)
117 */
118 public ClassGen(JavaClass clazz) {
119 class_name_index = clazz.getClassNameIndex();
120 superclass_name_index = clazz.getSuperclassNameIndex();
121 class_name = clazz.getClassName();
122 super_class_name = clazz.getSuperclassName();
123 file_name = clazz.getSourceFileName();
124 access_flags = clazz.getAccessFlags();
125 cp = new ConstantPoolGen(clazz.getConstantPool());
126 major = clazz.getMajor();
127 minor = clazz.getMinor();
128 Attribute[] attributes = clazz.getAttributes();
129 Method[] methods = clazz.getMethods();
130 Field[] fields = clazz.getFields();
131 String[] interfaces = clazz.getInterfaceNames();
132 for (int i = 0; i < interfaces.length; i++) {
133 addInterface(interfaces[i]);
134 }
135 for (int i = 0; i < attributes.length; i++) {
136 addAttribute(attributes[i]);
137 }
138 for (int i = 0; i < methods.length; i++) {
139 addMethod(methods[i]);
140 }
141 for (int i = 0; i < fields.length; i++) {
142 addField(fields[i]);
143 }
144 }
145
146
147 /**
148 * @return the (finally) built up Java class object.
149 */
150 public JavaClass getJavaClass() {
151 int[] interfaces = getInterfaces();
152 Field[] fields = getFields();
153 Method[] methods = getMethods();
154 Attribute[] attributes = getAttributes();
155 // Must be last since the above calls may still add something to it
156 ConstantPool _cp = this.cp.getFinalConstantPool();
157 return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
158 access_flags, _cp, interfaces, fields, methods, attributes);
159 }
160
161
162 /**
163 * Add an interface to this class, i.e., this class has to implement it.
164 * @param name interface to implement (fully qualified class name)
165 */
166 public void addInterface( String name ) {
167 interface_vec.add(name);
168 }
169
170
171 /**
172 * Remove an interface from this class.
173 * @param name interface to remove (fully qualified name)
174 */
175 public void removeInterface( String name ) {
176 interface_vec.remove(name);
177 }
178
179
180 /**
181 * @return major version number of class file
182 */
183 public int getMajor() {
184 return major;
185 }
186
187
188 /** Set major version number of class file, default value is 45 (JDK 1.1)
189 * @param major major version number
190 */
191 public void setMajor( int major ) {
192 this.major = major;
193 }
194
195
196 /** Set minor version number of class file, default value is 3 (JDK 1.1)
197 * @param minor minor version number
198 */
199 public void setMinor( int minor ) {
200 this.minor = minor;
201 }
202
203
204 /**
205 * @return minor version number of class file
206 */
207 public int getMinor() {
208 return minor;
209 }
210
211
212 /**
213 * Add an attribute to this class.
214 * @param a attribute to add
215 */
216 public void addAttribute( Attribute a ) {
217 attribute_vec.add(a);
218 }
219
220
221 /**
222 * Add a method to this class.
223 * @param m method to add
224 */
225 public void addMethod( Method m ) {
226 method_vec.add(m);
227 }
228
229
230 /**
231 * Convenience method.
232 *
233 * Add an empty constructor to this class that does nothing but calling super().
234 * @param access_flags rights for constructor
235 */
236 public void addEmptyConstructor( int access_flags ) {
237 InstructionList il = new InstructionList();
238 il.append(InstructionConstants.THIS); // Push `this'
239 il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name, "<init>", "()V")));
240 il.append(InstructionConstants.RETURN);
241 MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, "<init>",
242 class_name, il, cp);
243 mg.setMaxStack(1);
244 addMethod(mg.getMethod());
245 }
246
247
248 /**
249 * Add a field to this class.
250 * @param f field to add
251 */
252 public void addField( Field f ) {
253 field_vec.add(f);
254 }
255
256
257 public boolean containsField( Field f ) {
258 return field_vec.contains(f);
259 }
260
261
262 /** @return field object with given name, or null
263 */
264 public Field containsField( String name ) {
265 for (Iterator e = field_vec.iterator(); e.hasNext();) {
266 Field f = (Field) e.next();
267 if (f.getName().equals(name)) {
268 return f;
269 }
270 }
271 return null;
272 }
273
274
275 /** @return method object with given name and signature, or null
276 */
277 public Method containsMethod( String name, String signature ) {
278 for (Iterator e = method_vec.iterator(); e.hasNext();) {
279 Method m = (Method) e.next();
280 if (m.getName().equals(name) && m.getSignature().equals(signature)) {
281 return m;
282 }
283 }
284 return null;
285 }
286
287
288 /**
289 * Remove an attribute from this class.
290 * @param a attribute to remove
291 */
292 public void removeAttribute( Attribute a ) {
293 attribute_vec.remove(a);
294 }
295
296
297 /**
298 * Remove a method from this class.
299 * @param m method to remove
300 */
301 public void removeMethod( Method m ) {
302 method_vec.remove(m);
303 }
304
305
306 /** Replace given method with new one. If the old one does not exist
307 * add the new_ method to the class anyway.
308 */
309 public void replaceMethod( Method old, Method new_ ) {
310 if (new_ == null) {
311 throw new ClassGenException("Replacement method must not be null");
312 }
313 int i = method_vec.indexOf(old);
314 if (i < 0) {
315 method_vec.add(new_);
316 } else {
317 method_vec.set(i, new_);
318 }
319 }
320
321
322 /** Replace given field with new one. If the old one does not exist
323 * add the new_ field to the class anyway.
324 */
325 public void replaceField( Field old, Field new_ ) {
326 if (new_ == null) {
327 throw new ClassGenException("Replacement method must not be null");
328 }
329 int i = field_vec.indexOf(old);
330 if (i < 0) {
331 field_vec.add(new_);
332 } else {
333 field_vec.set(i, new_);
334 }
335 }
336
337
338 /**
339 * Remove a field to this class.
340 * @param f field to remove
341 */
342 public void removeField( Field f ) {
343 field_vec.remove(f);
344 }
345
346
347 public String getClassName() {
348 return class_name;
349 }
350
351
352 public String getSuperclassName() {
353 return super_class_name;
354 }
355
356
357 public String getFileName() {
358 return file_name;
359 }
360
361
362 public void setClassName( String name ) {
363 class_name = name.replace('/', '.');
364 class_name_index = cp.addClass(name);
365 }
366
367
368 public void setSuperclassName( String name ) {
369 super_class_name = name.replace('/', '.');
370 superclass_name_index = cp.addClass(name);
371 }
372
373
374 public Method[] getMethods() {
375 return (Method[]) method_vec.toArray(new Method[method_vec.size()]);
376 }
377
378
379 public void setMethods( Method[] methods ) {
380 method_vec.clear();
381 for (int m = 0; m < methods.length; m++) {
382 addMethod(methods[m]);
383 }
384 }
385
386
387 public void setMethodAt( Method method, int pos ) {
388 method_vec.set(pos, method);
389 }
390
391
392 public Method getMethodAt( int pos ) {
393 return (Method) method_vec.get(pos);
394 }
395
396
397 public String[] getInterfaceNames() {
398 int size = interface_vec.size();
399 String[] interfaces = new String[size];
400 interface_vec.toArray(interfaces);
401 return interfaces;
402 }
403
404
405 public int[] getInterfaces() {
406 int size = interface_vec.size();
407 int[] interfaces = new int[size];
408 for (int i = 0; i < size; i++) {
409 interfaces[i] = cp.addClass((String) interface_vec.get(i));
410 }
411 return interfaces;
412 }
413
414
415 public Field[] getFields() {
416 return (Field[]) field_vec.toArray(new Field[field_vec.size()]);
417 }
418
419
420 public Attribute[] getAttributes() {
421 return (Attribute[]) attribute_vec.toArray(new Attribute[attribute_vec.size()]);
422 }
423
424
425 public ConstantPoolGen getConstantPool() {
426 return cp;
427 }
428
429
430 public void setConstantPool( ConstantPoolGen constant_pool ) {
431 cp = constant_pool;
432 }
433
434
435 public void setClassNameIndex( int class_name_index ) {
436 this.class_name_index = class_name_index;
437 class_name = cp.getConstantPool().getConstantString(class_name_index,
438 Constants.CONSTANT_Class).replace('/', '.');
439 }
440
441
442 public void setSuperclassNameIndex( int superclass_name_index ) {
443 this.superclass_name_index = superclass_name_index;
444 super_class_name = cp.getConstantPool().getConstantString(superclass_name_index,
445 Constants.CONSTANT_Class).replace('/', '.');
446 }
447
448
449 public int getSuperclassNameIndex() {
450 return superclass_name_index;
451 }
452
453
454 public int getClassNameIndex() {
455 return class_name_index;
456 }
457
458 private ArrayList observers;
459
460
461 /** Add observer for this object.
462 */
463 public void addObserver( ClassObserver o ) {
464 if (observers == null) {
465 observers = new ArrayList();
466 }
467 observers.add(o);
468 }
469
470
471 /** Remove observer for this object.
472 */
473 public void removeObserver( ClassObserver o ) {
474 if (observers != null) {
475 observers.remove(o);
476 }
477 }
478
479
480 /** Call notify() method on all observers. This method is not called
481 * automatically whenever the state has changed, but has to be
482 * called by the user after he has finished editing the object.
483 */
484 public void update() {
485 if (observers != null) {
486 for (Iterator e = observers.iterator(); e.hasNext();) {
487 ((ClassObserver) e.next()).notify(this);
488 }
489 }
490 }
491
492
493 public Object clone() {
494 try {
495 return super.clone();
496 } catch (CloneNotSupportedException e) {
497 System.err.println(e);
498 return null;
499 }
500 }
501
502
503 /**
504 * @return Comparison strategy object
505 */
506 public static BCELComparator getComparator() {
507 return _cmp;
508 }
509
510
511 /**
512 * @param comparator Comparison strategy object
513 */
514 public static void setComparator( BCELComparator comparator ) {
515 _cmp = comparator;
516 }
517
518
519 /**
520 * Return value as defined by given BCELComparator strategy.
521 * By default two ClassGen objects are said to be equal when
522 * their class names are equal.
523 *
524 * @see java.lang.Object#equals(java.lang.Object)
525 */
526 public boolean equals( Object obj ) {
527 return _cmp.equals(this, obj);
528 }
529
530
531 /**
532 * Return value as defined by given BCELComparator strategy.
533 * By default return the hashcode of the class name.
534 *
535 * @see java.lang.Object#hashCode()
536 */
537 public int hashCode() {
538 return _cmp.hashCode(this);
539 }
540 }
+0
-36
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ClassGenException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Thrown on internal errors. Extends RuntimeException so it hasn't to be declared
20 * in the throws clause every time.
21 *
22 * @version $Id: ClassGenException.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ClassGenException extends RuntimeException {
26
27 public ClassGenException() {
28 super();
29 }
30
31
32 public ClassGenException(String s) {
33 super(s);
34 }
35 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ClassObserver.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Implement this interface if you're interested in changes to a ClassGen object
20 * and register yourself with addObserver().
21 *
22 * @version $Id: ClassObserver.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface ClassObserver {
26
27 public void notify( ClassGen clazz );
28 }
+0
-184
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CodeExceptionGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.classfile.CodeException;
19
20 /**
21 * This class represents an exception handler, i.e., specifies the region where
22 * a handler is active and an instruction where the actual handling is done.
23 * pool as parameters. Opposed to the JVM specification the end of the handled
24 * region is set to be inclusive, i.e. all instructions between start and end
25 * are protected including the start and end instructions (handles) themselves.
26 * The end of the region is automatically mapped to be exclusive when calling
27 * getCodeException(), i.e., there is no difference semantically.
28 *
29 * @version $Id: CodeExceptionGen.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see MethodGen
32 * @see CodeException
33 * @see InstructionHandle
34 */
35 public final class CodeExceptionGen implements InstructionTargeter, Cloneable, java.io.Serializable {
36
37 private InstructionHandle start_pc;
38 private InstructionHandle end_pc;
39 private InstructionHandle handler_pc;
40 private ObjectType catch_type;
41
42
43 /**
44 * Add an exception handler, i.e., specify region where a handler is active and an
45 * instruction where the actual handling is done.
46 *
47 * @param start_pc Start of handled region (inclusive)
48 * @param end_pc End of handled region (inclusive)
49 * @param handler_pc Where handling is done
50 * @param catch_type which exception is handled, null for ANY
51 */
52 public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc,
53 InstructionHandle handler_pc, ObjectType catch_type) {
54 setStartPC(start_pc);
55 setEndPC(end_pc);
56 setHandlerPC(handler_pc);
57 this.catch_type = catch_type;
58 }
59
60
61 /**
62 * Get CodeException object.<BR>
63 *
64 * This relies on that the instruction list has already been dumped
65 * to byte code or or that the `setPositions' methods has been
66 * called for the instruction list.
67 *
68 * @param cp constant pool
69 */
70 public CodeException getCodeException( ConstantPoolGen cp ) {
71 return new CodeException(start_pc.getPosition(), end_pc.getPosition()
72 + end_pc.getInstruction().getLength(), handler_pc.getPosition(),
73 (catch_type == null) ? 0 : cp.addClass(catch_type));
74 }
75
76
77 /* Set start of handler
78 * @param start_pc Start of handled region (inclusive)
79 */
80 public void setStartPC( InstructionHandle start_pc ) {
81 BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
82 this.start_pc = start_pc;
83 }
84
85
86 /* Set end of handler
87 * @param end_pc End of handled region (inclusive)
88 */
89 public void setEndPC( InstructionHandle end_pc ) {
90 BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
91 this.end_pc = end_pc;
92 }
93
94
95 /* Set handler code
96 * @param handler_pc Start of handler
97 */
98 public void setHandlerPC( InstructionHandle handler_pc ) {
99 BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this);
100 this.handler_pc = handler_pc;
101 }
102
103
104 /**
105 * @param old_ih old target, either start or end
106 * @param new_ih new target
107 */
108 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
109 boolean targeted = false;
110 if (start_pc == old_ih) {
111 targeted = true;
112 setStartPC(new_ih);
113 }
114 if (end_pc == old_ih) {
115 targeted = true;
116 setEndPC(new_ih);
117 }
118 if (handler_pc == old_ih) {
119 targeted = true;
120 setHandlerPC(new_ih);
121 }
122 if (!targeted) {
123 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start_pc + ", "
124 + end_pc + ", " + handler_pc + "}");
125 }
126 }
127
128
129 /**
130 * @return true, if ih is target of this handler
131 */
132 public boolean containsTarget( InstructionHandle ih ) {
133 return (start_pc == ih) || (end_pc == ih) || (handler_pc == ih);
134 }
135
136
137 /** Sets the type of the Exception to catch. Set 'null' for ANY. */
138 public void setCatchType( ObjectType catch_type ) {
139 this.catch_type = catch_type;
140 }
141
142
143 /** Gets the type of the Exception to catch, 'null' for ANY. */
144 public ObjectType getCatchType() {
145 return catch_type;
146 }
147
148
149 /** @return start of handled region (inclusive)
150 */
151 public InstructionHandle getStartPC() {
152 return start_pc;
153 }
154
155
156 /** @return end of handled region (inclusive)
157 */
158 public InstructionHandle getEndPC() {
159 return end_pc;
160 }
161
162
163 /** @return start of handler
164 */
165 public InstructionHandle getHandlerPC() {
166 return handler_pc;
167 }
168
169
170 public String toString() {
171 return "CodeExceptionGen(" + start_pc + ", " + end_pc + ", " + handler_pc + ")";
172 }
173
174
175 public Object clone() {
176 try {
177 return super.clone();
178 } catch (CloneNotSupportedException e) {
179 System.err.println(e);
180 return null;
181 }
182 }
183 }
+0
-38
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/CompoundInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Wrapper class for `compound' operations, virtual instructions that
20 * don't exist as byte code, but give a useful meaning. For example,
21 * the (virtual) PUSH instruction takes an arbitray argument and produces the
22 * appropiate code at dump time (ICONST, LDC, BIPUSH, ...). Also you can use the
23 * SWITCH instruction as a useful template for either LOOKUPSWITCH or
24 * TABLESWITCH.
25 *
26 * The interface provides the possibilty for the user to write
27 * `templates' or `macros' for such reuseable code patterns.
28 *
29 * @version $Id: CompoundInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see PUSH
32 * @see SWITCH
33 */
34 public interface CompoundInstruction {
35
36 public InstructionList getInstructionList();
37 }
+0
-764
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ConstantPoolGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.classfile.Constant;
22 import org.apache.bcel.classfile.ConstantCP;
23 import org.apache.bcel.classfile.ConstantClass;
24 import org.apache.bcel.classfile.ConstantDouble;
25 import org.apache.bcel.classfile.ConstantFieldref;
26 import org.apache.bcel.classfile.ConstantFloat;
27 import org.apache.bcel.classfile.ConstantInteger;
28 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
29 import org.apache.bcel.classfile.ConstantLong;
30 import org.apache.bcel.classfile.ConstantMethodref;
31 import org.apache.bcel.classfile.ConstantNameAndType;
32 import org.apache.bcel.classfile.ConstantPool;
33 import org.apache.bcel.classfile.ConstantString;
34 import org.apache.bcel.classfile.ConstantUtf8;
35
36 /**
37 * This class is used to build up a constant pool. The user adds
38 * constants via `addXXX' methods, `addString', `addClass',
39 * etc.. These methods return an index into the constant
40 * pool. Finally, `getFinalConstantPool()' returns the constant pool
41 * built up. Intermediate versions of the constant pool can be
42 * obtained with `getConstantPool()'. A constant pool has capacity for
43 * Constants.MAX_SHORT entries. Note that the first (0) is used by the
44 * JVM and that Double and Long constants need two slots.
45 *
46 * @version $Id: ConstantPoolGen.java 386056 2006-03-15 11:31:56Z tcurdt $
47 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
48 * @see Constant
49 */
50 public class ConstantPoolGen implements java.io.Serializable {
51
52 protected int size = 1024; // Inital size, sufficient in most cases
53 protected Constant[] constants = new Constant[size];
54 protected int index = 1; // First entry (0) used by JVM
55 private static final String METHODREF_DELIM = ":";
56 private static final String IMETHODREF_DELIM = "#";
57 private static final String FIELDREF_DELIM = "&";
58 private static final String NAT_DELIM = "%";
59
60 private static class Index implements java.io.Serializable {
61
62 int index;
63
64
65 Index(int i) {
66 index = i;
67 }
68 }
69
70
71 /**
72 * Initialize with given array of constants.
73 *
74 * @param cs array of given constants, new ones will be appended
75 */
76 public ConstantPoolGen(Constant[] cs) {
77 if (cs.length > size) {
78 size = cs.length;
79 constants = new Constant[size];
80 }
81 System.arraycopy(cs, 0, constants, 0, cs.length);
82 if (cs.length > 0) {
83 index = cs.length;
84 }
85 for (int i = 1; i < index; i++) {
86 Constant c = constants[i];
87 if (c instanceof ConstantString) {
88 ConstantString s = (ConstantString) c;
89 ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
90 String key = u8.getBytes();
91 if (!string_table.containsKey(key)) {
92 string_table.put(key, new Index(i));
93 }
94 } else if (c instanceof ConstantClass) {
95 ConstantClass s = (ConstantClass) c;
96 ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
97 String key = u8.getBytes();
98 if (!class_table.containsKey(key)) {
99 class_table.put(key, new Index(i));
100 }
101 } else if (c instanceof ConstantNameAndType) {
102 ConstantNameAndType n = (ConstantNameAndType) c;
103 ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
104 ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
105 String key = u8.getBytes() + NAT_DELIM + u8_2.getBytes();
106 if (!n_a_t_table.containsKey(key)) {
107 n_a_t_table.put(key, new Index(i));
108 }
109 } else if (c instanceof ConstantUtf8) {
110 ConstantUtf8 u = (ConstantUtf8) c;
111 String key = u.getBytes();
112 if (!utf8_table.containsKey(key)) {
113 utf8_table.put(key, new Index(i));
114 }
115 } else if (c instanceof ConstantCP) {
116 ConstantCP m = (ConstantCP) c;
117 ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
118 ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
119 ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
120 String class_name = u8.getBytes().replace('/', '.');
121 u8 = (ConstantUtf8) constants[n.getNameIndex()];
122 String method_name = u8.getBytes();
123 u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
124 String signature = u8.getBytes();
125 String delim = METHODREF_DELIM;
126 if (c instanceof ConstantInterfaceMethodref) {
127 delim = IMETHODREF_DELIM;
128 } else if (c instanceof ConstantFieldref) {
129 delim = FIELDREF_DELIM;
130 }
131 String key = class_name + delim + method_name + delim + signature;
132 if (!cp_table.containsKey(key)) {
133 cp_table.put(key, new Index(i));
134 }
135 }
136 }
137 }
138
139
140 /**
141 * Initialize with given constant pool.
142 */
143 public ConstantPoolGen(ConstantPool cp) {
144 this(cp.getConstantPool());
145 }
146
147
148 /**
149 * Create empty constant pool.
150 */
151 public ConstantPoolGen() {
152 }
153
154
155 /** Resize internal array of constants.
156 */
157 protected void adjustSize() {
158 if (index + 3 >= size) {
159 Constant[] cs = constants;
160 size *= 2;
161 constants = new Constant[size];
162 System.arraycopy(cs, 0, constants, 0, index);
163 }
164 }
165
166 private Map string_table = new HashMap();
167
168
169 /**
170 * Look for ConstantString in ConstantPool containing String `str'.
171 *
172 * @param str String to search for
173 * @return index on success, -1 otherwise
174 */
175 public int lookupString( String str ) {
176 Index index = (Index) string_table.get(str);
177 return (index != null) ? index.index : -1;
178 }
179
180
181 /**
182 * Add a new String constant to the ConstantPool, if it is not already in there.
183 *
184 * @param str String to add
185 * @return index of entry
186 */
187 public int addString( String str ) {
188 int ret;
189 if ((ret = lookupString(str)) != -1) {
190 return ret; // Already in CP
191 }
192 int utf8 = addUtf8(str);
193 adjustSize();
194 ConstantString s = new ConstantString(utf8);
195 ret = index;
196 constants[index++] = s;
197 if (!string_table.containsKey(str)) {
198 string_table.put(str, new Index(ret));
199 }
200 return ret;
201 }
202
203 private Map class_table = new HashMap();
204
205
206 /**
207 * Look for ConstantClass in ConstantPool named `str'.
208 *
209 * @param str String to search for
210 * @return index on success, -1 otherwise
211 */
212 public int lookupClass( String str ) {
213 Index index = (Index) class_table.get(str.replace('.', '/'));
214 return (index != null) ? index.index : -1;
215 }
216
217
218 private int addClass_( String clazz ) {
219 int ret;
220 if ((ret = lookupClass(clazz)) != -1) {
221 return ret; // Already in CP
222 }
223 adjustSize();
224 ConstantClass c = new ConstantClass(addUtf8(clazz));
225 ret = index;
226 constants[index++] = c;
227 if (!class_table.containsKey(clazz)) {
228 class_table.put(clazz, new Index(ret));
229 }
230 return ret;
231 }
232
233
234 /**
235 * Add a new Class reference to the ConstantPool, if it is not already in there.
236 *
237 * @param str Class to add
238 * @return index of entry
239 */
240 public int addClass( String str ) {
241 return addClass_(str.replace('.', '/'));
242 }
243
244
245 /**
246 * Add a new Class reference to the ConstantPool for a given type.
247 *
248 * @param type Class to add
249 * @return index of entry
250 */
251 public int addClass( ObjectType type ) {
252 return addClass(type.getClassName());
253 }
254
255
256 /**
257 * Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
258 * instruction, e.g. to the ConstantPool.
259 *
260 * @param type type of array class
261 * @return index of entry
262 */
263 public int addArrayClass( ArrayType type ) {
264 return addClass_(type.getSignature());
265 }
266
267
268 /**
269 * Look for ConstantInteger in ConstantPool.
270 *
271 * @param n integer number to look for
272 * @return index on success, -1 otherwise
273 */
274 public int lookupInteger( int n ) {
275 for (int i = 1; i < index; i++) {
276 if (constants[i] instanceof ConstantInteger) {
277 ConstantInteger c = (ConstantInteger) constants[i];
278 if (c.getBytes() == n) {
279 return i;
280 }
281 }
282 }
283 return -1;
284 }
285
286
287 /**
288 * Add a new Integer constant to the ConstantPool, if it is not already in there.
289 *
290 * @param n integer number to add
291 * @return index of entry
292 */
293 public int addInteger( int n ) {
294 int ret;
295 if ((ret = lookupInteger(n)) != -1) {
296 return ret; // Already in CP
297 }
298 adjustSize();
299 ret = index;
300 constants[index++] = new ConstantInteger(n);
301 return ret;
302 }
303
304
305 /**
306 * Look for ConstantFloat in ConstantPool.
307 *
308 * @param n Float number to look for
309 * @return index on success, -1 otherwise
310 */
311 public int lookupFloat( float n ) {
312 int bits = Float.floatToIntBits(n);
313 for (int i = 1; i < index; i++) {
314 if (constants[i] instanceof ConstantFloat) {
315 ConstantFloat c = (ConstantFloat) constants[i];
316 if (Float.floatToIntBits(c.getBytes()) == bits) {
317 return i;
318 }
319 }
320 }
321 return -1;
322 }
323
324
325 /**
326 * Add a new Float constant to the ConstantPool, if it is not already in there.
327 *
328 * @param n Float number to add
329 * @return index of entry
330 */
331 public int addFloat( float n ) {
332 int ret;
333 if ((ret = lookupFloat(n)) != -1) {
334 return ret; // Already in CP
335 }
336 adjustSize();
337 ret = index;
338 constants[index++] = new ConstantFloat(n);
339 return ret;
340 }
341
342 private Map utf8_table = new HashMap();
343
344
345 /**
346 * Look for ConstantUtf8 in ConstantPool.
347 *
348 * @param n Utf8 string to look for
349 * @return index on success, -1 otherwise
350 */
351 public int lookupUtf8( String n ) {
352 Index index = (Index) utf8_table.get(n);
353 return (index != null) ? index.index : -1;
354 }
355
356
357 /**
358 * Add a new Utf8 constant to the ConstantPool, if it is not already in there.
359 *
360 * @param n Utf8 string to add
361 * @return index of entry
362 */
363 public int addUtf8( String n ) {
364 int ret;
365 if ((ret = lookupUtf8(n)) != -1) {
366 return ret; // Already in CP
367 }
368 adjustSize();
369 ret = index;
370 constants[index++] = new ConstantUtf8(n);
371 if (!utf8_table.containsKey(n)) {
372 utf8_table.put(n, new Index(ret));
373 }
374 return ret;
375 }
376
377
378 /**
379 * Look for ConstantLong in ConstantPool.
380 *
381 * @param n Long number to look for
382 * @return index on success, -1 otherwise
383 */
384 public int lookupLong( long n ) {
385 for (int i = 1; i < index; i++) {
386 if (constants[i] instanceof ConstantLong) {
387 ConstantLong c = (ConstantLong) constants[i];
388 if (c.getBytes() == n) {
389 return i;
390 }
391 }
392 }
393 return -1;
394 }
395
396
397 /**
398 * Add a new long constant to the ConstantPool, if it is not already in there.
399 *
400 * @param n Long number to add
401 * @return index of entry
402 */
403 public int addLong( long n ) {
404 int ret;
405 if ((ret = lookupLong(n)) != -1) {
406 return ret; // Already in CP
407 }
408 adjustSize();
409 ret = index;
410 constants[index] = new ConstantLong(n);
411 index += 2; // Wastes one entry according to spec
412 return ret;
413 }
414
415
416 /**
417 * Look for ConstantDouble in ConstantPool.
418 *
419 * @param n Double number to look for
420 * @return index on success, -1 otherwise
421 */
422 public int lookupDouble( double n ) {
423 long bits = Double.doubleToLongBits(n);
424 for (int i = 1; i < index; i++) {
425 if (constants[i] instanceof ConstantDouble) {
426 ConstantDouble c = (ConstantDouble) constants[i];
427 if (Double.doubleToLongBits(c.getBytes()) == bits) {
428 return i;
429 }
430 }
431 }
432 return -1;
433 }
434
435
436 /**
437 * Add a new double constant to the ConstantPool, if it is not already in there.
438 *
439 * @param n Double number to add
440 * @return index of entry
441 */
442 public int addDouble( double n ) {
443 int ret;
444 if ((ret = lookupDouble(n)) != -1) {
445 return ret; // Already in CP
446 }
447 adjustSize();
448 ret = index;
449 constants[index] = new ConstantDouble(n);
450 index += 2; // Wastes one entry according to spec
451 return ret;
452 }
453
454 private Map n_a_t_table = new HashMap();
455
456
457 /**
458 * Look for ConstantNameAndType in ConstantPool.
459 *
460 * @param name of variable/method
461 * @param signature of variable/method
462 * @return index on success, -1 otherwise
463 */
464 public int lookupNameAndType( String name, String signature ) {
465 Index _index = (Index) n_a_t_table.get(name + NAT_DELIM + signature);
466 return (_index != null) ? _index.index : -1;
467 }
468
469
470 /**
471 * Add a new NameAndType constant to the ConstantPool if it is not already
472 * in there.
473 *
474 * @param name Name string to add
475 * @param signature signature string to add
476 * @return index of entry
477 */
478 public int addNameAndType( String name, String signature ) {
479 int ret;
480 int name_index, signature_index;
481 if ((ret = lookupNameAndType(name, signature)) != -1) {
482 return ret; // Already in CP
483 }
484 adjustSize();
485 name_index = addUtf8(name);
486 signature_index = addUtf8(signature);
487 ret = index;
488 constants[index++] = new ConstantNameAndType(name_index, signature_index);
489 String key = name + NAT_DELIM + signature;
490 if (!n_a_t_table.containsKey(key)) {
491 n_a_t_table.put(key, new Index(ret));
492 }
493 return ret;
494 }
495
496 private Map cp_table = new HashMap();
497
498
499 /**
500 * Look for ConstantMethodref in ConstantPool.
501 *
502 * @param class_name Where to find method
503 * @param method_name Guess what
504 * @param signature return and argument types
505 * @return index on success, -1 otherwise
506 */
507 public int lookupMethodref( String class_name, String method_name, String signature ) {
508 Index index = (Index) cp_table.get(class_name + METHODREF_DELIM + method_name
509 + METHODREF_DELIM + signature);
510 return (index != null) ? index.index : -1;
511 }
512
513
514 public int lookupMethodref( MethodGen method ) {
515 return lookupMethodref(method.getClassName(), method.getName(), method.getSignature());
516 }
517
518
519 /**
520 * Add a new Methodref constant to the ConstantPool, if it is not already
521 * in there.
522 *
523 * @param class_name class name string to add
524 * @param method_name method name string to add
525 * @param signature method signature string to add
526 * @return index of entry
527 */
528 public int addMethodref( String class_name, String method_name, String signature ) {
529 int ret, class_index, name_and_type_index;
530 if ((ret = lookupMethodref(class_name, method_name, signature)) != -1) {
531 return ret; // Already in CP
532 }
533 adjustSize();
534 name_and_type_index = addNameAndType(method_name, signature);
535 class_index = addClass(class_name);
536 ret = index;
537 constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
538 String key = class_name + METHODREF_DELIM + method_name + METHODREF_DELIM + signature;
539 if (!cp_table.containsKey(key)) {
540 cp_table.put(key, new Index(ret));
541 }
542 return ret;
543 }
544
545
546 public int addMethodref( MethodGen method ) {
547 return addMethodref(method.getClassName(), method.getName(), method.getSignature());
548 }
549
550
551 /**
552 * Look for ConstantInterfaceMethodref in ConstantPool.
553 *
554 * @param class_name Where to find method
555 * @param method_name Guess what
556 * @param signature return and argument types
557 * @return index on success, -1 otherwise
558 */
559 public int lookupInterfaceMethodref( String class_name, String method_name, String signature ) {
560 Index index = (Index) cp_table.get(class_name + IMETHODREF_DELIM + method_name
561 + IMETHODREF_DELIM + signature);
562 return (index != null) ? index.index : -1;
563 }
564
565
566 public int lookupInterfaceMethodref( MethodGen method ) {
567 return lookupInterfaceMethodref(method.getClassName(), method.getName(), method
568 .getSignature());
569 }
570
571
572 /**
573 * Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
574 * in there.
575 *
576 * @param class_name class name string to add
577 * @param method_name method name string to add
578 * @param signature signature string to add
579 * @return index of entry
580 */
581 public int addInterfaceMethodref( String class_name, String method_name, String signature ) {
582 int ret, class_index, name_and_type_index;
583 if ((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1) {
584 return ret; // Already in CP
585 }
586 adjustSize();
587 class_index = addClass(class_name);
588 name_and_type_index = addNameAndType(method_name, signature);
589 ret = index;
590 constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
591 String key = class_name + IMETHODREF_DELIM + method_name + IMETHODREF_DELIM + signature;
592 if (!cp_table.containsKey(key)) {
593 cp_table.put(key, new Index(ret));
594 }
595 return ret;
596 }
597
598
599 public int addInterfaceMethodref( MethodGen method ) {
600 return addInterfaceMethodref(method.getClassName(), method.getName(), method.getSignature());
601 }
602
603
604 /**
605 * Look for ConstantFieldref in ConstantPool.
606 *
607 * @param class_name Where to find method
608 * @param field_name Guess what
609 * @param signature return and argument types
610 * @return index on success, -1 otherwise
611 */
612 public int lookupFieldref( String class_name, String field_name, String signature ) {
613 Index index = (Index) cp_table.get(class_name + FIELDREF_DELIM + field_name
614 + FIELDREF_DELIM + signature);
615 return (index != null) ? index.index : -1;
616 }
617
618
619 /**
620 * Add a new Fieldref constant to the ConstantPool, if it is not already
621 * in there.
622 *
623 * @param class_name class name string to add
624 * @param field_name field name string to add
625 * @param signature signature string to add
626 * @return index of entry
627 */
628 public int addFieldref( String class_name, String field_name, String signature ) {
629 int ret;
630 int class_index, name_and_type_index;
631 if ((ret = lookupFieldref(class_name, field_name, signature)) != -1) {
632 return ret; // Already in CP
633 }
634 adjustSize();
635 class_index = addClass(class_name);
636 name_and_type_index = addNameAndType(field_name, signature);
637 ret = index;
638 constants[index++] = new ConstantFieldref(class_index, name_and_type_index);
639 String key = class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature;
640 if (!cp_table.containsKey(key)) {
641 cp_table.put(key, new Index(ret));
642 }
643 return ret;
644 }
645
646
647 /**
648 * @param i index in constant pool
649 * @return constant pool entry at index i
650 */
651 public Constant getConstant( int i ) {
652 return constants[i];
653 }
654
655
656 /**
657 * Use with care!
658 *
659 * @param i index in constant pool
660 * @param c new constant pool entry at index i
661 */
662 public void setConstant( int i, Constant c ) {
663 constants[i] = c;
664 }
665
666
667 /**
668 * @return intermediate constant pool
669 */
670 public ConstantPool getConstantPool() {
671 return new ConstantPool(constants);
672 }
673
674
675 /**
676 * @return current size of constant pool
677 */
678 public int getSize() {
679 return index;
680 }
681
682
683 /**
684 * @return constant pool with proper length
685 */
686 public ConstantPool getFinalConstantPool() {
687 Constant[] cs = new Constant[index];
688 System.arraycopy(constants, 0, cs, 0, index);
689 return new ConstantPool(cs);
690 }
691
692
693 /**
694 * @return String representation.
695 */
696 public String toString() {
697 StringBuffer buf = new StringBuffer();
698 for (int i = 1; i < index; i++) {
699 buf.append(i).append(")").append(constants[i]).append("\n");
700 }
701 return buf.toString();
702 }
703
704
705 /** Import constant from another ConstantPool and return new index.
706 */
707 public int addConstant( Constant c, ConstantPoolGen cp ) {
708 Constant[] constants = cp.getConstantPool().getConstantPool();
709 switch (c.getTag()) {
710 case Constants.CONSTANT_String: {
711 ConstantString s = (ConstantString) c;
712 ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
713 return addString(u8.getBytes());
714 }
715 case Constants.CONSTANT_Class: {
716 ConstantClass s = (ConstantClass) c;
717 ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
718 return addClass(u8.getBytes());
719 }
720 case Constants.CONSTANT_NameAndType: {
721 ConstantNameAndType n = (ConstantNameAndType) c;
722 ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
723 ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
724 return addNameAndType(u8.getBytes(), u8_2.getBytes());
725 }
726 case Constants.CONSTANT_Utf8:
727 return addUtf8(((ConstantUtf8) c).getBytes());
728 case Constants.CONSTANT_Double:
729 return addDouble(((ConstantDouble) c).getBytes());
730 case Constants.CONSTANT_Float:
731 return addFloat(((ConstantFloat) c).getBytes());
732 case Constants.CONSTANT_Long:
733 return addLong(((ConstantLong) c).getBytes());
734 case Constants.CONSTANT_Integer:
735 return addInteger(((ConstantInteger) c).getBytes());
736 case Constants.CONSTANT_InterfaceMethodref:
737 case Constants.CONSTANT_Methodref:
738 case Constants.CONSTANT_Fieldref: {
739 ConstantCP m = (ConstantCP) c;
740 ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
741 ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
742 ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
743 String class_name = u8.getBytes().replace('/', '.');
744 u8 = (ConstantUtf8) constants[n.getNameIndex()];
745 String name = u8.getBytes();
746 u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
747 String signature = u8.getBytes();
748 switch (c.getTag()) {
749 case Constants.CONSTANT_InterfaceMethodref:
750 return addInterfaceMethodref(class_name, name, signature);
751 case Constants.CONSTANT_Methodref:
752 return addMethodref(class_name, name, signature);
753 case Constants.CONSTANT_Fieldref:
754 return addFieldref(class_name, name, signature);
755 default: // Never reached
756 throw new RuntimeException("Unknown constant type " + c);
757 }
758 }
759 default: // Never reached
760 throw new RuntimeException("Unknown constant type " + c);
761 }
762 }
763 }
+0
-32
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ConstantPushInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes a push instruction that produces a literal on the stack
20 * such as SIPUSH, BIPUSH, ICONST, etc.
21 *
22 * @version $Id: ConstantPushInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
25 * @see ICONST
26 * @see SIPUSH
27 */
28 public interface ConstantPushInstruction extends PushInstruction, TypedInstruction {
29
30 public Number getValue();
31 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ConversionInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Super class for the x2y family of instructions.
22 *
23 * @version $Id: ConversionInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public abstract class ConversionInstruction extends Instruction implements TypedInstruction,
27 StackProducer, StackConsumer {
28
29 /**
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 ConversionInstruction() {
34 }
35
36
37 /**
38 * @param opcode opcode of instruction
39 */
40 protected ConversionInstruction(short opcode) {
41 super(opcode, (short) 1);
42 }
43
44
45 /** @return type associated with the instruction
46 */
47 public Type getType( ConstantPoolGen cp ) {
48 switch (opcode) {
49 case Constants.D2I:
50 case Constants.F2I:
51 case Constants.L2I:
52 return Type.INT;
53 case Constants.D2F:
54 case Constants.I2F:
55 case Constants.L2F:
56 return Type.FLOAT;
57 case Constants.D2L:
58 case Constants.F2L:
59 case Constants.I2L:
60 return Type.LONG;
61 case Constants.F2D:
62 case Constants.I2D:
63 case Constants.L2D:
64 return Type.DOUBLE;
65 case Constants.I2B:
66 return Type.BYTE;
67 case Constants.I2C:
68 return Type.CHAR;
69 case Constants.I2S:
70 return Type.SHORT;
71 default: // Never reached
72 throw new ClassGenException("Unknown type " + opcode);
73 }
74 }
75 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/D2F.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * D2F - Convert double to float
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: D2F.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class D2F extends ConversionInstruction {
26
27 /** Convert double to float
28 */
29 public D2F() {
30 super(org.apache.bcel.Constants.D2F);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitD2F(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/D2I.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * D2I - Convert double to int
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: D2I.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class D2I extends ConversionInstruction {
26
27 /** Convert double to int
28 */
29 public D2I() {
30 super(org.apache.bcel.Constants.D2I);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitD2I(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/D2L.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * D2L - Convert double to long
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: D2L.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class D2L extends ConversionInstruction {
26
27 /** Convert double to long
28 */
29 public D2L() {
30 super(org.apache.bcel.Constants.D2L);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitD2L(this);
48 }
49 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DADD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DADD - Add doubles
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result1.word2
22 *
23 * @version $Id: DADD.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DADD extends ArithmeticInstruction {
27
28 /** Add doubles
29 */
30 public DADD() {
31 super(org.apache.bcel.Constants.DADD);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitTypedInstruction(this);
45 v.visitStackProducer(this);
46 v.visitStackConsumer(this);
47 v.visitArithmeticInstruction(this);
48 v.visitDADD(this);
49 }
50 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DALOAD - Load double from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: DALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load double from array
28 */
29 public DALOAD() {
30 super(org.apache.bcel.Constants.DALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitDALOAD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DASTORE - Store into double array
20 * <PRE>Stack: ..., arrayref, index, value.word1, value.word2 -&gt; ...</PRE>
21 *
22 * @version $Id: DASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store double into array
28 */
29 public DASTORE() {
30 super(org.apache.bcel.Constants.DASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitDASTORE(this);
48 }
49 }
+0
-55
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DCMPG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DCMPG - Compare doubles: value1 > value2
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result
22 *
23 * @version $Id: DCMPG.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DCMPG extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
27
28 public DCMPG() {
29 super(org.apache.bcel.Constants.DCMPG, (short) 1);
30 }
31
32
33 /** @return Type.DOUBLE
34 */
35 public Type getType( ConstantPoolGen cp ) {
36 return Type.DOUBLE;
37 }
38
39
40 /**
41 * Call corresponding visitor method(s). The order is:
42 * Call visitor methods of implemented interfaces first, then
43 * call methods according to the class hierarchy in descending order,
44 * i.e., the most specific visitXXX() call comes last.
45 *
46 * @param v Visitor object
47 */
48 public void accept( Visitor v ) {
49 v.visitTypedInstruction(this);
50 v.visitStackProducer(this);
51 v.visitStackConsumer(this);
52 v.visitDCMPG(this);
53 }
54 }
+0
-55
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DCMPL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DCMPL - Compare doubles: value1 < value2
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result
22 *
23 * @version $Id: DCMPL.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DCMPL extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
27
28 public DCMPL() {
29 super(org.apache.bcel.Constants.DCMPL, (short) 1);
30 }
31
32
33 /** @return Type.DOUBLE
34 */
35 public Type getType( ConstantPoolGen cp ) {
36 return Type.DOUBLE;
37 }
38
39
40 /**
41 * Call corresponding visitor method(s). The order is:
42 * Call visitor methods of implemented interfaces first, then
43 * call methods according to the class hierarchy in descending order,
44 * i.e., the most specific visitXXX() call comes last.
45 *
46 * @param v Visitor object
47 */
48 public void accept( Visitor v ) {
49 v.visitTypedInstruction(this);
50 v.visitStackProducer(this);
51 v.visitStackConsumer(this);
52 v.visitDCMPL(this);
53 }
54 }
+0
-80
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DCONST.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DCONST - Push 0.0 or 1.0, other values cause an exception
20 *
21 * <PRE>Stack: ... -&gt; ..., </PRE>
22 *
23 * @version $Id: DCONST.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DCONST extends Instruction implements ConstantPushInstruction, TypedInstruction {
27
28 private double value;
29
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 DCONST() {
36 }
37
38
39 public DCONST(double f) {
40 super(org.apache.bcel.Constants.DCONST_0, (short) 1);
41 if (f == 0.0) {
42 opcode = org.apache.bcel.Constants.DCONST_0;
43 } else if (f == 1.0) {
44 opcode = org.apache.bcel.Constants.DCONST_1;
45 } else {
46 throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f);
47 }
48 value = f;
49 }
50
51
52 public Number getValue() {
53 return new Double(value);
54 }
55
56
57 /** @return Type.DOUBLE
58 */
59 public Type getType( ConstantPoolGen cp ) {
60 return Type.DOUBLE;
61 }
62
63
64 /**
65 * Call corresponding visitor method(s). The order is:
66 * Call visitor methods of implemented interfaces first, then
67 * call methods according to the class hierarchy in descending order,
68 * i.e., the most specific visitXXX() call comes last.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitPushInstruction(this);
74 v.visitStackProducer(this);
75 v.visitTypedInstruction(this);
76 v.visitConstantPushInstruction(this);
77 v.visitDCONST(this);
78 }
79 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DDIV.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DDIV - Divide doubles
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: DDIV.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DDIV extends ArithmeticInstruction {
27
28 /** Divide doubles
29 */
30 public DDIV() {
31 super(org.apache.bcel.Constants.DDIV);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitTypedInstruction(this);
45 v.visitStackProducer(this);
46 v.visitStackConsumer(this);
47 v.visitArithmeticInstruction(this);
48 v.visitDDIV(this);
49 }
50 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DLOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DLOAD - Load double from local variable
20 * <PRE>Stack ... -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: DLOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DLOAD extends LoadInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 DLOAD() {
32 super(org.apache.bcel.Constants.DLOAD, org.apache.bcel.Constants.DLOAD_0);
33 }
34
35
36 /** Load double from local variable
37 * @param n index of local variable
38 */
39 public DLOAD(int n) {
40 super(org.apache.bcel.Constants.DLOAD, org.apache.bcel.Constants.DLOAD_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitDLOAD(this);
55 }
56 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DMUL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DMUL - Multiply doubles
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: DMUL.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DMUL extends ArithmeticInstruction {
27
28 /** Multiply doubles
29 */
30 public DMUL() {
31 super(org.apache.bcel.Constants.DMUL);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitTypedInstruction(this);
45 v.visitStackProducer(this);
46 v.visitStackConsumer(this);
47 v.visitArithmeticInstruction(this);
48 v.visitDMUL(this);
49 }
50 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DNEG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DNEG - Negate double
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: DNEG.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DNEG extends ArithmeticInstruction {
26
27 public DNEG() {
28 super(org.apache.bcel.Constants.DNEG);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitDNEG(this);
46 }
47 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DREM.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DREM - Remainder of doubles
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: DREM.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DREM extends ArithmeticInstruction {
27
28 /** Remainder of doubles
29 */
30 public DREM() {
31 super(org.apache.bcel.Constants.DREM);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitTypedInstruction(this);
45 v.visitStackProducer(this);
46 v.visitStackConsumer(this);
47 v.visitArithmeticInstruction(this);
48 v.visitDREM(this);
49 }
50 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DRETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DRETURN - Return double from method
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: DRETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DRETURN extends ReturnInstruction {
26
27 /** Return double from method
28 */
29 public DRETURN() {
30 super(org.apache.bcel.Constants.DRETURN);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitExceptionThrower(this);
44 v.visitTypedInstruction(this);
45 v.visitStackConsumer(this);
46 v.visitReturnInstruction(this);
47 v.visitDRETURN(this);
48 }
49 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DSTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DSTORE - Store double into local variable
20 * <pre>Stack: ..., value.word1, value.word2 -&gt; ... </PRE>
21 *
22 * @version $Id: DSTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DSTORE extends StoreInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 DSTORE() {
32 super(org.apache.bcel.Constants.DSTORE, org.apache.bcel.Constants.DSTORE_0);
33 }
34
35
36 /** Store double into local variable
37 * @param n index of local variable
38 */
39 public DSTORE(int n) {
40 super(org.apache.bcel.Constants.DSTORE, org.apache.bcel.Constants.DSTORE_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitDSTORE(this);
55 }
56 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DSUB.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DSUB - Substract doubles
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: DSUB.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class DSUB extends ArithmeticInstruction {
27
28 /** Substract doubles
29 */
30 public DSUB() {
31 super(org.apache.bcel.Constants.DSUB);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitTypedInstruction(this);
45 v.visitStackProducer(this);
46 v.visitStackConsumer(this);
47 v.visitArithmeticInstruction(this);
48 v.visitDSUB(this);
49 }
50 }
+0
-47
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP - Duplicate top operand stack word
20 * <PRE>Stack: ..., word -&gt; ..., word, word</PRE>
21 *
22 * @version $Id: DUP.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP extends StackInstruction implements PushInstruction {
26
27 public DUP() {
28 super(org.apache.bcel.Constants.DUP);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackProducer(this);
42 v.visitPushInstruction(this);
43 v.visitStackInstruction(this);
44 v.visitDUP(this);
45 }
46 }
+0
-47
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP2.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP2 - Duplicate two top operand stack words
20 * <PRE>Stack: ..., word2, word1 -&gt; ..., word2, word1, word2, word1</PRE>
21 *
22 * @version $Id: DUP2.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP2 extends StackInstruction implements PushInstruction {
26
27 public DUP2() {
28 super(org.apache.bcel.Constants.DUP2);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackProducer(this);
42 v.visitPushInstruction(this);
43 v.visitStackInstruction(this);
44 v.visitDUP2(this);
45 }
46 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP2_X1.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP2_X1 - Duplicate two top operand stack words and put three down
20 * <PRE>Stack: ..., word3, word2, word1 -&gt; ..., word2, word1, word3, word2, word1</PRE>
21 *
22 * @version $Id: DUP2_X1.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP2_X1 extends StackInstruction {
26
27 public DUP2_X1() {
28 super(org.apache.bcel.Constants.DUP2_X1);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackInstruction(this);
42 v.visitDUP2_X1(this);
43 }
44 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP2_X2.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP2_X2 - Duplicate two top operand stack words and put four down
20 * <PRE>Stack: ..., word4, word3, word2, word1 -&gt; ..., word2, word1, word4, word3, word2, word1</PRE>
21 *
22 * @version $Id: DUP2_X2.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP2_X2 extends StackInstruction {
26
27 public DUP2_X2() {
28 super(org.apache.bcel.Constants.DUP2_X2);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackInstruction(this);
42 v.visitDUP2_X2(this);
43 }
44 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP_X1.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP_X1 - Duplicate top operand stack word and put two down
20 * <PRE>Stack: ..., word2, word1 -&gt; ..., word1, word2, word1</PRE>
21 *
22 * @version $Id: DUP_X1.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP_X1 extends StackInstruction {
26
27 public DUP_X1() {
28 super(org.apache.bcel.Constants.DUP_X1);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackInstruction(this);
42 v.visitDUP_X1(this);
43 }
44 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/DUP_X2.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * DUP_X2 - Duplicate top operand stack word and put three down
20 * <PRE>Stack: ..., word3, word2, word1 -&gt; ..., word1, word3, word2, word1</PRE>
21 *
22 * @version $Id: DUP_X2.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class DUP_X2 extends StackInstruction {
26
27 public DUP_X2() {
28 super(org.apache.bcel.Constants.DUP_X2);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackInstruction(this);
42 v.visitDUP_X2(this);
43 }
44 }
+0
-745
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/EmptyVisitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Supplies empty method bodies to be overridden by subclasses.
20 *
21 * @version $Id: EmptyVisitor.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class EmptyVisitor implements Visitor {
25
26 public void visitStackInstruction( StackInstruction obj ) {
27 }
28
29
30 public void visitLocalVariableInstruction( LocalVariableInstruction obj ) {
31 }
32
33
34 public void visitBranchInstruction( BranchInstruction obj ) {
35 }
36
37
38 public void visitLoadClass( LoadClass obj ) {
39 }
40
41
42 public void visitFieldInstruction( FieldInstruction obj ) {
43 }
44
45
46 public void visitIfInstruction( IfInstruction obj ) {
47 }
48
49
50 public void visitConversionInstruction( ConversionInstruction obj ) {
51 }
52
53
54 public void visitPopInstruction( PopInstruction obj ) {
55 }
56
57
58 public void visitJsrInstruction( JsrInstruction obj ) {
59 }
60
61
62 public void visitGotoInstruction( GotoInstruction obj ) {
63 }
64
65
66 public void visitStoreInstruction( StoreInstruction obj ) {
67 }
68
69
70 public void visitTypedInstruction( TypedInstruction obj ) {
71 }
72
73
74 public void visitSelect( Select obj ) {
75 }
76
77
78 public void visitUnconditionalBranch( UnconditionalBranch obj ) {
79 }
80
81
82 public void visitPushInstruction( PushInstruction obj ) {
83 }
84
85
86 public void visitArithmeticInstruction( ArithmeticInstruction obj ) {
87 }
88
89
90 public void visitCPInstruction( CPInstruction obj ) {
91 }
92
93
94 public void visitInvokeInstruction( InvokeInstruction obj ) {
95 }
96
97
98 public void visitArrayInstruction( ArrayInstruction obj ) {
99 }
100
101
102 public void visitAllocationInstruction( AllocationInstruction obj ) {
103 }
104
105
106 public void visitReturnInstruction( ReturnInstruction obj ) {
107 }
108
109
110 public void visitFieldOrMethod( FieldOrMethod obj ) {
111 }
112
113
114 public void visitConstantPushInstruction( ConstantPushInstruction obj ) {
115 }
116
117
118 public void visitExceptionThrower( ExceptionThrower obj ) {
119 }
120
121
122 public void visitLoadInstruction( LoadInstruction obj ) {
123 }
124
125
126 public void visitVariableLengthInstruction( VariableLengthInstruction obj ) {
127 }
128
129
130 public void visitStackProducer( StackProducer obj ) {
131 }
132
133
134 public void visitStackConsumer( StackConsumer obj ) {
135 }
136
137
138 public void visitACONST_NULL( ACONST_NULL obj ) {
139 }
140
141
142 public void visitGETSTATIC( GETSTATIC obj ) {
143 }
144
145
146 public void visitIF_ICMPLT( IF_ICMPLT obj ) {
147 }
148
149
150 public void visitMONITOREXIT( MONITOREXIT obj ) {
151 }
152
153
154 public void visitIFLT( IFLT obj ) {
155 }
156
157
158 public void visitLSTORE( LSTORE obj ) {
159 }
160
161
162 public void visitPOP2( POP2 obj ) {
163 }
164
165
166 public void visitBASTORE( BASTORE obj ) {
167 }
168
169
170 public void visitISTORE( ISTORE obj ) {
171 }
172
173
174 public void visitCHECKCAST( CHECKCAST obj ) {
175 }
176
177
178 public void visitFCMPG( FCMPG obj ) {
179 }
180
181
182 public void visitI2F( I2F obj ) {
183 }
184
185
186 public void visitATHROW( ATHROW obj ) {
187 }
188
189
190 public void visitDCMPL( DCMPL obj ) {
191 }
192
193
194 public void visitARRAYLENGTH( ARRAYLENGTH obj ) {
195 }
196
197
198 public void visitDUP( DUP obj ) {
199 }
200
201
202 public void visitINVOKESTATIC( INVOKESTATIC obj ) {
203 }
204
205
206 public void visitLCONST( LCONST obj ) {
207 }
208
209
210 public void visitDREM( DREM obj ) {
211 }
212
213
214 public void visitIFGE( IFGE obj ) {
215 }
216
217
218 public void visitCALOAD( CALOAD obj ) {
219 }
220
221
222 public void visitLASTORE( LASTORE obj ) {
223 }
224
225
226 public void visitI2D( I2D obj ) {
227 }
228
229
230 public void visitDADD( DADD obj ) {
231 }
232
233
234 public void visitINVOKESPECIAL( INVOKESPECIAL obj ) {
235 }
236
237
238 public void visitIAND( IAND obj ) {
239 }
240
241
242 public void visitPUTFIELD( PUTFIELD obj ) {
243 }
244
245
246 public void visitILOAD( ILOAD obj ) {
247 }
248
249
250 public void visitDLOAD( DLOAD obj ) {
251 }
252
253
254 public void visitDCONST( DCONST obj ) {
255 }
256
257
258 public void visitNEW( NEW obj ) {
259 }
260
261
262 public void visitIFNULL( IFNULL obj ) {
263 }
264
265
266 public void visitLSUB( LSUB obj ) {
267 }
268
269
270 public void visitL2I( L2I obj ) {
271 }
272
273
274 public void visitISHR( ISHR obj ) {
275 }
276
277
278 public void visitTABLESWITCH( TABLESWITCH obj ) {
279 }
280
281
282 public void visitIINC( IINC obj ) {
283 }
284
285
286 public void visitDRETURN( DRETURN obj ) {
287 }
288
289
290 public void visitFSTORE( FSTORE obj ) {
291 }
292
293
294 public void visitDASTORE( DASTORE obj ) {
295 }
296
297
298 public void visitIALOAD( IALOAD obj ) {
299 }
300
301
302 public void visitDDIV( DDIV obj ) {
303 }
304
305
306 public void visitIF_ICMPGE( IF_ICMPGE obj ) {
307 }
308
309
310 public void visitLAND( LAND obj ) {
311 }
312
313
314 public void visitIDIV( IDIV obj ) {
315 }
316
317
318 public void visitLOR( LOR obj ) {
319 }
320
321
322 public void visitCASTORE( CASTORE obj ) {
323 }
324
325
326 public void visitFREM( FREM obj ) {
327 }
328
329
330 public void visitLDC( LDC obj ) {
331 }
332
333
334 public void visitBIPUSH( BIPUSH obj ) {
335 }
336
337
338 public void visitDSTORE( DSTORE obj ) {
339 }
340
341
342 public void visitF2L( F2L obj ) {
343 }
344
345
346 public void visitFMUL( FMUL obj ) {
347 }
348
349
350 public void visitLLOAD( LLOAD obj ) {
351 }
352
353
354 public void visitJSR( JSR obj ) {
355 }
356
357
358 public void visitFSUB( FSUB obj ) {
359 }
360
361
362 public void visitSASTORE( SASTORE obj ) {
363 }
364
365
366 public void visitALOAD( ALOAD obj ) {
367 }
368
369
370 public void visitDUP2_X2( DUP2_X2 obj ) {
371 }
372
373
374 public void visitRETURN( RETURN obj ) {
375 }
376
377
378 public void visitDALOAD( DALOAD obj ) {
379 }
380
381
382 public void visitSIPUSH( SIPUSH obj ) {
383 }
384
385
386 public void visitDSUB( DSUB obj ) {
387 }
388
389
390 public void visitL2F( L2F obj ) {
391 }
392
393
394 public void visitIF_ICMPGT( IF_ICMPGT obj ) {
395 }
396
397
398 public void visitF2D( F2D obj ) {
399 }
400
401
402 public void visitI2L( I2L obj ) {
403 }
404
405
406 public void visitIF_ACMPNE( IF_ACMPNE obj ) {
407 }
408
409
410 public void visitPOP( POP obj ) {
411 }
412
413
414 public void visitI2S( I2S obj ) {
415 }
416
417
418 public void visitIFEQ( IFEQ obj ) {
419 }
420
421
422 public void visitSWAP( SWAP obj ) {
423 }
424
425
426 public void visitIOR( IOR obj ) {
427 }
428
429
430 public void visitIREM( IREM obj ) {
431 }
432
433
434 public void visitIASTORE( IASTORE obj ) {
435 }
436
437
438 public void visitNEWARRAY( NEWARRAY obj ) {
439 }
440
441
442 public void visitINVOKEINTERFACE( INVOKEINTERFACE obj ) {
443 }
444
445
446 public void visitINEG( INEG obj ) {
447 }
448
449
450 public void visitLCMP( LCMP obj ) {
451 }
452
453
454 public void visitJSR_W( JSR_W obj ) {
455 }
456
457
458 public void visitMULTIANEWARRAY( MULTIANEWARRAY obj ) {
459 }
460
461
462 public void visitDUP_X2( DUP_X2 obj ) {
463 }
464
465
466 public void visitSALOAD( SALOAD obj ) {
467 }
468
469
470 public void visitIFNONNULL( IFNONNULL obj ) {
471 }
472
473
474 public void visitDMUL( DMUL obj ) {
475 }
476
477
478 public void visitIFNE( IFNE obj ) {
479 }
480
481
482 public void visitIF_ICMPLE( IF_ICMPLE obj ) {
483 }
484
485
486 public void visitLDC2_W( LDC2_W obj ) {
487 }
488
489
490 public void visitGETFIELD( GETFIELD obj ) {
491 }
492
493
494 public void visitLADD( LADD obj ) {
495 }
496
497
498 public void visitNOP( NOP obj ) {
499 }
500
501
502 public void visitFALOAD( FALOAD obj ) {
503 }
504
505
506 public void visitINSTANCEOF( INSTANCEOF obj ) {
507 }
508
509
510 public void visitIFLE( IFLE obj ) {
511 }
512
513
514 public void visitLXOR( LXOR obj ) {
515 }
516
517
518 public void visitLRETURN( LRETURN obj ) {
519 }
520
521
522 public void visitFCONST( FCONST obj ) {
523 }
524
525
526 public void visitIUSHR( IUSHR obj ) {
527 }
528
529
530 public void visitBALOAD( BALOAD obj ) {
531 }
532
533
534 public void visitDUP2( DUP2 obj ) {
535 }
536
537
538 public void visitIF_ACMPEQ( IF_ACMPEQ obj ) {
539 }
540
541
542 public void visitIMPDEP1( IMPDEP1 obj ) {
543 }
544
545
546 public void visitMONITORENTER( MONITORENTER obj ) {
547 }
548
549
550 public void visitLSHL( LSHL obj ) {
551 }
552
553
554 public void visitDCMPG( DCMPG obj ) {
555 }
556
557
558 public void visitD2L( D2L obj ) {
559 }
560
561
562 public void visitIMPDEP2( IMPDEP2 obj ) {
563 }
564
565
566 public void visitL2D( L2D obj ) {
567 }
568
569
570 public void visitRET( RET obj ) {
571 }
572
573
574 public void visitIFGT( IFGT obj ) {
575 }
576
577
578 public void visitIXOR( IXOR obj ) {
579 }
580
581
582 public void visitINVOKEVIRTUAL( INVOKEVIRTUAL obj ) {
583 }
584
585
586 public void visitFASTORE( FASTORE obj ) {
587 }
588
589
590 public void visitIRETURN( IRETURN obj ) {
591 }
592
593
594 public void visitIF_ICMPNE( IF_ICMPNE obj ) {
595 }
596
597
598 public void visitFLOAD( FLOAD obj ) {
599 }
600
601
602 public void visitLDIV( LDIV obj ) {
603 }
604
605
606 public void visitPUTSTATIC( PUTSTATIC obj ) {
607 }
608
609
610 public void visitAALOAD( AALOAD obj ) {
611 }
612
613
614 public void visitD2I( D2I obj ) {
615 }
616
617
618 public void visitIF_ICMPEQ( IF_ICMPEQ obj ) {
619 }
620
621
622 public void visitAASTORE( AASTORE obj ) {
623 }
624
625
626 public void visitARETURN( ARETURN obj ) {
627 }
628
629
630 public void visitDUP2_X1( DUP2_X1 obj ) {
631 }
632
633
634 public void visitFNEG( FNEG obj ) {
635 }
636
637
638 public void visitGOTO_W( GOTO_W obj ) {
639 }
640
641
642 public void visitD2F( D2F obj ) {
643 }
644
645
646 public void visitGOTO( GOTO obj ) {
647 }
648
649
650 public void visitISUB( ISUB obj ) {
651 }
652
653
654 public void visitF2I( F2I obj ) {
655 }
656
657
658 public void visitDNEG( DNEG obj ) {
659 }
660
661
662 public void visitICONST( ICONST obj ) {
663 }
664
665
666 public void visitFDIV( FDIV obj ) {
667 }
668
669
670 public void visitI2B( I2B obj ) {
671 }
672
673
674 public void visitLNEG( LNEG obj ) {
675 }
676
677
678 public void visitLREM( LREM obj ) {
679 }
680
681
682 public void visitIMUL( IMUL obj ) {
683 }
684
685
686 public void visitIADD( IADD obj ) {
687 }
688
689
690 public void visitLSHR( LSHR obj ) {
691 }
692
693
694 public void visitLOOKUPSWITCH( LOOKUPSWITCH obj ) {
695 }
696
697
698 public void visitDUP_X1( DUP_X1 obj ) {
699 }
700
701
702 public void visitFCMPL( FCMPL obj ) {
703 }
704
705
706 public void visitI2C( I2C obj ) {
707 }
708
709
710 public void visitLMUL( LMUL obj ) {
711 }
712
713
714 public void visitLUSHR( LUSHR obj ) {
715 }
716
717
718 public void visitISHL( ISHL obj ) {
719 }
720
721
722 public void visitLALOAD( LALOAD obj ) {
723 }
724
725
726 public void visitASTORE( ASTORE obj ) {
727 }
728
729
730 public void visitANEWARRAY( ANEWARRAY obj ) {
731 }
732
733
734 public void visitFRETURN( FRETURN obj ) {
735 }
736
737
738 public void visitFADD( FADD obj ) {
739 }
740
741
742 public void visitBREAKPOINT( BREAKPOINT obj ) {
743 }
744 }
+0
-42
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ExceptionThrower.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote an instruction that may throw a run-time or a linking
20 * exception (or both) during execution. This is not quite the truth
21 * as such; because all instructions may throw an
22 * java.lang.VirtualMachineError. These exceptions are omitted.
23 *
24 * The Lava Language Specification specifies exactly which
25 * <i>RUN-TIME</i> and which <i>LINKING</i> exceptions each
26 * instruction may throw which is reflected by the implementers. Due
27 * to the structure of the JVM specification, it may be possible that
28 * an Instruction implementing this interface returns a Class[] of
29 * size 0.
30 *
31 * Please note that we speak of an "exception" here when we mean any
32 * "Throwable" object; so this term is equally used for "Exception"
33 * and "Error" objects.
34 *
35 * @version $Id: ExceptionThrower.java 386056 2006-03-15 11:31:56Z tcurdt $
36 * @author Enver Haase
37 */
38 public interface ExceptionThrower {
39
40 public java.lang.Class[] getExceptions();
41 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/F2D.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * F2D - Convert float to double
20 * <PRE>Stack: ..., value -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: F2D.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class F2D extends ConversionInstruction {
26
27 /** Convert float to double
28 */
29 public F2D() {
30 super(org.apache.bcel.Constants.F2D);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitF2D(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/F2I.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * F2I - Convert float to int
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: F2I.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class F2I extends ConversionInstruction {
26
27 /** Convert float to int
28 */
29 public F2I() {
30 super(org.apache.bcel.Constants.F2I);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitF2I(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/F2L.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * F2L - Convert float to long
20 * <PRE>Stack: ..., value -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: F2L.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class F2L extends ConversionInstruction {
26
27 /** Convert float to long
28 */
29 public F2L() {
30 super(org.apache.bcel.Constants.F2L);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitF2L(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FADD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FADD - Add floats
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: FADD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FADD extends ArithmeticInstruction {
26
27 /** Add floats
28 */
29 public FADD() {
30 super(org.apache.bcel.Constants.FADD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitFADD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FALOAD - Load float from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
21 *
22 * @version $Id: FALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load float from array
28 */
29 public FALOAD() {
30 super(org.apache.bcel.Constants.FALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitFALOAD(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FASTORE - Store into float array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: FASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store float into array
28 */
29 public FASTORE() {
30 super(org.apache.bcel.Constants.FASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitFASTORE(this);
48 }
49 }
+0
-54
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FCMPG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FCMPG - Compare floats: value1 > value2
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: FCMPG.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FCMPG extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
26
27 public FCMPG() {
28 super(org.apache.bcel.Constants.FCMPG, (short) 1);
29 }
30
31
32 /** @return Type.FLOAT
33 */
34 public Type getType( ConstantPoolGen cp ) {
35 return Type.FLOAT;
36 }
37
38
39 /**
40 * Call corresponding visitor method(s). The order is:
41 * Call visitor methods of implemented interfaces first, then
42 * call methods according to the class hierarchy in descending order,
43 * i.e., the most specific visitXXX() call comes last.
44 *
45 * @param v Visitor object
46 */
47 public void accept( Visitor v ) {
48 v.visitTypedInstruction(this);
49 v.visitStackProducer(this);
50 v.visitStackConsumer(this);
51 v.visitFCMPG(this);
52 }
53 }
+0
-54
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FCMPL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FCMPL - Compare floats: value1 < value2
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: FCMPL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FCMPL extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
26
27 public FCMPL() {
28 super(org.apache.bcel.Constants.FCMPL, (short) 1);
29 }
30
31
32 /** @return Type.FLOAT
33 */
34 public Type getType( ConstantPoolGen cp ) {
35 return Type.FLOAT;
36 }
37
38
39 /**
40 * Call corresponding visitor method(s). The order is:
41 * Call visitor methods of implemented interfaces first, then
42 * call methods according to the class hierarchy in descending order,
43 * i.e., the most specific visitXXX() call comes last.
44 *
45 * @param v Visitor object
46 */
47 public void accept( Visitor v ) {
48 v.visitTypedInstruction(this);
49 v.visitStackProducer(this);
50 v.visitStackConsumer(this);
51 v.visitFCMPL(this);
52 }
53 }
+0
-82
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FCONST.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FCONST - Push 0.0, 1.0 or 2.0, other values cause an exception
20 *
21 * <PRE>Stack: ... -&gt; ..., </PRE>
22 *
23 * @version $Id: FCONST.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class FCONST extends Instruction implements ConstantPushInstruction, TypedInstruction {
27
28 private float value;
29
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 FCONST() {
36 }
37
38
39 public FCONST(float f) {
40 super(org.apache.bcel.Constants.FCONST_0, (short) 1);
41 if (f == 0.0) {
42 opcode = org.apache.bcel.Constants.FCONST_0;
43 } else if (f == 1.0) {
44 opcode = org.apache.bcel.Constants.FCONST_1;
45 } else if (f == 2.0) {
46 opcode = org.apache.bcel.Constants.FCONST_2;
47 } else {
48 throw new ClassGenException("FCONST can be used only for 0.0, 1.0 and 2.0: " + f);
49 }
50 value = f;
51 }
52
53
54 public Number getValue() {
55 return new Float(value);
56 }
57
58
59 /** @return Type.FLOAT
60 */
61 public Type getType( ConstantPoolGen cp ) {
62 return Type.FLOAT;
63 }
64
65
66 /**
67 * Call corresponding visitor method(s). The order is:
68 * Call visitor methods of implemented interfaces first, then
69 * call methods according to the class hierarchy in descending order,
70 * i.e., the most specific visitXXX() call comes last.
71 *
72 * @param v Visitor object
73 */
74 public void accept( Visitor v ) {
75 v.visitPushInstruction(this);
76 v.visitStackProducer(this);
77 v.visitTypedInstruction(this);
78 v.visitConstantPushInstruction(this);
79 v.visitFCONST(this);
80 }
81 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FDIV.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FDIV - Divide floats
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: FDIV.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FDIV extends ArithmeticInstruction {
26
27 /** Divide floats
28 */
29 public FDIV() {
30 super(org.apache.bcel.Constants.FDIV);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitFDIV(this);
48 }
49 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FLOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FLOAD - Load float from local variable
20 * <PRE>Stack ... -&gt; ..., result</PRE>
21 *
22 * @version $Id: FLOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FLOAD extends LoadInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 FLOAD() {
32 super(org.apache.bcel.Constants.FLOAD, org.apache.bcel.Constants.FLOAD_0);
33 }
34
35
36 /** Load float from local variable
37 * @param n index of local variable
38 */
39 public FLOAD(int n) {
40 super(org.apache.bcel.Constants.FLOAD, org.apache.bcel.Constants.FLOAD_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitFLOAD(this);
55 }
56 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FMUL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FMUL - Multiply floats
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: FMUL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FMUL extends ArithmeticInstruction {
26
27 /** Multiply floats
28 */
29 public FMUL() {
30 super(org.apache.bcel.Constants.FMUL);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitFMUL(this);
48 }
49 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FNEG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FNEG - Negate float
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: FNEG.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FNEG extends ArithmeticInstruction {
26
27 public FNEG() {
28 super(org.apache.bcel.Constants.FNEG);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitFNEG(this);
46 }
47 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FREM.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FREM - Remainder of floats
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: FREM.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FREM extends ArithmeticInstruction {
26
27 /** Remainder of floats
28 */
29 public FREM() {
30 super(org.apache.bcel.Constants.FREM);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitFREM(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FRETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FRETURN - Return float from method
20 * <PRE>Stack: ..., value -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: FRETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FRETURN extends ReturnInstruction {
26
27 /** Return float from method
28 */
29 public FRETURN() {
30 super(org.apache.bcel.Constants.FRETURN);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitExceptionThrower(this);
44 v.visitTypedInstruction(this);
45 v.visitStackConsumer(this);
46 v.visitReturnInstruction(this);
47 v.visitFRETURN(this);
48 }
49 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FSTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FSTORE - Store float into local variable
20 * <PRE>Stack: ..., value -&gt; ... </PRE>
21 *
22 * @version $Id: FSTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FSTORE extends StoreInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 FSTORE() {
32 super(org.apache.bcel.Constants.FSTORE, org.apache.bcel.Constants.FSTORE_0);
33 }
34
35
36 /** Store float into local variable
37 * @param n index of local variable
38 */
39 public FSTORE(int n) {
40 super(org.apache.bcel.Constants.FSTORE, org.apache.bcel.Constants.FSTORE_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitFSTORE(this);
55 }
56 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FSUB.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * FSUB - Substract floats
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: FSUB.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class FSUB extends ArithmeticInstruction {
26
27 /** Substract floats
28 */
29 public FSUB() {
30 super(org.apache.bcel.Constants.FSUB);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitFSUB(this);
48 }
49 }
+0
-357
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FieldGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import org.apache.bcel.Constants;
22 import org.apache.bcel.classfile.Attribute;
23 import org.apache.bcel.classfile.Constant;
24 import org.apache.bcel.classfile.ConstantObject;
25 import org.apache.bcel.classfile.ConstantPool;
26 import org.apache.bcel.classfile.ConstantValue;
27 import org.apache.bcel.classfile.Field;
28 import org.apache.bcel.classfile.Utility;
29 import org.apache.bcel.util.BCELComparator;
30
31 /**
32 * Template class for building up a field. The only extraordinary thing
33 * one can do is to add a constant value attribute to a field (which must of
34 * course be compatible with to the declared type).
35 *
36 * @version $Id: FieldGen.java 386056 2006-03-15 11:31:56Z tcurdt $
37 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
38 * @see Field
39 */
40 public class FieldGen extends FieldGenOrMethodGen {
41
42 private Object value = null;
43 private static BCELComparator _cmp = new BCELComparator() {
44
45 public boolean equals( Object o1, Object o2 ) {
46 FieldGen THIS = (FieldGen) o1;
47 FieldGen THAT = (FieldGen) o2;
48 return THIS.getName().equals(THAT.getName())
49 && THIS.getSignature().equals(THAT.getSignature());
50 }
51
52
53 public int hashCode( Object o ) {
54 FieldGen THIS = (FieldGen) o;
55 return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
56 }
57 };
58
59
60 /**
61 * Declare a field. If it is static (isStatic() == true) and has a
62 * basic type like int or String it may have an initial value
63 * associated with it as defined by setInitValue().
64 *
65 * @param access_flags access qualifiers
66 * @param type field type
67 * @param name field name
68 * @param cp constant pool
69 */
70 public FieldGen(int access_flags, Type type, String name, ConstantPoolGen cp) {
71 setAccessFlags(access_flags);
72 setType(type);
73 setName(name);
74 setConstantPool(cp);
75 }
76
77
78 /**
79 * Instantiate from existing field.
80 *
81 * @param field Field object
82 * @param cp constant pool (must contain the same entries as the field's constant pool)
83 */
84 public FieldGen(Field field, ConstantPoolGen cp) {
85 this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
86 Attribute[] attrs = field.getAttributes();
87 for (int i = 0; i < attrs.length; i++) {
88 if (attrs[i] instanceof ConstantValue) {
89 setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
90 } else {
91 addAttribute(attrs[i]);
92 }
93 }
94 }
95
96
97 private void setValue( int index ) {
98 ConstantPool cp = this.cp.getConstantPool();
99 Constant c = cp.getConstant(index);
100 value = ((ConstantObject) c).getConstantValue(cp);
101 }
102
103
104 /**
105 * Set (optional) initial value of field, otherwise it will be set to null/0/false
106 * by the JVM automatically.
107 */
108 public void setInitValue( String str ) {
109 checkType( ObjectType.getInstance("java.lang.String"));
110 if (str != null) {
111 value = str;
112 }
113 }
114
115
116 public void setInitValue( long l ) {
117 checkType(Type.LONG);
118 if (l != 0L) {
119 value = new Long(l);
120 }
121 }
122
123
124 public void setInitValue( int i ) {
125 checkType(Type.INT);
126 if (i != 0) {
127 value = new Integer(i);
128 }
129 }
130
131
132 public void setInitValue( short s ) {
133 checkType(Type.SHORT);
134 if (s != 0) {
135 value = new Integer(s);
136 }
137 }
138
139
140 public void setInitValue( char c ) {
141 checkType(Type.CHAR);
142 if (c != 0) {
143 value = new Integer(c);
144 }
145 }
146
147
148 public void setInitValue( byte b ) {
149 checkType(Type.BYTE);
150 if (b != 0) {
151 value = new Integer(b);
152 }
153 }
154
155
156 public void setInitValue( boolean b ) {
157 checkType(Type.BOOLEAN);
158 if (b) {
159 value = new Integer(1);
160 }
161 }
162
163
164 public void setInitValue( float f ) {
165 checkType(Type.FLOAT);
166 if (f != 0.0) {
167 value = new Float(f);
168 }
169 }
170
171
172 public void setInitValue( double d ) {
173 checkType(Type.DOUBLE);
174 if (d != 0.0) {
175 value = new Double(d);
176 }
177 }
178
179
180 /** Remove any initial value.
181 */
182 public void cancelInitValue() {
183 value = null;
184 }
185
186
187 private void checkType( Type atype ) {
188 if (type == null) {
189 throw new ClassGenException("You haven't defined the type of the field yet");
190 }
191 if (!isFinal()) {
192 throw new ClassGenException("Only final fields may have an initial value!");
193 }
194 if (!type.equals(atype)) {
195 throw new ClassGenException("Types are not compatible: " + type + " vs. " + atype);
196 }
197 }
198
199
200 /**
201 * Get field object after having set up all necessary values.
202 */
203 public Field getField() {
204 String signature = getSignature();
205 int name_index = cp.addUtf8(name);
206 int signature_index = cp.addUtf8(signature);
207 if (value != null) {
208 checkType(type);
209 int index = addConstant();
210 addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp
211 .getConstantPool()));
212 }
213 return new Field(access_flags, name_index, signature_index, getAttributes(), cp
214 .getConstantPool());
215 }
216
217
218 private int addConstant() {
219 switch (type.getType()) {
220 case Constants.T_INT:
221 case Constants.T_CHAR:
222 case Constants.T_BYTE:
223 case Constants.T_BOOLEAN:
224 case Constants.T_SHORT:
225 return cp.addInteger(((Integer) value).intValue());
226 case Constants.T_FLOAT:
227 return cp.addFloat(((Float) value).floatValue());
228 case Constants.T_DOUBLE:
229 return cp.addDouble(((Double) value).doubleValue());
230 case Constants.T_LONG:
231 return cp.addLong(((Long) value).longValue());
232 case Constants.T_REFERENCE:
233 return cp.addString(((String) value));
234 default:
235 throw new RuntimeException("Oops: Unhandled : " + type.getType());
236 }
237 }
238
239
240 public String getSignature() {
241 return type.getSignature();
242 }
243
244 private List observers;
245
246
247 /** Add observer for this object.
248 */
249 public void addObserver( FieldObserver o ) {
250 if (observers == null) {
251 observers = new ArrayList();
252 }
253 observers.add(o);
254 }
255
256
257 /** Remove observer for this object.
258 */
259 public void removeObserver( FieldObserver o ) {
260 if (observers != null) {
261 observers.remove(o);
262 }
263 }
264
265
266 /** Call notify() method on all observers. This method is not called
267 * automatically whenever the state has changed, but has to be
268 * called by the user after he has finished editing the object.
269 */
270 public void update() {
271 if (observers != null) {
272 for (Iterator e = observers.iterator(); e.hasNext();) {
273 ((FieldObserver) e.next()).notify(this);
274 }
275 }
276 }
277
278
279 public String getInitValue() {
280 if (value != null) {
281 return value.toString();
282 } else {
283 return null;
284 }
285 }
286
287
288 /**
289 * Return string representation close to declaration format,
290 * `public static final short MAX = 100', e.g..
291 *
292 * @return String representation of field
293 */
294 public final String toString() {
295 String name, signature, access; // Short cuts to constant pool
296 access = Utility.accessToString(access_flags);
297 access = access.equals("") ? "" : (access + " ");
298 signature = type.toString();
299 name = getName();
300 StringBuffer buf = new StringBuffer(32);
301 buf.append(access).append(signature).append(" ").append(name);
302 String value = getInitValue();
303 if (value != null) {
304 buf.append(" = ").append(value);
305 }
306 return buf.toString();
307 }
308
309
310 /** @return deep copy of this field
311 */
312 public FieldGen copy( ConstantPoolGen cp ) {
313 FieldGen fg = (FieldGen) clone();
314 fg.setConstantPool(cp);
315 return fg;
316 }
317
318
319 /**
320 * @return Comparison strategy object
321 */
322 public static BCELComparator getComparator() {
323 return _cmp;
324 }
325
326
327 /**
328 * @param comparator Comparison strategy object
329 */
330 public static void setComparator( BCELComparator comparator ) {
331 _cmp = comparator;
332 }
333
334
335 /**
336 * Return value as defined by given BCELComparator strategy.
337 * By default two FieldGen objects are said to be equal when
338 * their names and signatures are equal.
339 *
340 * @see java.lang.Object#equals(java.lang.Object)
341 */
342 public boolean equals( Object obj ) {
343 return _cmp.equals(this, obj);
344 }
345
346
347 /**
348 * Return value as defined by given BCELComparator strategy.
349 * By default return the hashcode of the field's name XOR signature.
350 *
351 * @see java.lang.Object#hashCode()
352 */
353 public int hashCode() {
354 return _cmp.hashCode(this);
355 }
356 }
+0
-131
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FieldGenOrMethodGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.classfile.AccessFlags;
22 import org.apache.bcel.classfile.Attribute;
23
24 /**
25 * Super class for FieldGen and MethodGen objects, since they have
26 * some methods in common!
27 *
28 * @version $Id: FieldGenOrMethodGen.java 410087 2006-05-29 12:12:19Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAndTyped, Cloneable {
32
33 protected String name;
34 protected Type type;
35 protected ConstantPoolGen cp;
36 private List attribute_vec = new ArrayList();
37
38
39 protected FieldGenOrMethodGen() {
40 }
41
42
43 public void setType( Type type ) {
44 if (type.getType() == Constants.T_ADDRESS) {
45 throw new IllegalArgumentException("Type can not be " + type);
46 }
47 this.type = type;
48 }
49
50
51 public Type getType() {
52 return type;
53 }
54
55
56 /** @return name of method/field.
57 */
58 public String getName() {
59 return name;
60 }
61
62
63 public void setName( String name ) {
64 this.name = name;
65 }
66
67
68 public ConstantPoolGen getConstantPool() {
69 return cp;
70 }
71
72
73 public void setConstantPool( ConstantPoolGen cp ) {
74 this.cp = cp;
75 }
76
77
78 /**
79 * Add an attribute to this method. Currently, the JVM knows about
80 * the `Code', `ConstantValue', `Synthetic' and `Exceptions'
81 * attributes. Other attributes will be ignored by the JVM but do no
82 * harm.
83 *
84 * @param a attribute to be added
85 */
86 public void addAttribute( Attribute a ) {
87 attribute_vec.add(a);
88 }
89
90
91 /**
92 * Remove an attribute.
93 */
94 public void removeAttribute( Attribute a ) {
95 attribute_vec.remove(a);
96 }
97
98
99 /**
100 * Remove all attributes.
101 */
102 public void removeAttributes() {
103 attribute_vec.clear();
104 }
105
106
107 /**
108 * @return all attributes of this method.
109 */
110 public Attribute[] getAttributes() {
111 Attribute[] attributes = new Attribute[attribute_vec.size()];
112 attribute_vec.toArray(attributes);
113 return attributes;
114 }
115
116
117 /** @return signature of method/field.
118 */
119 public abstract String getSignature();
120
121
122 public Object clone() {
123 try {
124 return super.clone();
125 } catch (CloneNotSupportedException e) {
126 System.err.println(e);
127 return null;
128 }
129 }
130 }
+0
-80
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FieldInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.classfile.ConstantPool;
19
20 /**
21 * Super class for the GET/PUTxxx family of instructions.
22 *
23 * @version $Id: FieldInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public abstract class FieldInstruction extends FieldOrMethod implements TypedInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 FieldInstruction() {
33 }
34
35
36 /**
37 * @param index to constant pool
38 */
39 protected FieldInstruction(short opcode, int index) {
40 super(opcode, index);
41 }
42
43
44 /**
45 * @return mnemonic for instruction with symbolic references resolved
46 */
47 public String toString( ConstantPool cp ) {
48 return org.apache.bcel.Constants.OPCODE_NAMES[opcode] + " "
49 + cp.constantToString(index, org.apache.bcel.Constants.CONSTANT_Fieldref);
50 }
51
52
53 /** @return size of field (1 or 2)
54 */
55 protected int getFieldSize( ConstantPoolGen cpg ) {
56 return getType(cpg).getSize();
57 }
58
59
60 /** @return return type of referenced field
61 */
62 public Type getType( ConstantPoolGen cpg ) {
63 return getFieldType(cpg);
64 }
65
66
67 /** @return type of field
68 */
69 public Type getFieldType( ConstantPoolGen cpg ) {
70 return Type.getType(getSignature(cpg));
71 }
72
73
74 /** @return name of referenced field.
75 */
76 public String getFieldName( ConstantPoolGen cpg ) {
77 return getName(cpg);
78 }
79 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FieldObserver.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Imnplement this interface if you're interested in changes to a FieldGen object
20 * and register yourself with addObserver().
21 *
22 * @version $Id: FieldObserver.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface FieldObserver {
26
27 public void notify( FieldGen field );
28 }
+0
-128
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/FieldOrMethod.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.classfile.ConstantCP;
19 import org.apache.bcel.classfile.ConstantNameAndType;
20 import org.apache.bcel.classfile.ConstantPool;
21 import org.apache.bcel.classfile.ConstantUtf8;
22
23 /**
24 * Super class for InvokeInstruction and FieldInstruction, since they have
25 * some methods in common!
26 *
27 * @version $Id: FieldOrMethod.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public abstract class FieldOrMethod extends CPInstruction implements LoadClass {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 FieldOrMethod() {
37 }
38
39
40 /**
41 * @param index to constant pool
42 */
43 protected FieldOrMethod(short opcode, int index) {
44 super(opcode, index);
45 }
46
47
48 /** @return signature of referenced method/field.
49 */
50 public String getSignature( ConstantPoolGen cpg ) {
51 ConstantPool cp = cpg.getConstantPool();
52 ConstantCP cmr = (ConstantCP) cp.getConstant(index);
53 ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
54 return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
55 }
56
57
58 /** @return name of referenced method/field.
59 */
60 public String getName( ConstantPoolGen cpg ) {
61 ConstantPool cp = cpg.getConstantPool();
62 ConstantCP cmr = (ConstantCP) cp.getConstant(index);
63 ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
64 return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes();
65 }
66
67
68 /** @return name of the referenced class/interface
69 * @deprecated If the instruction references an array class,
70 * this method will return "java.lang.Object".
71 * For code generated by Java 1.5, this answer is
72 * sometimes wrong (e.g., if the "clone()" method is
73 * called on an array). A better idea is to use
74 * the getReferenceType() method, which correctly distinguishes
75 * between class types and array types.
76 */
77 public String getClassName( ConstantPoolGen cpg ) {
78 ConstantPool cp = cpg.getConstantPool();
79 ConstantCP cmr = (ConstantCP) cp.getConstant(index);
80 String className = cp.getConstantString(cmr.getClassIndex(),
81 org.apache.bcel.Constants.CONSTANT_Class);
82 if (className.startsWith("[")) {
83 // Turn array classes into java.lang.Object.
84 return "java.lang.Object";
85 }
86 return className.replace('/', '.');
87 }
88
89
90 /** @return type of the referenced class/interface
91 * @deprecated If the instruction references an array class,
92 * the ObjectType returned will be invalid. Use
93 * getReferenceType() instead.
94 */
95 public ObjectType getClassType( ConstantPoolGen cpg ) {
96 return ObjectType.getInstance(getClassName(cpg));
97 }
98
99
100 /**
101 * Return the reference type representing the class, interface,
102 * or array class referenced by the instruction.
103 * @param cpg the ConstantPoolGen used to create the instruction
104 * @return an ObjectType (if the referenced class type is a class
105 * or interface), or an ArrayType (if the referenced class
106 * type is an array class)
107 */
108 public ReferenceType getReferenceType( ConstantPoolGen cpg ) {
109 ConstantPool cp = cpg.getConstantPool();
110 ConstantCP cmr = (ConstantCP) cp.getConstant(index);
111 String className = cp.getConstantString(cmr.getClassIndex(),
112 org.apache.bcel.Constants.CONSTANT_Class);
113 if (className.startsWith("[")) {
114 return (ArrayType) Type.getType(className);
115 } else {
116 className = className.replace('/', '.');
117 return ObjectType.getInstance(className);
118 }
119 }
120
121
122 /** @return type of the referenced class/interface
123 */
124 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
125 return getClassType(cpg);
126 }
127 }
+0
-81
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/GETFIELD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * GETFIELD - Fetch field from object
23 * <PRE>Stack: ..., objectref -&gt; ..., value</PRE>
24 * OR
25 * <PRE>Stack: ..., objectref -&gt; ..., value.word1, value.word2</PRE>
26 *
27 * @version $Id: GETFIELD.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class GETFIELD extends FieldInstruction implements ExceptionThrower, StackConsumer,
31 StackProducer {
32
33 /**
34 * Empty constructor needed for the Class.newInstance() statement in
35 * Instruction.readInstruction(). Not to be used otherwise.
36 */
37 GETFIELD() {
38 }
39
40
41 public GETFIELD(int index) {
42 super(Constants.GETFIELD, index);
43 }
44
45
46 public int produceStack( ConstantPoolGen cpg ) {
47 return getFieldSize(cpg);
48 }
49
50
51 public Class[] getExceptions() {
52 Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
53 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
54 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
55 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
56 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
57 return cs;
58 }
59
60
61 /**
62 * Call corresponding visitor method(s). The order is:
63 * Call visitor methods of implemented interfaces first, then
64 * call methods according to the class hierarchy in descending order,
65 * i.e., the most specific visitXXX() call comes last.
66 *
67 * @param v Visitor object
68 */
69 public void accept( Visitor v ) {
70 v.visitExceptionThrower(this);
71 v.visitStackConsumer(this);
72 v.visitStackProducer(this);
73 v.visitTypedInstruction(this);
74 v.visitLoadClass(this);
75 v.visitCPInstruction(this);
76 v.visitFieldOrMethod(this);
77 v.visitFieldInstruction(this);
78 v.visitGETFIELD(this);
79 }
80 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/GETSTATIC.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * GETSTATIC - Fetch static field from class
23 * <PRE>Stack: ..., -&gt; ..., value</PRE>
24 * OR
25 * <PRE>Stack: ..., -&gt; ..., value.word1, value.word2</PRE>
26 *
27 * @version $Id: GETSTATIC.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class GETSTATIC extends FieldInstruction implements PushInstruction, ExceptionThrower {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 GETSTATIC() {
37 }
38
39
40 public GETSTATIC(int index) {
41 super(Constants.GETSTATIC, index);
42 }
43
44
45 public int produceStack( ConstantPoolGen cpg ) {
46 return getFieldSize(cpg);
47 }
48
49
50 public Class[] getExceptions() {
51 Class[] cs = new Class[1 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
52 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
53 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
54 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
55 return cs;
56 }
57
58
59 /**
60 * Call corresponding visitor method(s). The order is:
61 * Call visitor methods of implemented interfaces first, then
62 * call methods according to the class hierarchy in descending order,
63 * i.e., the most specific visitXXX() call comes last.
64 *
65 * @param v Visitor object
66 */
67 public void accept( Visitor v ) {
68 v.visitStackProducer(this);
69 v.visitPushInstruction(this);
70 v.visitExceptionThrower(this);
71 v.visitTypedInstruction(this);
72 v.visitLoadClass(this);
73 v.visitCPInstruction(this);
74 v.visitFieldOrMethod(this);
75 v.visitFieldInstruction(this);
76 v.visitGETSTATIC(this);
77 }
78 }
+0
-89
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/GOTO.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20
21 /**
22 * GOTO - Branch always (to relative offset, not absolute address)
23 *
24 * @version $Id: GOTO.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class GOTO extends GotoInstruction implements VariableLengthInstruction {
28
29 /**
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 GOTO() {
34 }
35
36
37 public GOTO(InstructionHandle target) {
38 super(org.apache.bcel.Constants.GOTO, target);
39 }
40
41
42 /**
43 * Dump instruction as byte code to stream out.
44 * @param out Output stream
45 */
46 public void dump( DataOutputStream out ) throws IOException {
47 index = getTargetOffset();
48 if (opcode == org.apache.bcel.Constants.GOTO) {
49 super.dump(out);
50 } else { // GOTO_W
51 index = getTargetOffset();
52 out.writeByte(opcode);
53 out.writeInt(index);
54 }
55 }
56
57
58 /** Called in pass 2 of InstructionList.setPositions() in order to update
59 * the branch target, that may shift due to variable length instructions.
60 */
61 protected int updatePosition( int offset, int max_offset ) {
62 int i = getTargetOffset(); // Depending on old position value
63 position += offset; // Position may be shifted by preceding expansions
64 if (Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
65 opcode = org.apache.bcel.Constants.GOTO_W;
66 length = 5;
67 return 2; // 5 - 3
68 }
69 return 0;
70 }
71
72
73 /**
74 * Call corresponding visitor method(s). The order is:
75 * Call visitor methods of implemented interfaces first, then
76 * call methods according to the class hierarchy in descending order,
77 * i.e., the most specific visitXXX() call comes last.
78 *
79 * @param v Visitor object
80 */
81 public void accept( Visitor v ) {
82 v.visitVariableLengthInstruction(this);
83 v.visitUnconditionalBranch(this);
84 v.visitBranchInstruction(this);
85 v.visitGotoInstruction(this);
86 v.visitGOTO(this);
87 }
88 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/GOTO_W.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * GOTO_W - Branch always (to relative offset, not absolute address)
24 *
25 * @version $Id: GOTO_W.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public class GOTO_W extends GotoInstruction {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 GOTO_W() {
35 }
36
37
38 public GOTO_W(InstructionHandle target) {
39 super(org.apache.bcel.Constants.GOTO_W, target);
40 length = 5;
41 }
42
43
44 /**
45 * Dump instruction as byte code to stream out.
46 * @param out Output stream
47 */
48 public void dump( DataOutputStream out ) throws IOException {
49 index = getTargetOffset();
50 out.writeByte(opcode);
51 out.writeInt(index);
52 }
53
54
55 /**
56 * Read needed data (e.g. index) from file.
57 */
58 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
59 index = bytes.readInt();
60 length = 5;
61 }
62
63
64 /**
65 * Call corresponding visitor method(s). The order is:
66 * Call visitor methods of implemented interfaces first, then
67 * call methods according to the class hierarchy in descending order,
68 * i.e., the most specific visitXXX() call comes last.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitUnconditionalBranch(this);
74 v.visitBranchInstruction(this);
75 v.visitGotoInstruction(this);
76 v.visitGOTO_W(this);
77 }
78 }
+0
-38
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/GotoInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Super class for GOTO
20 *
21 * @version $Id: GotoInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class GotoInstruction extends BranchInstruction implements UnconditionalBranch {
25
26 GotoInstruction(short opcode, InstructionHandle target) {
27 super(opcode, target);
28 }
29
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 GotoInstruction() {
36 }
37 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2B.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2B - Convert int to byte
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: I2B.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2B extends ConversionInstruction {
26
27 /** Convert int to byte
28 */
29 public I2B() {
30 super(org.apache.bcel.Constants.I2B);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitI2B(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2C.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2C - Convert int to char
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: I2C.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2C extends ConversionInstruction {
26
27 /** Convert int to char
28 */
29 public I2C() {
30 super(org.apache.bcel.Constants.I2C);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitI2C(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2D.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2D - Convert int to double
20 * <PRE>Stack: ..., value -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: I2D.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2D extends ConversionInstruction {
26
27 /** Convert int to double
28 */
29 public I2D() {
30 super(org.apache.bcel.Constants.I2D);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitI2D(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2F.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2F - Convert int to float
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: I2F.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2F extends ConversionInstruction {
26
27 /** Convert int to float
28 */
29 public I2F() {
30 super(org.apache.bcel.Constants.I2F);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitI2F(this);
48 }
49 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2L.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2L - Convert int to long
20 * <PRE>Stack: ..., value -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: I2L.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2L extends ConversionInstruction {
26
27 /** Convert int to long
28 */
29 public I2L() {
30 super(org.apache.bcel.Constants.I2L);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitConversionInstruction(this);
47 v.visitI2L(this);
48 }
49 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/I2S.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * I2S - Convert int to short
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: I2S.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class I2S extends ConversionInstruction {
26
27 public I2S() {
28 super(org.apache.bcel.Constants.I2S);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitConversionInstruction(this);
45 v.visitI2S(this);
46 }
47 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IADD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IADD - Add ints
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: IADD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IADD extends ArithmeticInstruction {
26
27 /** Add ints
28 */
29 public IADD() {
30 super(org.apache.bcel.Constants.IADD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitIADD(this);
48 }
49 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IALOAD - Load int from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
21 *
22 * @version $Id: IALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IALOAD extends ArrayInstruction implements StackProducer {
26
27 /**
28 * Load int from array
29 */
30 public IALOAD() {
31 super(org.apache.bcel.Constants.IALOAD);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitStackProducer(this);
45 v.visitExceptionThrower(this);
46 v.visitTypedInstruction(this);
47 v.visitArrayInstruction(this);
48 v.visitIALOAD(this);
49 }
50 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IAND.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IAND - Bitwise AND int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: IAND.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IAND extends ArithmeticInstruction {
26
27 public IAND() {
28 super(org.apache.bcel.Constants.IAND);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitIAND(this);
46 }
47 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IASTORE - Store into int array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: IASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IASTORE extends ArrayInstruction implements StackConsumer {
26
27 /**
28 * Store into int array
29 */
30 public IASTORE() {
31 super(org.apache.bcel.Constants.IASTORE);
32 }
33
34
35 /**
36 * Call corresponding visitor method(s). The order is:
37 * Call visitor methods of implemented interfaces first, then
38 * call methods according to the class hierarchy in descending order,
39 * i.e., the most specific visitXXX() call comes last.
40 *
41 * @param v Visitor object
42 */
43 public void accept( Visitor v ) {
44 v.visitStackConsumer(this);
45 v.visitExceptionThrower(this);
46 v.visitTypedInstruction(this);
47 v.visitArrayInstruction(this);
48 v.visitIASTORE(this);
49 }
50 }
+0
-78
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ICONST.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ICONST - Push value between -1, ..., 5, other values cause an exception
20 *
21 * <PRE>Stack: ... -&gt; ..., </PRE>
22 *
23 * @version $Id: ICONST.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class ICONST extends Instruction implements ConstantPushInstruction, TypedInstruction {
27
28 private int value;
29
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 ICONST() {
36 }
37
38
39 public ICONST(int i) {
40 super(org.apache.bcel.Constants.ICONST_0, (short) 1);
41 if ((i >= -1) && (i <= 5)) {
42 opcode = (short) (org.apache.bcel.Constants.ICONST_0 + i); // Even works for i == -1
43 } else {
44 throw new ClassGenException("ICONST can be used only for value between -1 and 5: " + i);
45 }
46 value = i;
47 }
48
49
50 public Number getValue() {
51 return new Integer(value);
52 }
53
54
55 /** @return Type.INT
56 */
57 public Type getType( ConstantPoolGen cp ) {
58 return Type.INT;
59 }
60
61
62 /**
63 * Call corresponding visitor method(s). The order is:
64 * Call visitor methods of implemented interfaces first, then
65 * call methods according to the class hierarchy in descending order,
66 * i.e., the most specific visitXXX() call comes last.
67 *
68 * @param v Visitor object
69 */
70 public void accept( Visitor v ) {
71 v.visitPushInstruction(this);
72 v.visitStackProducer(this);
73 v.visitTypedInstruction(this);
74 v.visitConstantPushInstruction(this);
75 v.visitICONST(this);
76 }
77 }
+0
-60
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IDIV.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IDIV - Divide ints
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: IDIV.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IDIV extends ArithmeticInstruction implements ExceptionThrower {
26
27 /** Divide ints
28 */
29 public IDIV() {
30 super(org.apache.bcel.Constants.IDIV);
31 }
32
33
34 /** @return exceptions this instruction may cause
35 */
36 public Class[] getExceptions() {
37 return new Class[] {
38 org.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION
39 };
40 }
41
42
43 /**
44 * Call corresponding visitor method(s). The order is:
45 * Call visitor methods of implemented interfaces first, then
46 * call methods according to the class hierarchy in descending order,
47 * i.e., the most specific visitXXX() call comes last.
48 *
49 * @param v Visitor object
50 */
51 public void accept( Visitor v ) {
52 v.visitExceptionThrower(this);
53 v.visitTypedInstruction(this);
54 v.visitStackProducer(this);
55 v.visitStackConsumer(this);
56 v.visitArithmeticInstruction(this);
57 v.visitIDIV(this);
58 }
59 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFEQ.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFEQ - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFEQ.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFEQ extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFEQ() {
33 }
34
35
36 public IFEQ(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFEQ, target);
38 }
39
40
41 /**
42 * @return negation of instruction, e.g. IFEQ.negate() == IFNE
43 */
44 public IfInstruction negate() {
45 return new IFNE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFEQ(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFGE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFGE - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFGE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFGE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFGE() {
33 }
34
35
36 public IFGE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFGE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFLT(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFGE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFGT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFGT - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFGT.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFGT extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFGT() {
33 }
34
35
36 public IFGT(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFGT, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFLE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFGT(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFLE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFLE - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFLE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFLE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFLE() {
33 }
34
35
36 public IFLE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFLE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFGT(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFLE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFLT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFLT - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFLT.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFLT extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFLT() {
33 }
34
35
36 public IFLT(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFLT, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFGE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFLT(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFNE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFNE - Branch if int comparison with zero succeeds
20 *
21 * <PRE>Stack: ..., value -&gt; ...</PRE>
22 *
23 * @version $Id: IFNE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFNE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFNE() {
33 }
34
35
36 public IFNE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFNE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFEQ(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFNE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFNONNULL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFNONNULL - Branch if reference is not null
20 *
21 * <PRE>Stack: ..., reference -&gt; ...</PRE>
22 *
23 * @version $Id: IFNONNULL.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFNONNULL extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFNONNULL() {
33 }
34
35
36 public IFNONNULL(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFNONNULL, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFNULL(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFNONNULL(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IFNULL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IFNULL - Branch if reference is not null
20 *
21 * <PRE>Stack: ..., reference -&gt; ...</PRE>
22 *
23 * @version $Id: IFNULL.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IFNULL extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IFNULL() {
33 }
34
35
36 public IFNULL(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IFNULL, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IFNONNULL(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIFNULL(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ACMPEQ.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ACMPEQ - Branch if reference comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ACMPEQ.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ACMPEQ extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ACMPEQ() {
33 }
34
35
36 public IF_ACMPEQ(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ACMPEQ, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ACMPNE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ACMPEQ(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ACMPNE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ACMPNE - Branch if reference comparison doesn't succeed
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ACMPNE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ACMPNE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ACMPNE() {
33 }
34
35
36 public IF_ACMPNE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ACMPNE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ACMPEQ(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ACMPNE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPEQ.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPEQ - Branch if int comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPEQ.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPEQ extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPEQ() {
33 }
34
35
36 public IF_ICMPEQ(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPEQ, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPNE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPEQ(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPGE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPGE - Branch if int comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPGE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPGE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPGE() {
33 }
34
35
36 public IF_ICMPGE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPGE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPLT(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPGE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPGT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPGT - Branch if int comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPGT.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPGT extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPGT() {
33 }
34
35
36 public IF_ICMPGT(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPGT, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPLE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPGT(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPLE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPLE - Branch if int comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPLE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPLE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPLE() {
33 }
34
35
36 public IF_ICMPLE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPLE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPGT(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPLE(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPLT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPLT - Branch if int comparison succeeds
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPLT.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPLT extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPLT() {
33 }
34
35
36 public IF_ICMPLT(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPLT, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPGE(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPLT(this);
62 }
63 }
+0
-64
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IF_ICMPNE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IF_ICMPNE - Branch if int comparison doesn't succeed
20 *
21 * <PRE>Stack: ..., value1, value2 -&gt; ...</PRE>
22 *
23 * @version $Id: IF_ICMPNE.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class IF_ICMPNE extends IfInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 IF_ICMPNE() {
33 }
34
35
36 public IF_ICMPNE(InstructionHandle target) {
37 super(org.apache.bcel.Constants.IF_ICMPNE, target);
38 }
39
40
41 /**
42 * @return negation of instruction
43 */
44 public IfInstruction negate() {
45 return new IF_ICMPEQ(target);
46 }
47
48
49 /**
50 * Call corresponding visitor method(s). The order is:
51 * Call visitor methods of implemented interfaces first, then
52 * call methods according to the class hierarchy in descending order,
53 * i.e., the most specific visitXXX() call comes last.
54 *
55 * @param v Visitor object
56 */
57 public void accept( Visitor v ) {
58 v.visitStackConsumer(this);
59 v.visitBranchInstruction(this);
60 v.visitIfInstruction(this);
61 v.visitIF_ICMPNE(this);
62 }
63 }
+0
-158
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IINC.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * IINC - Increment local variable by constant
24 *
25 * @version $Id: IINC.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public class IINC extends LocalVariableInstruction {
29
30 private boolean wide;
31 private int c;
32
33
34 /**
35 * Empty constructor needed for the Class.newInstance() statement in
36 * Instruction.readInstruction(). Not to be used otherwise.
37 */
38 IINC() {
39 }
40
41
42 /**
43 * @param n index of local variable
44 * @param c increment factor
45 */
46 public IINC(int n, int c) {
47 super(); // Default behaviour of LocalVariableInstruction causes error
48 this.opcode = org.apache.bcel.Constants.IINC;
49 this.length = (short) 3;
50 setIndex(n); // May set wide as side effect
51 setIncrement(c);
52 }
53
54
55 /**
56 * Dump instruction as byte code to stream out.
57 * @param out Output stream
58 */
59 public void dump( DataOutputStream out ) throws IOException {
60 if (wide) {
61 out.writeByte(org.apache.bcel.Constants.WIDE);
62 }
63 out.writeByte(opcode);
64 if (wide) {
65 out.writeShort(n);
66 out.writeShort(c);
67 } else {
68 out.writeByte(n);
69 out.writeByte(c);
70 }
71 }
72
73
74 private final void setWide() {
75 wide = (n > org.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE);
76 if (wide) {
77 length = 6; // wide byte included
78 } else {
79 length = 3;
80 }
81 }
82
83
84 /**
85 * Read needed data (e.g. index) from file.
86 */
87 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
88 this.wide = wide;
89 if (wide) {
90 length = 6;
91 n = bytes.readUnsignedShort();
92 c = bytes.readShort();
93 } else {
94 length = 3;
95 n = bytes.readUnsignedByte();
96 c = bytes.readByte();
97 }
98 }
99
100
101 /**
102 * @return mnemonic for instruction
103 */
104 public String toString( boolean verbose ) {
105 return super.toString(verbose) + " " + c;
106 }
107
108
109 /**
110 * Set index of local variable.
111 */
112 public final void setIndex( int n ) {
113 if (n < 0) {
114 throw new ClassGenException("Negative index value: " + n);
115 }
116 this.n = n;
117 setWide();
118 }
119
120
121 /**
122 * @return increment factor
123 */
124 public final int getIncrement() {
125 return c;
126 }
127
128
129 /**
130 * Set increment factor.
131 */
132 public final void setIncrement( int c ) {
133 this.c = c;
134 setWide();
135 }
136
137
138 /** @return int type
139 */
140 public Type getType( ConstantPoolGen cp ) {
141 return Type.INT;
142 }
143
144
145 /**
146 * Call corresponding visitor method(s). The order is:
147 * Call visitor methods of implemented interfaces first, then
148 * call methods according to the class hierarchy in descending order,
149 * i.e., the most specific visitXXX() call comes last.
150 *
151 * @param v Visitor object
152 */
153 public void accept( Visitor v ) {
154 v.visitLocalVariableInstruction(this);
155 v.visitIINC(this);
156 }
157 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ILOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ILOAD - Load int from local variable onto stack
20 * <PRE>Stack: ... -&gt; ..., result</PRE>
21 *
22 * @version $Id: ILOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ILOAD extends LoadInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 ILOAD() {
32 super(org.apache.bcel.Constants.ILOAD, org.apache.bcel.Constants.ILOAD_0);
33 }
34
35
36 /** Load int from local variable
37 * @param n index of local variable
38 */
39 public ILOAD(int n) {
40 super(org.apache.bcel.Constants.ILOAD, org.apache.bcel.Constants.ILOAD_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitILOAD(this);
55 }
56 }
+0
-43
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IMPDEP1.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IMPDEP1 - Implementation dependent
20 *
21 * @version $Id: IMPDEP1.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public class IMPDEP1 extends Instruction {
25
26 public IMPDEP1() {
27 super(org.apache.bcel.Constants.IMPDEP1, (short) 1);
28 }
29
30
31 /**
32 * Call corresponding visitor method(s). The order is:
33 * Call visitor methods of implemented interfaces first, then
34 * call methods according to the class hierarchy in descending order,
35 * i.e., the most specific visitXXX() call comes last.
36 *
37 * @param v Visitor object
38 */
39 public void accept( Visitor v ) {
40 v.visitIMPDEP1(this);
41 }
42 }
+0
-43
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IMPDEP2.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IMPDEP2 - Implementation dependent
20 *
21 * @version $Id: IMPDEP2.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public class IMPDEP2 extends Instruction {
25
26 public IMPDEP2() {
27 super(org.apache.bcel.Constants.IMPDEP2, (short) 1);
28 }
29
30
31 /**
32 * Call corresponding visitor method(s). The order is:
33 * Call visitor methods of implemented interfaces first, then
34 * call methods according to the class hierarchy in descending order,
35 * i.e., the most specific visitXXX() call comes last.
36 *
37 * @param v Visitor object
38 */
39 public void accept( Visitor v ) {
40 v.visitIMPDEP2(this);
41 }
42 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IMUL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IMUL - Multiply ints
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: IMUL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IMUL extends ArithmeticInstruction {
26
27 /** Multiply ints
28 */
29 public IMUL() {
30 super(org.apache.bcel.Constants.IMUL);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitIMUL(this);
48 }
49 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INEG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * INEG - Negate int
20 * <PRE>Stack: ..., value -&gt; ..., result</PRE>
21 *
22 * @version $Id: INEG.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class INEG extends ArithmeticInstruction {
26
27 public INEG() {
28 super(org.apache.bcel.Constants.INEG);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitINEG(this);
46 }
47 }
+0
-73
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INSTANCEOF.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * INSTANCEOF - Determine if object is of given type
20 * <PRE>Stack: ..., objectref -&gt; ..., result</PRE>
21 *
22 * @version $Id: INSTANCEOF.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class INSTANCEOF extends CPInstruction implements LoadClass, ExceptionThrower,
26 StackProducer, StackConsumer {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 INSTANCEOF() {
33 }
34
35
36 public INSTANCEOF(int index) {
37 super(org.apache.bcel.Constants.INSTANCEOF, index);
38 }
39
40
41 public Class[] getExceptions() {
42 return org.apache.bcel.ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION;
43 }
44
45
46 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
47 Type t = getType(cpg);
48 if (t instanceof ArrayType) {
49 t = ((ArrayType) t).getBasicType();
50 }
51 return (t instanceof ObjectType) ? (ObjectType) t : null;
52 }
53
54
55 /**
56 * Call corresponding visitor method(s). The order is:
57 * Call visitor methods of implemented interfaces first, then
58 * call methods according to the class hierarchy in descending order,
59 * i.e., the most specific visitXXX() call comes last.
60 *
61 * @param v Visitor object
62 */
63 public void accept( Visitor v ) {
64 v.visitLoadClass(this);
65 v.visitExceptionThrower(this);
66 v.visitStackProducer(this);
67 v.visitStackConsumer(this);
68 v.visitTypedInstruction(this);
69 v.visitCPInstruction(this);
70 v.visitINSTANCEOF(this);
71 }
72 }
+0
-132
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INVOKEINTERFACE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.ExceptionConstants;
22 import org.apache.bcel.classfile.ConstantPool;
23 import org.apache.bcel.util.ByteSequence;
24
25 /**
26 * INVOKEINTERFACE - Invoke interface method
27 * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
28 *
29 * @version $Id: INVOKEINTERFACE.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 */
32 public final class INVOKEINTERFACE extends InvokeInstruction {
33
34 private int nargs; // Number of arguments on stack (number of stack slots), called "count" in vmspec2
35
36
37 /**
38 * Empty constructor needed for the Class.newInstance() statement in
39 * Instruction.readInstruction(). Not to be used otherwise.
40 */
41 INVOKEINTERFACE() {
42 }
43
44
45 public INVOKEINTERFACE(int index, int nargs) {
46 super(Constants.INVOKEINTERFACE, index);
47 length = 5;
48 if (nargs < 1) {
49 throw new ClassGenException("Number of arguments must be > 0 " + nargs);
50 }
51 this.nargs = nargs;
52 }
53
54
55 /**
56 * Dump instruction as byte code to stream out.
57 * @param out Output stream
58 */
59 public void dump( DataOutputStream out ) throws IOException {
60 out.writeByte(opcode);
61 out.writeShort(index);
62 out.writeByte(nargs);
63 out.writeByte(0);
64 }
65
66
67 /**
68 * The <B>count</B> argument according to the Java Language Specification,
69 * Second Edition.
70 */
71 public int getCount() {
72 return nargs;
73 }
74
75
76 /**
77 * Read needed data (i.e., index) from file.
78 */
79 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
80 super.initFromFile(bytes, wide);
81 length = 5;
82 nargs = bytes.readUnsignedByte();
83 bytes.readByte(); // Skip 0 byte
84 }
85
86
87 /**
88 * @return mnemonic for instruction with symbolic references resolved
89 */
90 public String toString( ConstantPool cp ) {
91 return super.toString(cp) + " " + nargs;
92 }
93
94
95 public int consumeStack( ConstantPoolGen cpg ) { // nargs is given in byte-code
96 return nargs; // nargs includes this reference
97 }
98
99
100 public Class[] getExceptions() {
101 Class[] cs = new Class[4 + ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length];
102 System.arraycopy(ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION, 0, cs, 0,
103 ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length);
104 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 3] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
105 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 2] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
106 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 1] = ExceptionConstants.ABSTRACT_METHOD_ERROR;
107 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length] = ExceptionConstants.UNSATISFIED_LINK_ERROR;
108 return cs;
109 }
110
111
112 /**
113 * Call corresponding visitor method(s). The order is:
114 * Call visitor methods of implemented interfaces first, then
115 * call methods according to the class hierarchy in descending order,
116 * i.e., the most specific visitXXX() call comes last.
117 *
118 * @param v Visitor object
119 */
120 public void accept( Visitor v ) {
121 v.visitExceptionThrower(this);
122 v.visitTypedInstruction(this);
123 v.visitStackConsumer(this);
124 v.visitStackProducer(this);
125 v.visitLoadClass(this);
126 v.visitCPInstruction(this);
127 v.visitFieldOrMethod(this);
128 v.visitInvokeInstruction(this);
129 v.visitINVOKEINTERFACE(this);
130 }
131 }
+0
-77
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INVOKESPECIAL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * INVOKESPECIAL - Invoke instance method; special handling for superclass, private
23 * and instance initialization method invocations
24 *
25 * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
26 *
27 * @version $Id: INVOKESPECIAL.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class INVOKESPECIAL extends InvokeInstruction {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 INVOKESPECIAL() {
37 }
38
39
40 public INVOKESPECIAL(int index) {
41 super(Constants.INVOKESPECIAL, index);
42 }
43
44
45 public Class[] getExceptions() {
46 Class[] cs = new Class[4 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
47 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
48 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
49 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 3] = ExceptionConstants.UNSATISFIED_LINK_ERROR;
50 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 2] = ExceptionConstants.ABSTRACT_METHOD_ERROR;
51 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
52 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
53 return cs;
54 }
55
56
57 /**
58 * Call corresponding visitor method(s). The order is:
59 * Call visitor methods of implemented interfaces first, then
60 * call methods according to the class hierarchy in descending order,
61 * i.e., the most specific visitXXX() call comes last.
62 *
63 * @param v Visitor object
64 */
65 public void accept( Visitor v ) {
66 v.visitExceptionThrower(this);
67 v.visitTypedInstruction(this);
68 v.visitStackConsumer(this);
69 v.visitStackProducer(this);
70 v.visitLoadClass(this);
71 v.visitCPInstruction(this);
72 v.visitFieldOrMethod(this);
73 v.visitInvokeInstruction(this);
74 v.visitINVOKESPECIAL(this);
75 }
76 }
+0
-74
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INVOKESTATIC.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * INVOKESTATIC - Invoke a class (static) method
23 *
24 * <PRE>Stack: ..., [arg1, [arg2 ...]] -&gt; ...</PRE>
25 *
26 * @version $Id: INVOKESTATIC.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public class INVOKESTATIC extends InvokeInstruction {
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 INVOKESTATIC() {
36 }
37
38
39 public INVOKESTATIC(int index) {
40 super(Constants.INVOKESTATIC, index);
41 }
42
43
44 public Class[] getExceptions() {
45 Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
46 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
47 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
48 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.UNSATISFIED_LINK_ERROR;
49 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
50 return cs;
51 }
52
53
54 /**
55 * Call corresponding visitor method(s). The order is:
56 * Call visitor methods of implemented interfaces first, then
57 * call methods according to the class hierarchy in descending order,
58 * i.e., the most specific visitXXX() call comes last.
59 *
60 * @param v Visitor object
61 */
62 public void accept( Visitor v ) {
63 v.visitExceptionThrower(this);
64 v.visitTypedInstruction(this);
65 v.visitStackConsumer(this);
66 v.visitStackProducer(this);
67 v.visitLoadClass(this);
68 v.visitCPInstruction(this);
69 v.visitFieldOrMethod(this);
70 v.visitInvokeInstruction(this);
71 v.visitINVOKESTATIC(this);
72 }
73 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/INVOKEVIRTUAL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * INVOKEVIRTUAL - Invoke instance method; dispatch based on class
23 *
24 * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
25 *
26 * @version $Id: INVOKEVIRTUAL.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public class INVOKEVIRTUAL extends InvokeInstruction {
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 INVOKEVIRTUAL() {
36 }
37
38
39 public INVOKEVIRTUAL(int index) {
40 super(Constants.INVOKEVIRTUAL, index);
41 }
42
43
44 public Class[] getExceptions() {
45 Class[] cs = new Class[4 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
46 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
47 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
48 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 3] = ExceptionConstants.UNSATISFIED_LINK_ERROR;
49 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 2] = ExceptionConstants.ABSTRACT_METHOD_ERROR;
50 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
51 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
52 return cs;
53 }
54
55
56 /**
57 * Call corresponding visitor method(s). The order is:
58 * Call visitor methods of implemented interfaces first, then
59 * call methods according to the class hierarchy in descending order,
60 * i.e., the most specific visitXXX() call comes last.
61 *
62 * @param v Visitor object
63 */
64 public void accept( Visitor v ) {
65 v.visitExceptionThrower(this);
66 v.visitTypedInstruction(this);
67 v.visitStackConsumer(this);
68 v.visitStackProducer(this);
69 v.visitLoadClass(this);
70 v.visitCPInstruction(this);
71 v.visitFieldOrMethod(this);
72 v.visitInvokeInstruction(this);
73 v.visitINVOKEVIRTUAL(this);
74 }
75 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IOR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IOR - Bitwise OR int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: IOR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IOR extends ArithmeticInstruction {
26
27 public IOR() {
28 super(org.apache.bcel.Constants.IOR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitIOR(this);
46 }
47 }
+0
-60
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IREM.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IREM - Remainder of int
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: IREM.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IREM extends ArithmeticInstruction implements ExceptionThrower {
26
27 /** Remainder of ints
28 */
29 public IREM() {
30 super(org.apache.bcel.Constants.IREM);
31 }
32
33
34 /** @return exceptions this instruction may cause
35 */
36 public Class[] getExceptions() {
37 return new Class[] {
38 org.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION
39 };
40 }
41
42
43 /**
44 * Call corresponding visitor method(s). The order is:
45 * Call visitor methods of implemented interfaces first, then
46 * call methods according to the class hierarchy in descending order,
47 * i.e., the most specific visitXXX() call comes last.
48 *
49 * @param v Visitor object
50 */
51 public void accept( Visitor v ) {
52 v.visitExceptionThrower(this);
53 v.visitTypedInstruction(this);
54 v.visitStackProducer(this);
55 v.visitStackConsumer(this);
56 v.visitArithmeticInstruction(this);
57 v.visitIREM(this);
58 }
59 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IRETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IRETURN - Return int from method
20 * <PRE>Stack: ..., value -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: IRETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IRETURN extends ReturnInstruction {
26
27 /** Return int from method
28 */
29 public IRETURN() {
30 super(org.apache.bcel.Constants.IRETURN);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitExceptionThrower(this);
44 v.visitTypedInstruction(this);
45 v.visitStackConsumer(this);
46 v.visitReturnInstruction(this);
47 v.visitIRETURN(this);
48 }
49 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ISHL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ISHL - Arithmetic shift left int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: ISHL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ISHL extends ArithmeticInstruction {
26
27 public ISHL() {
28 super(org.apache.bcel.Constants.ISHL);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitISHL(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ISHR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ISHR - Arithmetic shift right int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: ISHR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ISHR extends ArithmeticInstruction {
26
27 public ISHR() {
28 super(org.apache.bcel.Constants.ISHR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitISHR(this);
46 }
47 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ISTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ISTORE - Store int from stack into local variable
20 * <PRE>Stack: ..., value -&gt; ... </PRE>
21 *
22 * @version $Id: ISTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ISTORE extends StoreInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 ISTORE() {
32 super(org.apache.bcel.Constants.ISTORE, org.apache.bcel.Constants.ISTORE_0);
33 }
34
35
36 /** Store int into local variable
37 * @param n index of local variable
38 */
39 public ISTORE(int n) {
40 super(org.apache.bcel.Constants.ISTORE, org.apache.bcel.Constants.ISTORE_0, n);
41 }
42
43
44 /**
45 * Call corresponding visitor method(s). The order is:
46 * Call visitor methods of implemented interfaces first, then
47 * call methods according to the class hierarchy in descending order,
48 * i.e., the most specific visitXXX() call comes last.
49 *
50 * @param v Visitor object
51 */
52 public void accept( Visitor v ) {
53 super.accept(v);
54 v.visitISTORE(this);
55 }
56 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ISUB.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * ISUB - Substract ints
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: ISUB.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class ISUB extends ArithmeticInstruction {
26
27 /** Substract ints
28 */
29 public ISUB() {
30 super(org.apache.bcel.Constants.ISUB);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitTypedInstruction(this);
44 v.visitStackProducer(this);
45 v.visitStackConsumer(this);
46 v.visitArithmeticInstruction(this);
47 v.visitISUB(this);
48 }
49 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IUSHR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IUSHR - Logical shift right int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: IUSHR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IUSHR extends ArithmeticInstruction {
26
27 public IUSHR() {
28 super(org.apache.bcel.Constants.IUSHR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitIUSHR(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IXOR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * IXOR - Bitwise XOR int
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: IXOR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class IXOR extends ArithmeticInstruction {
26
27 public IXOR() {
28 super(org.apache.bcel.Constants.IXOR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitIXOR(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IfInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Super class for the IFxxx family of instructions.
20 *
21 * @version $Id: IfInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class IfInstruction extends BranchInstruction implements StackConsumer {
25
26 /**
27 * Empty constructor needed for the Class.newInstance() statement in
28 * Instruction.readInstruction(). Not to be used otherwise.
29 */
30 IfInstruction() {
31 }
32
33
34 /**
35 * @param opcode opcode of instruction
36 * @param target Target instruction to branch to
37 */
38 protected IfInstruction(short opcode, InstructionHandle target) {
39 super(opcode, target);
40 }
41
42
43 /**
44 * @return negation of instruction, e.g. IFEQ.negate() == IFNE
45 */
46 public abstract IfInstruction negate();
47 }
+0
-32
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/IndexedInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote entity that refers to an index, e.g. local variable instructions,
20 * RET, CPInstruction, etc.
21 *
22 * @version $Id: IndexedInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface IndexedInstruction {
26
27 public int getIndex();
28
29
30 public void setIndex( int index );
31 }
+0
-292
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/Instruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import java.io.Serializable;
21 import java.util.Locale;
22 import org.apache.bcel.Constants;
23 import org.apache.bcel.classfile.ConstantPool;
24 import org.apache.bcel.util.ByteSequence;
25
26 /**
27 * Abstract super class for all Java byte codes.
28 *
29 * @version $Id: Instruction.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 */
32 public abstract class Instruction implements Cloneable, Serializable {
33
34 protected short length = 1; // Length of instruction in bytes
35 protected short opcode = -1; // Opcode number
36 private static InstructionComparator cmp = InstructionComparator.DEFAULT;
37
38
39 /**
40 * Empty constructor needed for the Class.newInstance() statement in
41 * Instruction.readInstruction(). Not to be used otherwise.
42 */
43 Instruction() {
44 }
45
46
47 public Instruction(short opcode, short length) {
48 this.length = length;
49 this.opcode = opcode;
50 }
51
52
53 /**
54 * Dump instruction as byte code to stream out.
55 * @param out Output stream
56 */
57 public void dump( DataOutputStream out ) throws IOException {
58 out.writeByte(opcode); // Common for all instructions
59 }
60
61
62 /** @return name of instruction, i.e., opcode name
63 */
64 public String getName() {
65 return Constants.OPCODE_NAMES[opcode];
66 }
67
68
69 /**
70 * Long output format:
71 *
72 * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
73 * "("&lt;length of instruction&gt;")"
74 *
75 * @param verbose long/short format switch
76 * @return mnemonic for instruction
77 */
78 public String toString( boolean verbose ) {
79 if (verbose) {
80 return getName() + "[" + opcode + "](" + length + ")";
81 } else {
82 return getName();
83 }
84 }
85
86
87 /**
88 * @return mnemonic for instruction in verbose format
89 */
90 public String toString() {
91 return toString(true);
92 }
93
94
95 /**
96 * @return mnemonic for instruction with sumbolic references resolved
97 */
98 public String toString( ConstantPool cp ) {
99 return toString(false);
100 }
101
102
103 /**
104 * Use with caution, since `BranchInstruction's have a `target' reference which
105 * is not copied correctly (only basic types are). This also applies for
106 * `Select' instructions with their multiple branch targets.
107 *
108 * @see BranchInstruction
109 * @return (shallow) copy of an instruction
110 */
111 public Instruction copy() {
112 Instruction i = null;
113 // "Constant" instruction, no need to duplicate
114 if (InstructionConstants.INSTRUCTIONS[this.getOpcode()] != null) {
115 i = this;
116 } else {
117 try {
118 i = (Instruction) clone();
119 } catch (CloneNotSupportedException e) {
120 System.err.println(e);
121 }
122 }
123 return i;
124 }
125
126
127 /**
128 * Read needed data (e.g. index) from file.
129 *
130 * @param bytes byte sequence to read from
131 * @param wide "wide" instruction flag
132 */
133 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
134 }
135
136
137 /**
138 * Read an instruction from (byte code) input stream and return the
139 * appropiate object.
140 *
141 * @param bytes input stream bytes
142 * @return instruction object being read
143 */
144 public static final Instruction readInstruction( ByteSequence bytes ) throws IOException {
145 boolean wide = false;
146 short opcode = (short) bytes.readUnsignedByte();
147 Instruction obj = null;
148 if (opcode == Constants.WIDE) { // Read next opcode after wide byte
149 wide = true;
150 opcode = (short) bytes.readUnsignedByte();
151 }
152 if (InstructionConstants.INSTRUCTIONS[opcode] != null) {
153 return InstructionConstants.INSTRUCTIONS[opcode]; // Used predefined immutable object, if available
154 }
155 /* Find appropiate class, instantiate an (empty) instruction object
156 * and initialize it by hand.
157 */
158 Class clazz;
159 try {
160 clazz = Class.forName(className(opcode));
161 } catch (ClassNotFoundException cnfe) {
162 // If a class by that name does not exist, the opcode is illegal.
163 // Note that IMPDEP1, IMPDEP2, BREAKPOINT are also illegal in a sense.
164 throw new ClassGenException("Illegal opcode detected.");
165 }
166 try {
167 obj = (Instruction) clazz.newInstance();
168 if (wide
169 && !((obj instanceof LocalVariableInstruction) || (obj instanceof IINC) || (obj instanceof RET))) {
170 throw new Exception("Illegal opcode after wide: " + opcode);
171 }
172 obj.setOpcode(opcode);
173 obj.initFromFile(bytes, wide); // Do further initializations, if any
174 // Byte code offset set in InstructionList
175 } catch (Exception e) {
176 throw new ClassGenException(e.toString());
177 }
178 return obj;
179 }
180
181
182 private static final String className( short opcode ) {
183 String name = Constants.OPCODE_NAMES[opcode].toUpperCase(Locale.ENGLISH);
184 /* ICONST_0, etc. will be shortened to ICONST, etc., since ICONST_0 and the like
185 * are not implemented (directly).
186 */
187 try {
188 int len = name.length();
189 char ch1 = name.charAt(len - 2), ch2 = name.charAt(len - 1);
190 if ((ch1 == '_') && (ch2 >= '0') && (ch2 <= '5')) {
191 name = name.substring(0, len - 2);
192 }
193 if (name.equals("ICONST_M1")) {
194 name = "ICONST";
195 }
196 } catch (StringIndexOutOfBoundsException e) {
197 System.err.println(e);
198 }
199 return "org.apache.bcel.generic." + name;
200 }
201
202
203 /**
204 * This method also gives right results for instructions whose
205 * effect on the stack depends on the constant pool entry they
206 * reference.
207 * @return Number of words consumed from stack by this instruction,
208 * or Constants.UNPREDICTABLE, if this can not be computed statically
209 */
210 public int consumeStack( ConstantPoolGen cpg ) {
211 return Constants.CONSUME_STACK[opcode];
212 }
213
214
215 /**
216 * This method also gives right results for instructions whose
217 * effect on the stack depends on the constant pool entry they
218 * reference.
219 * @return Number of words produced onto stack by this instruction,
220 * or Constants.UNPREDICTABLE, if this can not be computed statically
221 */
222 public int produceStack( ConstantPoolGen cpg ) {
223 return Constants.PRODUCE_STACK[opcode];
224 }
225
226
227 /**
228 * @return this instructions opcode
229 */
230 public short getOpcode() {
231 return opcode;
232 }
233
234
235 /**
236 * @return length (in bytes) of instruction
237 */
238 public int getLength() {
239 return length;
240 }
241
242
243 /**
244 * Needed in readInstruction.
245 */
246 private void setOpcode( short opcode ) {
247 this.opcode = opcode;
248 }
249
250
251 /** Some instructions may be reused, so don't do anything by default.
252 */
253 void dispose() {
254 }
255
256
257 /**
258 * Call corresponding visitor method(s). The order is:
259 * Call visitor methods of implemented interfaces first, then
260 * call methods according to the class hierarchy in descending order,
261 * i.e., the most specific visitXXX() call comes last.
262 *
263 * @param v Visitor object
264 */
265 public abstract void accept( Visitor v );
266
267
268 /** Get Comparator object used in the equals() method to determine
269 * equality of instructions.
270 *
271 * @return currently used comparator for equals()
272 */
273 public static InstructionComparator getComparator() {
274 return cmp;
275 }
276
277
278 /** Set comparator to be used for equals().
279 */
280 public static void setComparator( InstructionComparator c ) {
281 cmp = c;
282 }
283
284
285 /** Check for equality, delegated to comparator
286 * @return true if that is an Instruction and has the same opcode
287 */
288 public boolean equals( Object that ) {
289 return (that instanceof Instruction) ? cmp.equals(this, (Instruction) that) : false;
290 }
291 }
+0
-69
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionComparator.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Equality of instructions isn't clearly to be defined. You might
20 * wish, for example, to compare whether instructions have the same
21 * meaning. E.g., whether two INVOKEVIRTUALs describe the same
22 * call.<br>The DEFAULT comparator however, considers two instructions
23 * to be equal if they have same opcode and point to the same indexes
24 * (if any) in the constant pool or the same local variable index. Branch
25 * instructions must have the same target.
26 *
27 * @see Instruction
28 * @version $Id: InstructionComparator.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public interface InstructionComparator {
32
33 public static final InstructionComparator DEFAULT = new InstructionComparator() {
34
35 public boolean equals( Instruction i1, Instruction i2 ) {
36 if (i1.opcode == i2.opcode) {
37 if (i1 instanceof Select) {
38 InstructionHandle[] t1 = ((Select) i1).getTargets();
39 InstructionHandle[] t2 = ((Select) i2).getTargets();
40 if (t1.length == t2.length) {
41 for (int i = 0; i < t1.length; i++) {
42 if (t1[i] != t2[i]) {
43 return false;
44 }
45 }
46 return true;
47 }
48 } else if (i1 instanceof BranchInstruction) {
49 return ((BranchInstruction) i1).target == ((BranchInstruction) i2).target;
50 } else if (i1 instanceof ConstantPushInstruction) {
51 return ((ConstantPushInstruction) i1).getValue().equals(
52 ((ConstantPushInstruction) i2).getValue());
53 } else if (i1 instanceof IndexedInstruction) {
54 return ((IndexedInstruction) i1).getIndex() == ((IndexedInstruction) i2)
55 .getIndex();
56 } else if (i1 instanceof NEWARRAY) {
57 return ((NEWARRAY) i1).getTypecode() == ((NEWARRAY) i2).getTypecode();
58 } else {
59 return true;
60 }
61 }
62 return false;
63 }
64 };
65
66
67 public boolean equals( Instruction i1, Instruction i2 );
68 }
+0
-286
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionConstants.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * This interface contains shareable instruction objects.
22 *
23 * In order to save memory you can use some instructions multiply,
24 * since they have an immutable state and are directly derived from
25 * Instruction. I.e. they have no instance fields that could be
26 * changed. Since some of these instructions like ICONST_0 occur
27 * very frequently this can save a lot of time and space. This
28 * feature is an adaptation of the FlyWeight design pattern, we
29 * just use an array instead of a factory.
30 *
31 * The Instructions can also accessed directly under their names, so
32 * it's possible to write il.append(Instruction.ICONST_0);
33 *
34 * @version $Id: InstructionConstants.java 386056 2006-03-15 11:31:56Z tcurdt $
35 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36 */
37 public interface InstructionConstants {
38
39 /** Predefined instruction objects
40 */
41 public static final Instruction NOP = new NOP();
42 public static final Instruction ACONST_NULL = new ACONST_NULL();
43 public static final Instruction ICONST_M1 = new ICONST(-1);
44 public static final Instruction ICONST_0 = new ICONST(0);
45 public static final Instruction ICONST_1 = new ICONST(1);
46 public static final Instruction ICONST_2 = new ICONST(2);
47 public static final Instruction ICONST_3 = new ICONST(3);
48 public static final Instruction ICONST_4 = new ICONST(4);
49 public static final Instruction ICONST_5 = new ICONST(5);
50 public static final Instruction LCONST_0 = new LCONST(0);
51 public static final Instruction LCONST_1 = new LCONST(1);
52 public static final Instruction FCONST_0 = new FCONST(0);
53 public static final Instruction FCONST_1 = new FCONST(1);
54 public static final Instruction FCONST_2 = new FCONST(2);
55 public static final Instruction DCONST_0 = new DCONST(0);
56 public static final Instruction DCONST_1 = new DCONST(1);
57 public static final ArrayInstruction IALOAD = new IALOAD();
58 public static final ArrayInstruction LALOAD = new LALOAD();
59 public static final ArrayInstruction FALOAD = new FALOAD();
60 public static final ArrayInstruction DALOAD = new DALOAD();
61 public static final ArrayInstruction AALOAD = new AALOAD();
62 public static final ArrayInstruction BALOAD = new BALOAD();
63 public static final ArrayInstruction CALOAD = new CALOAD();
64 public static final ArrayInstruction SALOAD = new SALOAD();
65 public static final ArrayInstruction IASTORE = new IASTORE();
66 public static final ArrayInstruction LASTORE = new LASTORE();
67 public static final ArrayInstruction FASTORE = new FASTORE();
68 public static final ArrayInstruction DASTORE = new DASTORE();
69 public static final ArrayInstruction AASTORE = new AASTORE();
70 public static final ArrayInstruction BASTORE = new BASTORE();
71 public static final ArrayInstruction CASTORE = new CASTORE();
72 public static final ArrayInstruction SASTORE = new SASTORE();
73 public static final StackInstruction POP = new POP();
74 public static final StackInstruction POP2 = new POP2();
75 public static final StackInstruction DUP = new DUP();
76 public static final StackInstruction DUP_X1 = new DUP_X1();
77 public static final StackInstruction DUP_X2 = new DUP_X2();
78 public static final StackInstruction DUP2 = new DUP2();
79 public static final StackInstruction DUP2_X1 = new DUP2_X1();
80 public static final StackInstruction DUP2_X2 = new DUP2_X2();
81 public static final StackInstruction SWAP = new SWAP();
82 public static final ArithmeticInstruction IADD = new IADD();
83 public static final ArithmeticInstruction LADD = new LADD();
84 public static final ArithmeticInstruction FADD = new FADD();
85 public static final ArithmeticInstruction DADD = new DADD();
86 public static final ArithmeticInstruction ISUB = new ISUB();
87 public static final ArithmeticInstruction LSUB = new LSUB();
88 public static final ArithmeticInstruction FSUB = new FSUB();
89 public static final ArithmeticInstruction DSUB = new DSUB();
90 public static final ArithmeticInstruction IMUL = new IMUL();
91 public static final ArithmeticInstruction LMUL = new LMUL();
92 public static final ArithmeticInstruction FMUL = new FMUL();
93 public static final ArithmeticInstruction DMUL = new DMUL();
94 public static final ArithmeticInstruction IDIV = new IDIV();
95 public static final ArithmeticInstruction LDIV = new LDIV();
96 public static final ArithmeticInstruction FDIV = new FDIV();
97 public static final ArithmeticInstruction DDIV = new DDIV();
98 public static final ArithmeticInstruction IREM = new IREM();
99 public static final ArithmeticInstruction LREM = new LREM();
100 public static final ArithmeticInstruction FREM = new FREM();
101 public static final ArithmeticInstruction DREM = new DREM();
102 public static final ArithmeticInstruction INEG = new INEG();
103 public static final ArithmeticInstruction LNEG = new LNEG();
104 public static final ArithmeticInstruction FNEG = new FNEG();
105 public static final ArithmeticInstruction DNEG = new DNEG();
106 public static final ArithmeticInstruction ISHL = new ISHL();
107 public static final ArithmeticInstruction LSHL = new LSHL();
108 public static final ArithmeticInstruction ISHR = new ISHR();
109 public static final ArithmeticInstruction LSHR = new LSHR();
110 public static final ArithmeticInstruction IUSHR = new IUSHR();
111 public static final ArithmeticInstruction LUSHR = new LUSHR();
112 public static final ArithmeticInstruction IAND = new IAND();
113 public static final ArithmeticInstruction LAND = new LAND();
114 public static final ArithmeticInstruction IOR = new IOR();
115 public static final ArithmeticInstruction LOR = new LOR();
116 public static final ArithmeticInstruction IXOR = new IXOR();
117 public static final ArithmeticInstruction LXOR = new LXOR();
118 public static final ConversionInstruction I2L = new I2L();
119 public static final ConversionInstruction I2F = new I2F();
120 public static final ConversionInstruction I2D = new I2D();
121 public static final ConversionInstruction L2I = new L2I();
122 public static final ConversionInstruction L2F = new L2F();
123 public static final ConversionInstruction L2D = new L2D();
124 public static final ConversionInstruction F2I = new F2I();
125 public static final ConversionInstruction F2L = new F2L();
126 public static final ConversionInstruction F2D = new F2D();
127 public static final ConversionInstruction D2I = new D2I();
128 public static final ConversionInstruction D2L = new D2L();
129 public static final ConversionInstruction D2F = new D2F();
130 public static final ConversionInstruction I2B = new I2B();
131 public static final ConversionInstruction I2C = new I2C();
132 public static final ConversionInstruction I2S = new I2S();
133 public static final Instruction LCMP = new LCMP();
134 public static final Instruction FCMPL = new FCMPL();
135 public static final Instruction FCMPG = new FCMPG();
136 public static final Instruction DCMPL = new DCMPL();
137 public static final Instruction DCMPG = new DCMPG();
138 public static final ReturnInstruction IRETURN = new IRETURN();
139 public static final ReturnInstruction LRETURN = new LRETURN();
140 public static final ReturnInstruction FRETURN = new FRETURN();
141 public static final ReturnInstruction DRETURN = new DRETURN();
142 public static final ReturnInstruction ARETURN = new ARETURN();
143 public static final ReturnInstruction RETURN = new RETURN();
144 public static final Instruction ARRAYLENGTH = new ARRAYLENGTH();
145 public static final Instruction ATHROW = new ATHROW();
146 public static final Instruction MONITORENTER = new MONITORENTER();
147 public static final Instruction MONITOREXIT = new MONITOREXIT();
148 /** You can use these constants in multiple places safely, if you can guarantee
149 * that you will never alter their internal values, e.g. call setIndex().
150 */
151 public static final LocalVariableInstruction THIS = new ALOAD(0);
152 public static final LocalVariableInstruction ALOAD_0 = THIS;
153 public static final LocalVariableInstruction ALOAD_1 = new ALOAD(1);
154 public static final LocalVariableInstruction ALOAD_2 = new ALOAD(2);
155 public static final LocalVariableInstruction ILOAD_0 = new ILOAD(0);
156 public static final LocalVariableInstruction ILOAD_1 = new ILOAD(1);
157 public static final LocalVariableInstruction ILOAD_2 = new ILOAD(2);
158 public static final LocalVariableInstruction ASTORE_0 = new ASTORE(0);
159 public static final LocalVariableInstruction ASTORE_1 = new ASTORE(1);
160 public static final LocalVariableInstruction ASTORE_2 = new ASTORE(2);
161 public static final LocalVariableInstruction ISTORE_0 = new ISTORE(0);
162 public static final LocalVariableInstruction ISTORE_1 = new ISTORE(1);
163 public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
164 /** Get object via its opcode, for immutable instructions like
165 * branch instructions entries are set to null.
166 */
167 public static final Instruction[] INSTRUCTIONS = new Instruction[256];
168 /** Interfaces may have no static initializers, so we simulate this
169 * with an inner class.
170 */
171 static final Clinit bla = new Clinit();
172
173 static class Clinit {
174
175 Clinit() {
176 INSTRUCTIONS[Constants.NOP] = NOP;
177 INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL;
178 INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1;
179 INSTRUCTIONS[Constants.ICONST_0] = ICONST_0;
180 INSTRUCTIONS[Constants.ICONST_1] = ICONST_1;
181 INSTRUCTIONS[Constants.ICONST_2] = ICONST_2;
182 INSTRUCTIONS[Constants.ICONST_3] = ICONST_3;
183 INSTRUCTIONS[Constants.ICONST_4] = ICONST_4;
184 INSTRUCTIONS[Constants.ICONST_5] = ICONST_5;
185 INSTRUCTIONS[Constants.LCONST_0] = LCONST_0;
186 INSTRUCTIONS[Constants.LCONST_1] = LCONST_1;
187 INSTRUCTIONS[Constants.FCONST_0] = FCONST_0;
188 INSTRUCTIONS[Constants.FCONST_1] = FCONST_1;
189 INSTRUCTIONS[Constants.FCONST_2] = FCONST_2;
190 INSTRUCTIONS[Constants.DCONST_0] = DCONST_0;
191 INSTRUCTIONS[Constants.DCONST_1] = DCONST_1;
192 INSTRUCTIONS[Constants.IALOAD] = IALOAD;
193 INSTRUCTIONS[Constants.LALOAD] = LALOAD;
194 INSTRUCTIONS[Constants.FALOAD] = FALOAD;
195 INSTRUCTIONS[Constants.DALOAD] = DALOAD;
196 INSTRUCTIONS[Constants.AALOAD] = AALOAD;
197 INSTRUCTIONS[Constants.BALOAD] = BALOAD;
198 INSTRUCTIONS[Constants.CALOAD] = CALOAD;
199 INSTRUCTIONS[Constants.SALOAD] = SALOAD;
200 INSTRUCTIONS[Constants.IASTORE] = IASTORE;
201 INSTRUCTIONS[Constants.LASTORE] = LASTORE;
202 INSTRUCTIONS[Constants.FASTORE] = FASTORE;
203 INSTRUCTIONS[Constants.DASTORE] = DASTORE;
204 INSTRUCTIONS[Constants.AASTORE] = AASTORE;
205 INSTRUCTIONS[Constants.BASTORE] = BASTORE;
206 INSTRUCTIONS[Constants.CASTORE] = CASTORE;
207 INSTRUCTIONS[Constants.SASTORE] = SASTORE;
208 INSTRUCTIONS[Constants.POP] = POP;
209 INSTRUCTIONS[Constants.POP2] = POP2;
210 INSTRUCTIONS[Constants.DUP] = DUP;
211 INSTRUCTIONS[Constants.DUP_X1] = DUP_X1;
212 INSTRUCTIONS[Constants.DUP_X2] = DUP_X2;
213 INSTRUCTIONS[Constants.DUP2] = DUP2;
214 INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1;
215 INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2;
216 INSTRUCTIONS[Constants.SWAP] = SWAP;
217 INSTRUCTIONS[Constants.IADD] = IADD;
218 INSTRUCTIONS[Constants.LADD] = LADD;
219 INSTRUCTIONS[Constants.FADD] = FADD;
220 INSTRUCTIONS[Constants.DADD] = DADD;
221 INSTRUCTIONS[Constants.ISUB] = ISUB;
222 INSTRUCTIONS[Constants.LSUB] = LSUB;
223 INSTRUCTIONS[Constants.FSUB] = FSUB;
224 INSTRUCTIONS[Constants.DSUB] = DSUB;
225 INSTRUCTIONS[Constants.IMUL] = IMUL;
226 INSTRUCTIONS[Constants.LMUL] = LMUL;
227 INSTRUCTIONS[Constants.FMUL] = FMUL;
228 INSTRUCTIONS[Constants.DMUL] = DMUL;
229 INSTRUCTIONS[Constants.IDIV] = IDIV;
230 INSTRUCTIONS[Constants.LDIV] = LDIV;
231 INSTRUCTIONS[Constants.FDIV] = FDIV;
232 INSTRUCTIONS[Constants.DDIV] = DDIV;
233 INSTRUCTIONS[Constants.IREM] = IREM;
234 INSTRUCTIONS[Constants.LREM] = LREM;
235 INSTRUCTIONS[Constants.FREM] = FREM;
236 INSTRUCTIONS[Constants.DREM] = DREM;
237 INSTRUCTIONS[Constants.INEG] = INEG;
238 INSTRUCTIONS[Constants.LNEG] = LNEG;
239 INSTRUCTIONS[Constants.FNEG] = FNEG;
240 INSTRUCTIONS[Constants.DNEG] = DNEG;
241 INSTRUCTIONS[Constants.ISHL] = ISHL;
242 INSTRUCTIONS[Constants.LSHL] = LSHL;
243 INSTRUCTIONS[Constants.ISHR] = ISHR;
244 INSTRUCTIONS[Constants.LSHR] = LSHR;
245 INSTRUCTIONS[Constants.IUSHR] = IUSHR;
246 INSTRUCTIONS[Constants.LUSHR] = LUSHR;
247 INSTRUCTIONS[Constants.IAND] = IAND;
248 INSTRUCTIONS[Constants.LAND] = LAND;
249 INSTRUCTIONS[Constants.IOR] = IOR;
250 INSTRUCTIONS[Constants.LOR] = LOR;
251 INSTRUCTIONS[Constants.IXOR] = IXOR;
252 INSTRUCTIONS[Constants.LXOR] = LXOR;
253 INSTRUCTIONS[Constants.I2L] = I2L;
254 INSTRUCTIONS[Constants.I2F] = I2F;
255 INSTRUCTIONS[Constants.I2D] = I2D;
256 INSTRUCTIONS[Constants.L2I] = L2I;
257 INSTRUCTIONS[Constants.L2F] = L2F;
258 INSTRUCTIONS[Constants.L2D] = L2D;
259 INSTRUCTIONS[Constants.F2I] = F2I;
260 INSTRUCTIONS[Constants.F2L] = F2L;
261 INSTRUCTIONS[Constants.F2D] = F2D;
262 INSTRUCTIONS[Constants.D2I] = D2I;
263 INSTRUCTIONS[Constants.D2L] = D2L;
264 INSTRUCTIONS[Constants.D2F] = D2F;
265 INSTRUCTIONS[Constants.I2B] = I2B;
266 INSTRUCTIONS[Constants.I2C] = I2C;
267 INSTRUCTIONS[Constants.I2S] = I2S;
268 INSTRUCTIONS[Constants.LCMP] = LCMP;
269 INSTRUCTIONS[Constants.FCMPL] = FCMPL;
270 INSTRUCTIONS[Constants.FCMPG] = FCMPG;
271 INSTRUCTIONS[Constants.DCMPL] = DCMPL;
272 INSTRUCTIONS[Constants.DCMPG] = DCMPG;
273 INSTRUCTIONS[Constants.IRETURN] = IRETURN;
274 INSTRUCTIONS[Constants.LRETURN] = LRETURN;
275 INSTRUCTIONS[Constants.FRETURN] = FRETURN;
276 INSTRUCTIONS[Constants.DRETURN] = DRETURN;
277 INSTRUCTIONS[Constants.ARETURN] = ARETURN;
278 INSTRUCTIONS[Constants.RETURN] = RETURN;
279 INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH;
280 INSTRUCTIONS[Constants.ATHROW] = ATHROW;
281 INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER;
282 INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT;
283 }
284 }
285 }
+0
-743
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionFactory.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Instances of this class may be used, e.g., to generate typed
22 * versions of instructions. Its main purpose is to be used as the
23 * byte code generating backend of a compiler. You can subclass it to
24 * add your own create methods.
25 *
26 * @version $Id: InstructionFactory.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 * @see Constants
29 */
30 public class InstructionFactory implements InstructionConstants, java.io.Serializable {
31
32 protected ClassGen cg;
33 protected ConstantPoolGen cp;
34
35
36 public InstructionFactory(ClassGen cg, ConstantPoolGen cp) {
37 this.cg = cg;
38 this.cp = cp;
39 }
40
41
42 /** Initialize with ClassGen object
43 */
44 public InstructionFactory(ClassGen cg) {
45 this(cg, cg.getConstantPool());
46 }
47
48
49 /** Initialize just with ConstantPoolGen object
50 */
51 public InstructionFactory(ConstantPoolGen cp) {
52 this(null, cp);
53 }
54
55
56 /** Create an invoke instruction.
57 *
58 * @param class_name name of the called class
59 * @param name name of the called method
60 * @param ret_type return type of method
61 * @param arg_types argument types of method
62 * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL,
63 * or INVOKESPECIAL
64 * @see Constants
65 */
66 public InvokeInstruction createInvoke( String class_name, String name, Type ret_type,
67 Type[] arg_types, short kind ) {
68 int index;
69 int nargs = 0;
70 String signature = Type.getMethodSignature(ret_type, arg_types);
71 for (int i = 0; i < arg_types.length; i++) {
72 nargs += arg_types[i].getSize();
73 }
74 if (kind == Constants.INVOKEINTERFACE) {
75 index = cp.addInterfaceMethodref(class_name, name, signature);
76 } else {
77 index = cp.addMethodref(class_name, name, signature);
78 }
79 switch (kind) {
80 case Constants.INVOKESPECIAL:
81 return new INVOKESPECIAL(index);
82 case Constants.INVOKEVIRTUAL:
83 return new INVOKEVIRTUAL(index);
84 case Constants.INVOKESTATIC:
85 return new INVOKESTATIC(index);
86 case Constants.INVOKEINTERFACE:
87 return new INVOKEINTERFACE(index, nargs + 1);
88 default:
89 throw new RuntimeException("Oops: Unknown invoke kind:" + kind);
90 }
91 }
92
93
94 /** Create a call to the most popular System.out.println() method.
95 *
96 * @param s the string to print
97 */
98 public InstructionList createPrintln( String s ) {
99 InstructionList il = new InstructionList();
100 int out = cp.addFieldref("java.lang.System", "out", "Ljava/io/PrintStream;");
101 int println = cp.addMethodref("java.io.PrintStream", "println", "(Ljava/lang/String;)V");
102 il.append(new GETSTATIC(out));
103 il.append(new PUSH(cp, s));
104 il.append(new INVOKEVIRTUAL(println));
105 return il;
106 }
107
108
109 /** Uses PUSH to push a constant value onto the stack.
110 * @param value must be of type Number, Boolean, Character or String
111 */
112 public Instruction createConstant( Object value ) {
113 PUSH push;
114 if (value instanceof Number) {
115 push = new PUSH(cp, (Number) value);
116 } else if (value instanceof String) {
117 push = new PUSH(cp, (String) value);
118 } else if (value instanceof Boolean) {
119 push = new PUSH(cp, (Boolean) value);
120 } else if (value instanceof Character) {
121 push = new PUSH(cp, (Character) value);
122 } else {
123 throw new ClassGenException("Illegal type: " + value.getClass());
124 }
125 return push.getInstruction();
126 }
127
128 private static class MethodObject {
129
130 Type[] arg_types;
131 Type result_type;
132 String class_name;
133 String name;
134 int access;
135
136
137 MethodObject(String c, String n, Type r, Type[] a, int acc) {
138 class_name = c;
139 name = n;
140 result_type = r;
141 arg_types = a;
142 access = acc;
143 }
144 }
145
146
147 private InvokeInstruction createInvoke( MethodObject m, short kind ) {
148 return createInvoke(m.class_name, m.name, m.result_type, m.arg_types, kind);
149 }
150
151 private static MethodObject[] append_mos = {
152 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
153 Type.STRING
154 }, Constants.ACC_PUBLIC),
155 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
156 Type.OBJECT
157 }, Constants.ACC_PUBLIC),
158 null,
159 null, // indices 2, 3
160 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
161 Type.BOOLEAN
162 }, Constants.ACC_PUBLIC),
163 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
164 Type.CHAR
165 }, Constants.ACC_PUBLIC),
166 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
167 Type.FLOAT
168 }, Constants.ACC_PUBLIC),
169 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
170 Type.DOUBLE
171 }, Constants.ACC_PUBLIC),
172 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
173 Type.INT
174 }, Constants.ACC_PUBLIC),
175 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, // No append(byte)
176 new Type[] {
177 Type.INT
178 }, Constants.ACC_PUBLIC),
179 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, // No append(short)
180 new Type[] {
181 Type.INT
182 }, Constants.ACC_PUBLIC),
183 new MethodObject("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[] {
184 Type.LONG
185 }, Constants.ACC_PUBLIC)
186 };
187
188
189 private static final boolean isString( Type type ) {
190 return ((type instanceof ObjectType) && ((ObjectType) type).getClassName().equals(
191 "java.lang.String"));
192 }
193
194
195 public Instruction createAppend( Type type ) {
196 byte t = type.getType();
197 if (isString(type)) {
198 return createInvoke(append_mos[0], Constants.INVOKEVIRTUAL);
199 }
200 switch (t) {
201 case Constants.T_BOOLEAN:
202 case Constants.T_CHAR:
203 case Constants.T_FLOAT:
204 case Constants.T_DOUBLE:
205 case Constants.T_BYTE:
206 case Constants.T_SHORT:
207 case Constants.T_INT:
208 case Constants.T_LONG:
209 return createInvoke(append_mos[t], Constants.INVOKEVIRTUAL);
210 case Constants.T_ARRAY:
211 case Constants.T_OBJECT:
212 return createInvoke(append_mos[1], Constants.INVOKEVIRTUAL);
213 default:
214 throw new RuntimeException("Oops: No append for this type? " + type);
215 }
216 }
217
218
219 /** Create a field instruction.
220 *
221 * @param class_name name of the accessed class
222 * @param name name of the referenced field
223 * @param type type of field
224 * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
225 * @see Constants
226 */
227 public FieldInstruction createFieldAccess( String class_name, String name, Type type, short kind ) {
228 int index;
229 String signature = type.getSignature();
230 index = cp.addFieldref(class_name, name, signature);
231 switch (kind) {
232 case Constants.GETFIELD:
233 return new GETFIELD(index);
234 case Constants.PUTFIELD:
235 return new PUTFIELD(index);
236 case Constants.GETSTATIC:
237 return new GETSTATIC(index);
238 case Constants.PUTSTATIC:
239 return new PUTSTATIC(index);
240 default:
241 throw new RuntimeException("Oops: Unknown getfield kind:" + kind);
242 }
243 }
244
245
246 /** Create reference to `this'
247 */
248 public static Instruction createThis() {
249 return new ALOAD(0);
250 }
251
252
253 /** Create typed return
254 */
255 public static ReturnInstruction createReturn( Type type ) {
256 switch (type.getType()) {
257 case Constants.T_ARRAY:
258 case Constants.T_OBJECT:
259 return ARETURN;
260 case Constants.T_INT:
261 case Constants.T_SHORT:
262 case Constants.T_BOOLEAN:
263 case Constants.T_CHAR:
264 case Constants.T_BYTE:
265 return IRETURN;
266 case Constants.T_FLOAT:
267 return FRETURN;
268 case Constants.T_DOUBLE:
269 return DRETURN;
270 case Constants.T_LONG:
271 return LRETURN;
272 case Constants.T_VOID:
273 return RETURN;
274 default:
275 throw new RuntimeException("Invalid type: " + type);
276 }
277 }
278
279
280 private static final ArithmeticInstruction createBinaryIntOp( char first, String op ) {
281 switch (first) {
282 case '-':
283 return ISUB;
284 case '+':
285 return IADD;
286 case '%':
287 return IREM;
288 case '*':
289 return IMUL;
290 case '/':
291 return IDIV;
292 case '&':
293 return IAND;
294 case '|':
295 return IOR;
296 case '^':
297 return IXOR;
298 case '<':
299 return ISHL;
300 case '>':
301 return op.equals(">>>")
302 ? (ArithmeticInstruction) IUSHR
303 : (ArithmeticInstruction) ISHR;
304 default:
305 throw new RuntimeException("Invalid operand " + op);
306 }
307 }
308
309
310 private static final ArithmeticInstruction createBinaryLongOp( char first, String op ) {
311 switch (first) {
312 case '-':
313 return LSUB;
314 case '+':
315 return LADD;
316 case '%':
317 return LREM;
318 case '*':
319 return LMUL;
320 case '/':
321 return LDIV;
322 case '&':
323 return LAND;
324 case '|':
325 return LOR;
326 case '^':
327 return LXOR;
328 case '<':
329 return LSHL;
330 case '>':
331 return op.equals(">>>")
332 ? (ArithmeticInstruction) LUSHR
333 : (ArithmeticInstruction) LSHR;
334 default:
335 throw new RuntimeException("Invalid operand " + op);
336 }
337 }
338
339
340 private static final ArithmeticInstruction createBinaryFloatOp( char op ) {
341 switch (op) {
342 case '-':
343 return FSUB;
344 case '+':
345 return FADD;
346 case '*':
347 return FMUL;
348 case '/':
349 return FDIV;
350 default:
351 throw new RuntimeException("Invalid operand " + op);
352 }
353 }
354
355
356 private static final ArithmeticInstruction createBinaryDoubleOp( char op ) {
357 switch (op) {
358 case '-':
359 return DSUB;
360 case '+':
361 return DADD;
362 case '*':
363 return DMUL;
364 case '/':
365 return DDIV;
366 default:
367 throw new RuntimeException("Invalid operand " + op);
368 }
369 }
370
371
372 /**
373 * Create binary operation for simple basic types, such as int and float.
374 *
375 * @param op operation, such as "+", "*", "<<", etc.
376 */
377 public static ArithmeticInstruction createBinaryOperation( String op, Type type ) {
378 char first = op.toCharArray()[0];
379 switch (type.getType()) {
380 case Constants.T_BYTE:
381 case Constants.T_SHORT:
382 case Constants.T_INT:
383 case Constants.T_CHAR:
384 return createBinaryIntOp(first, op);
385 case Constants.T_LONG:
386 return createBinaryLongOp(first, op);
387 case Constants.T_FLOAT:
388 return createBinaryFloatOp(first);
389 case Constants.T_DOUBLE:
390 return createBinaryDoubleOp(first);
391 default:
392 throw new RuntimeException("Invalid type " + type);
393 }
394 }
395
396
397 /**
398 * @param size size of operand, either 1 (int, e.g.) or 2 (double)
399 */
400 public static StackInstruction createPop( int size ) {
401 return (size == 2) ? (StackInstruction) POP2 : (StackInstruction) POP;
402 }
403
404
405 /**
406 * @param size size of operand, either 1 (int, e.g.) or 2 (double)
407 */
408 public static StackInstruction createDup( int size ) {
409 return (size == 2) ? (StackInstruction) DUP2 : (StackInstruction) DUP;
410 }
411
412
413 /**
414 * @param size size of operand, either 1 (int, e.g.) or 2 (double)
415 */
416 public static StackInstruction createDup_2( int size ) {
417 return (size == 2) ? (StackInstruction) DUP2_X2 : (StackInstruction) DUP_X2;
418 }
419
420
421 /**
422 * @param size size of operand, either 1 (int, e.g.) or 2 (double)
423 */
424 public static StackInstruction createDup_1( int size ) {
425 return (size == 2) ? (StackInstruction) DUP2_X1 : (StackInstruction) DUP_X1;
426 }
427
428
429 /**
430 * @param index index of local variable
431 */
432 public static LocalVariableInstruction createStore( Type type, int index ) {
433 switch (type.getType()) {
434 case Constants.T_BOOLEAN:
435 case Constants.T_CHAR:
436 case Constants.T_BYTE:
437 case Constants.T_SHORT:
438 case Constants.T_INT:
439 return new ISTORE(index);
440 case Constants.T_FLOAT:
441 return new FSTORE(index);
442 case Constants.T_DOUBLE:
443 return new DSTORE(index);
444 case Constants.T_LONG:
445 return new LSTORE(index);
446 case Constants.T_ARRAY:
447 case Constants.T_OBJECT:
448 return new ASTORE(index);
449 default:
450 throw new RuntimeException("Invalid type " + type);
451 }
452 }
453
454
455 /**
456 * @param index index of local variable
457 */
458 public static LocalVariableInstruction createLoad( Type type, int index ) {
459 switch (type.getType()) {
460 case Constants.T_BOOLEAN:
461 case Constants.T_CHAR:
462 case Constants.T_BYTE:
463 case Constants.T_SHORT:
464 case Constants.T_INT:
465 return new ILOAD(index);
466 case Constants.T_FLOAT:
467 return new FLOAD(index);
468 case Constants.T_DOUBLE:
469 return new DLOAD(index);
470 case Constants.T_LONG:
471 return new LLOAD(index);
472 case Constants.T_ARRAY:
473 case Constants.T_OBJECT:
474 return new ALOAD(index);
475 default:
476 throw new RuntimeException("Invalid type " + type);
477 }
478 }
479
480
481 /**
482 * @param type type of elements of array, i.e., array.getElementType()
483 */
484 public static ArrayInstruction createArrayLoad( Type type ) {
485 switch (type.getType()) {
486 case Constants.T_BOOLEAN:
487 case Constants.T_BYTE:
488 return BALOAD;
489 case Constants.T_CHAR:
490 return CALOAD;
491 case Constants.T_SHORT:
492 return SALOAD;
493 case Constants.T_INT:
494 return IALOAD;
495 case Constants.T_FLOAT:
496 return FALOAD;
497 case Constants.T_DOUBLE:
498 return DALOAD;
499 case Constants.T_LONG:
500 return LALOAD;
501 case Constants.T_ARRAY:
502 case Constants.T_OBJECT:
503 return AALOAD;
504 default:
505 throw new RuntimeException("Invalid type " + type);
506 }
507 }
508
509
510 /**
511 * @param type type of elements of array, i.e., array.getElementType()
512 */
513 public static ArrayInstruction createArrayStore( Type type ) {
514 switch (type.getType()) {
515 case Constants.T_BOOLEAN:
516 case Constants.T_BYTE:
517 return BASTORE;
518 case Constants.T_CHAR:
519 return CASTORE;
520 case Constants.T_SHORT:
521 return SASTORE;
522 case Constants.T_INT:
523 return IASTORE;
524 case Constants.T_FLOAT:
525 return FASTORE;
526 case Constants.T_DOUBLE:
527 return DASTORE;
528 case Constants.T_LONG:
529 return LASTORE;
530 case Constants.T_ARRAY:
531 case Constants.T_OBJECT:
532 return AASTORE;
533 default:
534 throw new RuntimeException("Invalid type " + type);
535 }
536 }
537
538
539 /** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g.,
540 * if the operands are basic types and CHECKCAST if they are reference types.
541 */
542 public Instruction createCast( Type src_type, Type dest_type ) {
543 if ((src_type instanceof BasicType) && (dest_type instanceof BasicType)) {
544 byte dest = dest_type.getType();
545 byte src = src_type.getType();
546 if (dest == Constants.T_LONG
547 && (src == Constants.T_CHAR || src == Constants.T_BYTE || src == Constants.T_SHORT)) {
548 src = Constants.T_INT;
549 }
550 String[] short_names = {
551 "C", "F", "D", "B", "S", "I", "L"
552 };
553 String name = "org.apache.bcel.generic." + short_names[src - Constants.T_CHAR] + "2"
554 + short_names[dest - Constants.T_CHAR];
555 Instruction i = null;
556 try {
557 i = (Instruction) java.lang.Class.forName(name).newInstance();
558 } catch (Exception e) {
559 throw new RuntimeException("Could not find instruction: " + name);
560 }
561 return i;
562 } else if ((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) {
563 if (dest_type instanceof ArrayType) {
564 return new CHECKCAST(cp.addArrayClass((ArrayType) dest_type));
565 } else {
566 return new CHECKCAST(cp.addClass(((ObjectType) dest_type).getClassName()));
567 }
568 } else {
569 throw new RuntimeException("Can not cast " + src_type + " to " + dest_type);
570 }
571 }
572
573
574 public GETFIELD createGetField( String class_name, String name, Type t ) {
575 return new GETFIELD(cp.addFieldref(class_name, name, t.getSignature()));
576 }
577
578
579 public GETSTATIC createGetStatic( String class_name, String name, Type t ) {
580 return new GETSTATIC(cp.addFieldref(class_name, name, t.getSignature()));
581 }
582
583
584 public PUTFIELD createPutField( String class_name, String name, Type t ) {
585 return new PUTFIELD(cp.addFieldref(class_name, name, t.getSignature()));
586 }
587
588
589 public PUTSTATIC createPutStatic( String class_name, String name, Type t ) {
590 return new PUTSTATIC(cp.addFieldref(class_name, name, t.getSignature()));
591 }
592
593
594 public CHECKCAST createCheckCast( ReferenceType t ) {
595 if (t instanceof ArrayType) {
596 return new CHECKCAST(cp.addArrayClass((ArrayType) t));
597 } else {
598 return new CHECKCAST(cp.addClass((ObjectType) t));
599 }
600 }
601
602
603 public INSTANCEOF createInstanceOf( ReferenceType t ) {
604 if (t instanceof ArrayType) {
605 return new INSTANCEOF(cp.addArrayClass((ArrayType) t));
606 } else {
607 return new INSTANCEOF(cp.addClass((ObjectType) t));
608 }
609 }
610
611
612 public NEW createNew( ObjectType t ) {
613 return new NEW(cp.addClass(t));
614 }
615
616
617 public NEW createNew( String s ) {
618 return createNew(ObjectType.getInstance(s));
619 }
620
621
622 /** Create new array of given size and type.
623 * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction
624 */
625 public Instruction createNewArray( Type t, short dim ) {
626 if (dim == 1) {
627 if (t instanceof ObjectType) {
628 return new ANEWARRAY(cp.addClass((ObjectType) t));
629 } else if (t instanceof ArrayType) {
630 return new ANEWARRAY(cp.addArrayClass((ArrayType) t));
631 } else {
632 return new NEWARRAY(((BasicType) t).getType());
633 }
634 } else {
635 ArrayType at;
636 if (t instanceof ArrayType) {
637 at = (ArrayType) t;
638 } else {
639 at = new ArrayType(t, dim);
640 }
641 return new MULTIANEWARRAY(cp.addArrayClass(at), dim);
642 }
643 }
644
645
646 /** Create "null" value for reference types, 0 for basic types like int
647 */
648 public static Instruction createNull( Type type ) {
649 switch (type.getType()) {
650 case Constants.T_ARRAY:
651 case Constants.T_OBJECT:
652 return ACONST_NULL;
653 case Constants.T_INT:
654 case Constants.T_SHORT:
655 case Constants.T_BOOLEAN:
656 case Constants.T_CHAR:
657 case Constants.T_BYTE:
658 return ICONST_0;
659 case Constants.T_FLOAT:
660 return FCONST_0;
661 case Constants.T_DOUBLE:
662 return DCONST_0;
663 case Constants.T_LONG:
664 return LCONST_0;
665 case Constants.T_VOID:
666 return NOP;
667 default:
668 throw new RuntimeException("Invalid type: " + type);
669 }
670 }
671
672
673 /** Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.
674 * For those you should use the SWITCH compound instruction.
675 */
676 public static BranchInstruction createBranchInstruction( short opcode, InstructionHandle target ) {
677 switch (opcode) {
678 case Constants.IFEQ:
679 return new IFEQ(target);
680 case Constants.IFNE:
681 return new IFNE(target);
682 case Constants.IFLT:
683 return new IFLT(target);
684 case Constants.IFGE:
685 return new IFGE(target);
686 case Constants.IFGT:
687 return new IFGT(target);
688 case Constants.IFLE:
689 return new IFLE(target);
690 case Constants.IF_ICMPEQ:
691 return new IF_ICMPEQ(target);
692 case Constants.IF_ICMPNE:
693 return new IF_ICMPNE(target);
694 case Constants.IF_ICMPLT:
695 return new IF_ICMPLT(target);
696 case Constants.IF_ICMPGE:
697 return new IF_ICMPGE(target);
698 case Constants.IF_ICMPGT:
699 return new IF_ICMPGT(target);
700 case Constants.IF_ICMPLE:
701 return new IF_ICMPLE(target);
702 case Constants.IF_ACMPEQ:
703 return new IF_ACMPEQ(target);
704 case Constants.IF_ACMPNE:
705 return new IF_ACMPNE(target);
706 case Constants.GOTO:
707 return new GOTO(target);
708 case Constants.JSR:
709 return new JSR(target);
710 case Constants.IFNULL:
711 return new IFNULL(target);
712 case Constants.IFNONNULL:
713 return new IFNONNULL(target);
714 case Constants.GOTO_W:
715 return new GOTO_W(target);
716 case Constants.JSR_W:
717 return new JSR_W(target);
718 default:
719 throw new RuntimeException("Invalid opcode: " + opcode);
720 }
721 }
722
723
724 public void setClassGen( ClassGen c ) {
725 cg = c;
726 }
727
728
729 public ClassGen getClassGen() {
730 return cg;
731 }
732
733
734 public void setConstantPool( ConstantPoolGen c ) {
735 cp = c;
736 }
737
738
739 public ConstantPoolGen getConstantPool() {
740 return cp;
741 }
742 }
+0
-290
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionHandle.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Map;
22 import java.util.Set;
23 import org.apache.bcel.classfile.Utility;
24
25 /**
26 * Instances of this class give users a handle to the instructions contained in
27 * an InstructionList. Instruction objects may be used more than once within a
28 * list, this is useful because it saves memory and may be much faster.
29 *
30 * Within an InstructionList an InstructionHandle object is wrapped
31 * around all instructions, i.e., it implements a cell in a
32 * doubly-linked list. From the outside only the next and the
33 * previous instruction (handle) are accessible. One
34 * can traverse the list via an Enumeration returned by
35 * InstructionList.elements().
36 *
37 * @version $Id: InstructionHandle.java 386056 2006-03-15 11:31:56Z tcurdt $
38 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
39 * @see Instruction
40 * @see BranchHandle
41 * @see InstructionList
42 */
43 public class InstructionHandle implements java.io.Serializable {
44
45 InstructionHandle next, prev; // Will be set from the outside
46 Instruction instruction;
47 protected int i_position = -1; // byte code offset of instruction
48 private Set targeters;
49 private Map attributes;
50
51
52 public final InstructionHandle getNext() {
53 return next;
54 }
55
56
57 public final InstructionHandle getPrev() {
58 return prev;
59 }
60
61
62 public final Instruction getInstruction() {
63 return instruction;
64 }
65
66
67 /**
68 * Replace current instruction contained in this handle.
69 * Old instruction is disposed using Instruction.dispose().
70 */
71 public void setInstruction( Instruction i ) { // Overridden in BranchHandle
72 if (i == null) {
73 throw new ClassGenException("Assigning null to handle");
74 }
75 if ((this.getClass() != BranchHandle.class) && (i instanceof BranchInstruction)) {
76 throw new ClassGenException("Assigning branch instruction " + i + " to plain handle");
77 }
78 if (instruction != null) {
79 instruction.dispose();
80 }
81 instruction = i;
82 }
83
84
85 /**
86 * Temporarily swap the current instruction, without disturbing
87 * anything. Meant to be used by a debugger, implementing
88 * breakpoints. Current instruction is returned.
89 */
90 public Instruction swapInstruction( Instruction i ) {
91 Instruction oldInstruction = instruction;
92 instruction = i;
93 return oldInstruction;
94 }
95
96
97 /*private*/protected InstructionHandle(Instruction i) {
98 setInstruction(i);
99 }
100
101 private static InstructionHandle ih_list = null; // List of reusable handles
102
103
104 /** Factory method.
105 */
106 static final InstructionHandle getInstructionHandle( Instruction i ) {
107 if (ih_list == null) {
108 return new InstructionHandle(i);
109 } else {
110 InstructionHandle ih = ih_list;
111 ih_list = ih.next;
112 ih.setInstruction(i);
113 return ih;
114 }
115 }
116
117
118 /**
119 * Called by InstructionList.setPositions when setting the position for every
120 * instruction. In the presence of variable length instructions `setPositions()'
121 * performs multiple passes over the instruction list to calculate the
122 * correct (byte) positions and offsets by calling this function.
123 *
124 * @param offset additional offset caused by preceding (variable length) instructions
125 * @param max_offset the maximum offset that may be caused by these instructions
126 * @return additional offset caused by possible change of this instruction's length
127 */
128 protected int updatePosition( int offset, int max_offset ) {
129 i_position += offset;
130 return 0;
131 }
132
133
134 /** @return the position, i.e., the byte code offset of the contained
135 * instruction. This is accurate only after
136 * InstructionList.setPositions() has been called.
137 */
138 public int getPosition() {
139 return i_position;
140 }
141
142
143 /** Set the position, i.e., the byte code offset of the contained
144 * instruction.
145 */
146 void setPosition( int pos ) {
147 i_position = pos;
148 }
149
150
151 /** Overridden in BranchHandle
152 */
153 protected void addHandle() {
154 next = ih_list;
155 ih_list = this;
156 }
157
158
159 /**
160 * Delete contents, i.e., remove user access and make handle reusable.
161 */
162 void dispose() {
163 next = prev = null;
164 instruction.dispose();
165 instruction = null;
166 i_position = -1;
167 attributes = null;
168 removeAllTargeters();
169 addHandle();
170 }
171
172
173 /** Remove all targeters, if any.
174 */
175 public void removeAllTargeters() {
176 if (targeters != null) {
177 targeters.clear();
178 }
179 }
180
181
182 /**
183 * Denote this handle isn't referenced anymore by t.
184 */
185 public void removeTargeter( InstructionTargeter t ) {
186 if (targeters != null) {
187 targeters.remove(t);
188 }
189 }
190
191
192 /**
193 * Denote this handle is being referenced by t.
194 */
195 public void addTargeter( InstructionTargeter t ) {
196 if (targeters == null) {
197 targeters = new HashSet();
198 }
199 //if(!targeters.contains(t))
200 targeters.add(t);
201 }
202
203
204 public boolean hasTargeters() {
205 return (targeters != null) && (targeters.size() > 0);
206 }
207
208
209 /**
210 * @return null, if there are no targeters
211 */
212 public InstructionTargeter[] getTargeters() {
213 if (!hasTargeters()) {
214 return null;
215 }
216 InstructionTargeter[] t = new InstructionTargeter[targeters.size()];
217 targeters.toArray(t);
218 return t;
219 }
220
221
222 /** @return a (verbose) string representation of the contained instruction.
223 */
224 public String toString( boolean verbose ) {
225 return Utility.format(i_position, 4, false, ' ') + ": " + instruction.toString(verbose);
226 }
227
228
229 /** @return a string representation of the contained instruction.
230 */
231 public String toString() {
232 return toString(true);
233 }
234
235
236 /** Add an attribute to an instruction handle.
237 *
238 * @param key the key object to store/retrieve the attribute
239 * @param attr the attribute to associate with this handle
240 */
241 public void addAttribute( Object key, Object attr ) {
242 if (attributes == null) {
243 attributes = new HashMap(3);
244 }
245 attributes.put(key, attr);
246 }
247
248
249 /** Delete an attribute of an instruction handle.
250 *
251 * @param key the key object to retrieve the attribute
252 */
253 public void removeAttribute( Object key ) {
254 if (attributes != null) {
255 attributes.remove(key);
256 }
257 }
258
259
260 /** Get attribute of an instruction handle.
261 *
262 * @param key the key object to store/retrieve the attribute
263 */
264 public Object getAttribute( Object key ) {
265 if (attributes != null) {
266 return attributes.get(key);
267 }
268 return null;
269 }
270
271
272 /** @return all attributes associated with this handle
273 */
274 public Collection getAttributes() {
275 if (attributes == null) {
276 attributes = new HashMap(3);
277 }
278 return attributes.values();
279 }
280
281
282 /** Convenience method, simply calls accept() on the contained instruction.
283 *
284 * @param v Visitor object
285 */
286 public void accept( Visitor v ) {
287 instruction.accept(v);
288 }
289 }
+0
-1265
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionList.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import org.apache.bcel.Constants;
28 import org.apache.bcel.classfile.Constant;
29 import org.apache.bcel.util.ByteSequence;
30
31 /**
32 * This class is a container for a list of <a
33 * href="Instruction.html">Instruction</a> objects. Instructions can
34 * be appended, inserted, moved, deleted, etc.. Instructions are being
35 * wrapped into <a
36 * href="InstructionHandle.html">InstructionHandles</a> objects that
37 * are returned upon append/insert operations. They give the user
38 * (read only) access to the list structure, such that it can be traversed and
39 * manipulated in a controlled way.
40 *
41 * A list is finally dumped to a byte code array with <a
42 * href="#getByteCode()">getByteCode</a>.
43 *
44 * @version $Id: InstructionList.java 386056 2006-03-15 11:31:56Z tcurdt $
45 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
46 * @see Instruction
47 * @see InstructionHandle
48 * @see BranchHandle
49 */
50 public class InstructionList implements Serializable {
51
52 private InstructionHandle start = null, end = null;
53 private int length = 0; // number of elements in list
54 private int[] byte_positions; // byte code offsets corresponding to instructions
55
56
57 /**
58 * Create (empty) instruction list.
59 */
60 public InstructionList() {
61 }
62
63
64 /**
65 * Create instruction list containing one instruction.
66 * @param i initial instruction
67 */
68 public InstructionList(Instruction i) {
69 append(i);
70 }
71
72
73 /**
74 * Create instruction list containing one instruction.
75 * @param i initial instruction
76 */
77 public InstructionList(BranchInstruction i) {
78 append(i);
79 }
80
81
82 /**
83 * Initialize list with (nonnull) compound instruction. Consumes argument
84 * list, i.e., it becomes empty.
85 *
86 * @param c compound instruction (list)
87 */
88 public InstructionList(CompoundInstruction c) {
89 append(c.getInstructionList());
90 }
91
92
93 /**
94 * Test for empty list.
95 */
96 public boolean isEmpty() {
97 return start == null;
98 } // && end == null
99
100
101 /**
102 * Find the target instruction (handle) that corresponds to the given target
103 * position (byte code offset).
104 *
105 * @param ihs array of instruction handles, i.e. il.getInstructionHandles()
106 * @param pos array of positions corresponding to ihs, i.e. il.getInstructionPositions()
107 * @param count length of arrays
108 * @param target target position to search for
109 * @return target position's instruction handle if available
110 */
111 public static InstructionHandle findHandle( InstructionHandle[] ihs, int[] pos, int count,
112 int target ) {
113 int l = 0, r = count - 1;
114 /* Do a binary search since the pos array is orderd.
115 */
116 do {
117 int i = (l + r) / 2;
118 int j = pos[i];
119 if (j == target) {
120 return ihs[i];
121 } else if (target < j) {
122 r = i - 1;
123 } else {
124 l = i + 1;
125 }
126 } while (l <= r);
127 return null;
128 }
129
130
131 /**
132 * Get instruction handle for instruction at byte code position pos.
133 * This only works properly, if the list is freshly initialized from a byte array or
134 * setPositions() has been called before this method.
135 *
136 * @param pos byte code position to search for
137 * @return target position's instruction handle if available
138 */
139 public InstructionHandle findHandle( int pos ) {
140 InstructionHandle[] ihs = getInstructionHandles();
141 return findHandle(ihs, byte_positions, length, pos);
142 }
143
144
145 /**
146 * Initialize instruction list from byte array.
147 *
148 * @param code byte array containing the instructions
149 */
150 public InstructionList(byte[] code) {
151 ByteSequence bytes = new ByteSequence(code);
152 InstructionHandle[] ihs = new InstructionHandle[code.length];
153 int[] pos = new int[code.length]; // Can't be more than that
154 int count = 0; // Contains actual length
155 /* Pass 1: Create an object for each byte code and append them
156 * to the list.
157 */
158 try {
159 while (bytes.available() > 0) {
160 // Remember byte offset and associate it with the instruction
161 int off = bytes.getIndex();
162 pos[count] = off;
163 /* Read one instruction from the byte stream, the byte position is set
164 * accordingly.
165 */
166 Instruction i = Instruction.readInstruction(bytes);
167 InstructionHandle ih;
168 if (i instanceof BranchInstruction) {
169 ih = append((BranchInstruction) i);
170 } else {
171 ih = append(i);
172 }
173 ih.setPosition(off);
174 ihs[count] = ih;
175 count++;
176 }
177 } catch (IOException e) {
178 throw new ClassGenException(e.toString());
179 }
180 byte_positions = new int[count]; // Trim to proper size
181 System.arraycopy(pos, 0, byte_positions, 0, count);
182 /* Pass 2: Look for BranchInstruction and update their targets, i.e.,
183 * convert offsets to instruction handles.
184 */
185 for (int i = 0; i < count; i++) {
186 if (ihs[i] instanceof BranchHandle) {
187 BranchInstruction bi = (BranchInstruction) ihs[i].instruction;
188 int target = bi.position + bi.getIndex(); /* Byte code position:
189 * relative -> absolute. */
190 // Search for target position
191 InstructionHandle ih = findHandle(ihs, pos, count, target);
192 if (ih == null) {
193 throw new ClassGenException("Couldn't find target for branch: " + bi);
194 }
195 bi.setTarget(ih); // Update target
196 // If it is a Select instruction, update all branch targets
197 if (bi instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH
198 Select s = (Select) bi;
199 int[] indices = s.getIndices();
200 for (int j = 0; j < indices.length; j++) {
201 target = bi.position + indices[j];
202 ih = findHandle(ihs, pos, count, target);
203 if (ih == null) {
204 throw new ClassGenException("Couldn't find target for switch: " + bi);
205 }
206 s.setTarget(j, ih); // Update target
207 }
208 }
209 }
210 }
211 }
212
213
214 /**
215 * Append another list after instruction (handle) ih contained in this list.
216 * Consumes argument list, i.e., it becomes empty.
217 *
218 * @param ih where to append the instruction list
219 * @param il Instruction list to append to this one
220 * @return instruction handle pointing to the <B>first</B> appended instruction
221 */
222 public InstructionHandle append( InstructionHandle ih, InstructionList il ) {
223 if (il == null) {
224 throw new ClassGenException("Appending null InstructionList");
225 }
226 if (il.isEmpty()) {
227 return ih;
228 }
229 InstructionHandle next = ih.next, ret = il.start;
230 ih.next = il.start;
231 il.start.prev = ih;
232 il.end.next = next;
233 if (next != null) {
234 next.prev = il.end;
235 } else {
236 end = il.end; // Update end ...
237 }
238 length += il.length; // Update length
239 il.clear();
240 return ret;
241 }
242
243
244 /**
245 * Append another list after instruction i contained in this list.
246 * Consumes argument list, i.e., it becomes empty.
247 *
248 * @param i where to append the instruction list
249 * @param il Instruction list to append to this one
250 * @return instruction handle pointing to the <B>first</B> appended instruction
251 */
252 public InstructionHandle append( Instruction i, InstructionList il ) {
253 InstructionHandle ih;
254 if ((ih = findInstruction2(i)) == null) {
255 throw new ClassGenException("Instruction " + i + " is not contained in this list.");
256 }
257 return append(ih, il);
258 }
259
260
261 /**
262 * Append another list to this one.
263 * Consumes argument list, i.e., it becomes empty.
264 *
265 * @param il list to append to end of this list
266 * @return instruction handle of the <B>first</B> appended instruction
267 */
268 public InstructionHandle append( InstructionList il ) {
269 if (il == null) {
270 throw new ClassGenException("Appending null InstructionList");
271 }
272 if (il.isEmpty()) {
273 return null;
274 }
275 if (isEmpty()) {
276 start = il.start;
277 end = il.end;
278 length = il.length;
279 il.clear();
280 return start;
281 } else {
282 return append(end, il); // was end.instruction
283 }
284 }
285
286
287 /**
288 * Append an instruction to the end of this list.
289 *
290 * @param ih instruction to append
291 */
292 private void append( InstructionHandle ih ) {
293 if (isEmpty()) {
294 start = end = ih;
295 ih.next = ih.prev = null;
296 } else {
297 end.next = ih;
298 ih.prev = end;
299 ih.next = null;
300 end = ih;
301 }
302 length++; // Update length
303 }
304
305
306 /**
307 * Append an instruction to the end of this list.
308 *
309 * @param i instruction to append
310 * @return instruction handle of the appended instruction
311 */
312 public InstructionHandle append( Instruction i ) {
313 InstructionHandle ih = InstructionHandle.getInstructionHandle(i);
314 append(ih);
315 return ih;
316 }
317
318
319 /**
320 * Append a branch instruction to the end of this list.
321 *
322 * @param i branch instruction to append
323 * @return branch instruction handle of the appended instruction
324 */
325 public BranchHandle append( BranchInstruction i ) {
326 BranchHandle ih = BranchHandle.getBranchHandle(i);
327 append(ih);
328 return ih;
329 }
330
331
332 /**
333 * Append a single instruction j after another instruction i, which
334 * must be in this list of course!
335 *
336 * @param i Instruction in list
337 * @param j Instruction to append after i in list
338 * @return instruction handle of the first appended instruction
339 */
340 public InstructionHandle append( Instruction i, Instruction j ) {
341 return append(i, new InstructionList(j));
342 }
343
344
345 /**
346 * Append a compound instruction, after instruction i.
347 *
348 * @param i Instruction in list
349 * @param c The composite instruction (containing an InstructionList)
350 * @return instruction handle of the first appended instruction
351 */
352 public InstructionHandle append( Instruction i, CompoundInstruction c ) {
353 return append(i, c.getInstructionList());
354 }
355
356
357 /**
358 * Append a compound instruction.
359 *
360 * @param c The composite instruction (containing an InstructionList)
361 * @return instruction handle of the first appended instruction
362 */
363 public InstructionHandle append( CompoundInstruction c ) {
364 return append(c.getInstructionList());
365 }
366
367
368 /**
369 * Append a compound instruction.
370 *
371 * @param ih where to append the instruction list
372 * @param c The composite instruction (containing an InstructionList)
373 * @return instruction handle of the first appended instruction
374 */
375 public InstructionHandle append( InstructionHandle ih, CompoundInstruction c ) {
376 return append(ih, c.getInstructionList());
377 }
378
379
380 /**
381 * Append an instruction after instruction (handle) ih contained in this list.
382 *
383 * @param ih where to append the instruction list
384 * @param i Instruction to append
385 * @return instruction handle pointing to the <B>first</B> appended instruction
386 */
387 public InstructionHandle append( InstructionHandle ih, Instruction i ) {
388 return append(ih, new InstructionList(i));
389 }
390
391
392 /**
393 * Append an instruction after instruction (handle) ih contained in this list.
394 *
395 * @param ih where to append the instruction list
396 * @param i Instruction to append
397 * @return instruction handle pointing to the <B>first</B> appended instruction
398 */
399 public BranchHandle append( InstructionHandle ih, BranchInstruction i ) {
400 BranchHandle bh = BranchHandle.getBranchHandle(i);
401 InstructionList il = new InstructionList();
402 il.append(bh);
403 append(ih, il);
404 return bh;
405 }
406
407
408 /**
409 * Insert another list before Instruction handle ih contained in this list.
410 * Consumes argument list, i.e., it becomes empty.
411 *
412 * @param ih where to append the instruction list
413 * @param il Instruction list to insert
414 * @return instruction handle of the first inserted instruction
415 */
416 public InstructionHandle insert( InstructionHandle ih, InstructionList il ) {
417 if (il == null) {
418 throw new ClassGenException("Inserting null InstructionList");
419 }
420 if (il.isEmpty()) {
421 return ih;
422 }
423 InstructionHandle prev = ih.prev, ret = il.start;
424 ih.prev = il.end;
425 il.end.next = ih;
426 il.start.prev = prev;
427 if (prev != null) {
428 prev.next = il.start;
429 } else {
430 start = il.start; // Update start ...
431 }
432 length += il.length; // Update length
433 il.clear();
434 return ret;
435 }
436
437
438 /**
439 * Insert another list.
440 *
441 * @param il list to insert before start of this list
442 * @return instruction handle of the first inserted instruction
443 */
444 public InstructionHandle insert( InstructionList il ) {
445 if (isEmpty()) {
446 append(il); // Code is identical for this case
447 return start;
448 } else {
449 return insert(start, il);
450 }
451 }
452
453
454 /**
455 * Insert an instruction at start of this list.
456 *
457 * @param ih instruction to insert
458 */
459 private void insert( InstructionHandle ih ) {
460 if (isEmpty()) {
461 start = end = ih;
462 ih.next = ih.prev = null;
463 } else {
464 start.prev = ih;
465 ih.next = start;
466 ih.prev = null;
467 start = ih;
468 }
469 length++;
470 }
471
472
473 /**
474 * Insert another list before Instruction i contained in this list.
475 * Consumes argument list, i.e., it becomes empty.
476 *
477 * @param i where to append the instruction list
478 * @param il Instruction list to insert
479 * @return instruction handle pointing to the first inserted instruction,
480 * i.e., il.getStart()
481 */
482 public InstructionHandle insert( Instruction i, InstructionList il ) {
483 InstructionHandle ih;
484 if ((ih = findInstruction1(i)) == null) {
485 throw new ClassGenException("Instruction " + i + " is not contained in this list.");
486 }
487 return insert(ih, il);
488 }
489
490
491 /**
492 * Insert an instruction at start of this list.
493 *
494 * @param i instruction to insert
495 * @return instruction handle of the inserted instruction
496 */
497 public InstructionHandle insert( Instruction i ) {
498 InstructionHandle ih = InstructionHandle.getInstructionHandle(i);
499 insert(ih);
500 return ih;
501 }
502
503
504 /**
505 * Insert a branch instruction at start of this list.
506 *
507 * @param i branch instruction to insert
508 * @return branch instruction handle of the appended instruction
509 */
510 public BranchHandle insert( BranchInstruction i ) {
511 BranchHandle ih = BranchHandle.getBranchHandle(i);
512 insert(ih);
513 return ih;
514 }
515
516
517 /**
518 * Insert a single instruction j before another instruction i, which
519 * must be in this list of course!
520 *
521 * @param i Instruction in list
522 * @param j Instruction to insert before i in list
523 * @return instruction handle of the first inserted instruction
524 */
525 public InstructionHandle insert( Instruction i, Instruction j ) {
526 return insert(i, new InstructionList(j));
527 }
528
529
530 /**
531 * Insert a compound instruction before instruction i.
532 *
533 * @param i Instruction in list
534 * @param c The composite instruction (containing an InstructionList)
535 * @return instruction handle of the first inserted instruction
536 */
537 public InstructionHandle insert( Instruction i, CompoundInstruction c ) {
538 return insert(i, c.getInstructionList());
539 }
540
541
542 /**
543 * Insert a compound instruction.
544 *
545 * @param c The composite instruction (containing an InstructionList)
546 * @return instruction handle of the first inserted instruction
547 */
548 public InstructionHandle insert( CompoundInstruction c ) {
549 return insert(c.getInstructionList());
550 }
551
552
553 /**
554 * Insert an instruction before instruction (handle) ih contained in this list.
555 *
556 * @param ih where to insert to the instruction list
557 * @param i Instruction to insert
558 * @return instruction handle of the first inserted instruction
559 */
560 public InstructionHandle insert( InstructionHandle ih, Instruction i ) {
561 return insert(ih, new InstructionList(i));
562 }
563
564
565 /**
566 * Insert a compound instruction.
567 *
568 * @param ih where to insert the instruction list
569 * @param c The composite instruction (containing an InstructionList)
570 * @return instruction handle of the first inserted instruction
571 */
572 public InstructionHandle insert( InstructionHandle ih, CompoundInstruction c ) {
573 return insert(ih, c.getInstructionList());
574 }
575
576
577 /**
578 * Insert an instruction before instruction (handle) ih contained in this list.
579 *
580 * @param ih where to insert to the instruction list
581 * @param i Instruction to insert
582 * @return instruction handle of the first inserted instruction
583 */
584 public BranchHandle insert( InstructionHandle ih, BranchInstruction i ) {
585 BranchHandle bh = BranchHandle.getBranchHandle(i);
586 InstructionList il = new InstructionList();
587 il.append(bh);
588 insert(ih, il);
589 return bh;
590 }
591
592
593 /**
594 * Take all instructions (handles) from "start" to "end" and append them after the
595 * new location "target". Of course, "end" must be after "start" and target must
596 * not be located withing this range. If you want to move something to the start of
597 * the list use null as value for target.<br>
598 * Any instruction targeters pointing to handles within the block, keep their targets.
599 *
600 * @param start of moved block
601 * @param end of moved block
602 * @param target of moved block
603 */
604 public void move( InstructionHandle start, InstructionHandle end, InstructionHandle target ) {
605 // Step 1: Check constraints
606 if ((start == null) || (end == null)) {
607 throw new ClassGenException("Invalid null handle: From " + start + " to " + end);
608 }
609 if ((target == start) || (target == end)) {
610 throw new ClassGenException("Invalid range: From " + start + " to " + end
611 + " contains target " + target);
612 }
613 for (InstructionHandle ih = start; ih != end.next; ih = ih.next) {
614 if (ih == null) {
615 throw new ClassGenException("Invalid range: From " + start + " to " + end);
616 } else if (ih == target) {
617 throw new ClassGenException("Invalid range: From " + start + " to " + end
618 + " contains target " + target);
619 }
620 }
621 // Step 2: Temporarily remove the given instructions from the list
622 InstructionHandle prev = start.prev, next = end.next;
623 if (prev != null) {
624 prev.next = next;
625 } else {
626 this.start = next;
627 }
628 if (next != null) {
629 next.prev = prev;
630 } else {
631 this.end = prev;
632 }
633 start.prev = end.next = null;
634 // Step 3: append after target
635 if (target == null) { // append to start of list
636 if (this.start != null) {
637 this.start.prev = end;
638 }
639 end.next = this.start;
640 this.start = start;
641 } else {
642 next = target.next;
643 target.next = start;
644 start.prev = target;
645 end.next = next;
646 if (next != null) {
647 next.prev = end;
648 } else {
649 this.end = end;
650 }
651 }
652 }
653
654
655 /**
656 * Move a single instruction (handle) to a new location.
657 *
658 * @param ih moved instruction
659 * @param target new location of moved instruction
660 */
661 public void move( InstructionHandle ih, InstructionHandle target ) {
662 move(ih, ih, target);
663 }
664
665
666 /**
667 * Remove from instruction `prev' to instruction `next' both contained
668 * in this list. Throws TargetLostException when one of the removed instruction handles
669 * is still being targeted.
670 *
671 * @param prev where to start deleting (predecessor, exclusive)
672 * @param next where to end deleting (successor, exclusive)
673 */
674 private void remove( InstructionHandle prev, InstructionHandle next )
675 throws TargetLostException {
676 InstructionHandle first, last; // First and last deleted instruction
677 if ((prev == null) && (next == null)) { // singleton list
678 first = last = start;
679 start = end = null;
680 } else {
681 if (prev == null) { // At start of list
682 first = start;
683 start = next;
684 } else {
685 first = prev.next;
686 prev.next = next;
687 }
688 if (next == null) { // At end of list
689 last = end;
690 end = prev;
691 } else {
692 last = next.prev;
693 next.prev = prev;
694 }
695 }
696 first.prev = null; // Completely separated from rest of list
697 last.next = null;
698 List target_vec = new ArrayList();
699 for (InstructionHandle ih = first; ih != null; ih = ih.next) {
700 ih.getInstruction().dispose(); // e.g. BranchInstructions release their targets
701 }
702 StringBuffer buf = new StringBuffer("{ ");
703 for (InstructionHandle ih = first; ih != null; ih = next) {
704 next = ih.next;
705 length--;
706 if (ih.hasTargeters()) { // Still got targeters?
707 target_vec.add(ih);
708 buf.append(ih.toString(true) + " ");
709 ih.next = ih.prev = null;
710 } else {
711 ih.dispose();
712 }
713 }
714 buf.append("}");
715 if (!target_vec.isEmpty()) {
716 InstructionHandle[] targeted = new InstructionHandle[target_vec.size()];
717 target_vec.toArray(targeted);
718 throw new TargetLostException(targeted, buf.toString());
719 }
720 }
721
722
723 /**
724 * Remove instruction from this list. The corresponding Instruction
725 * handles must not be reused!
726 *
727 * @param ih instruction (handle) to remove
728 */
729 public void delete( InstructionHandle ih ) throws TargetLostException {
730 remove(ih.prev, ih.next);
731 }
732
733
734 /**
735 * Remove instruction from this list. The corresponding Instruction
736 * handles must not be reused!
737 *
738 * @param i instruction to remove
739 */
740 public void delete( Instruction i ) throws TargetLostException {
741 InstructionHandle ih;
742 if ((ih = findInstruction1(i)) == null) {
743 throw new ClassGenException("Instruction " + i + " is not contained in this list.");
744 }
745 delete(ih);
746 }
747
748
749 /**
750 * Remove instructions from instruction `from' to instruction `to' contained
751 * in this list. The user must ensure that `from' is an instruction before
752 * `to', or risk havoc. The corresponding Instruction handles must not be reused!
753 *
754 * @param from where to start deleting (inclusive)
755 * @param to where to end deleting (inclusive)
756 */
757 public void delete( InstructionHandle from, InstructionHandle to ) throws TargetLostException {
758 remove(from.prev, to.next);
759 }
760
761
762 /**
763 * Remove instructions from instruction `from' to instruction `to' contained
764 * in this list. The user must ensure that `from' is an instruction before
765 * `to', or risk havoc. The corresponding Instruction handles must not be reused!
766 *
767 * @param from where to start deleting (inclusive)
768 * @param to where to end deleting (inclusive)
769 */
770 public void delete( Instruction from, Instruction to ) throws TargetLostException {
771 InstructionHandle from_ih, to_ih;
772 if ((from_ih = findInstruction1(from)) == null) {
773 throw new ClassGenException("Instruction " + from + " is not contained in this list.");
774 }
775 if ((to_ih = findInstruction2(to)) == null) {
776 throw new ClassGenException("Instruction " + to + " is not contained in this list.");
777 }
778 delete(from_ih, to_ih);
779 }
780
781
782 /**
783 * Search for given Instruction reference, start at beginning of list.
784 *
785 * @param i instruction to search for
786 * @return instruction found on success, null otherwise
787 */
788 private InstructionHandle findInstruction1( Instruction i ) {
789 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
790 if (ih.instruction == i) {
791 return ih;
792 }
793 }
794 return null;
795 }
796
797
798 /**
799 * Search for given Instruction reference, start at end of list
800 *
801 * @param i instruction to search for
802 * @return instruction found on success, null otherwise
803 */
804 private InstructionHandle findInstruction2( Instruction i ) {
805 for (InstructionHandle ih = end; ih != null; ih = ih.prev) {
806 if (ih.instruction == i) {
807 return ih;
808 }
809 }
810 return null;
811 }
812
813
814 public boolean contains( InstructionHandle i ) {
815 if (i == null) {
816 return false;
817 }
818 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
819 if (ih == i) {
820 return true;
821 }
822 }
823 return false;
824 }
825
826
827 public boolean contains( Instruction i ) {
828 return findInstruction1(i) != null;
829 }
830
831
832 public void setPositions() {
833 setPositions(false);
834 }
835
836
837 /**
838 * Give all instructions their position number (offset in byte stream), i.e.,
839 * make the list ready to be dumped.
840 *
841 * @param check Perform sanity checks, e.g. if all targeted instructions really belong
842 * to this list
843 */
844 public void setPositions( boolean check ) {
845 int max_additional_bytes = 0, additional_bytes = 0;
846 int index = 0, count = 0;
847 int[] pos = new int[length];
848 /* Pass 0: Sanity checks
849 */
850 if (check) {
851 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
852 Instruction i = ih.instruction;
853 if (i instanceof BranchInstruction) { // target instruction within list?
854 Instruction inst = ((BranchInstruction) i).getTarget().instruction;
855 if (!contains(inst)) {
856 throw new ClassGenException("Branch target of "
857 + Constants.OPCODE_NAMES[i.opcode] + ":" + inst
858 + " not in instruction list");
859 }
860 if (i instanceof Select) {
861 InstructionHandle[] targets = ((Select) i).getTargets();
862 for (int j = 0; j < targets.length; j++) {
863 inst = targets[j].instruction;
864 if (!contains(inst)) {
865 throw new ClassGenException("Branch target of "
866 + Constants.OPCODE_NAMES[i.opcode] + ":" + inst
867 + " not in instruction list");
868 }
869 }
870 }
871 if (!(ih instanceof BranchHandle)) {
872 throw new ClassGenException("Branch instruction "
873 + Constants.OPCODE_NAMES[i.opcode] + ":" + inst
874 + " not contained in BranchHandle.");
875 }
876 }
877 }
878 }
879 /* Pass 1: Set position numbers and sum up the maximum number of bytes an
880 * instruction may be shifted.
881 */
882 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
883 Instruction i = ih.instruction;
884 ih.setPosition(index);
885 pos[count++] = index;
886 /* Get an estimate about how many additional bytes may be added, because
887 * BranchInstructions may have variable length depending on the target
888 * offset (short vs. int) or alignment issues (TABLESWITCH and
889 * LOOKUPSWITCH).
890 */
891 switch (i.getOpcode()) {
892 case Constants.JSR:
893 case Constants.GOTO:
894 max_additional_bytes += 2;
895 break;
896 case Constants.TABLESWITCH:
897 case Constants.LOOKUPSWITCH:
898 max_additional_bytes += 3;
899 break;
900 }
901 index += i.getLength();
902 }
903 /* Pass 2: Expand the variable-length (Branch)Instructions depending on
904 * the target offset (short or int) and ensure that branch targets are
905 * within this list.
906 */
907 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
908 additional_bytes += ih.updatePosition(additional_bytes, max_additional_bytes);
909 }
910 /* Pass 3: Update position numbers (which may have changed due to the
911 * preceding expansions), like pass 1.
912 */
913 index = count = 0;
914 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
915 Instruction i = ih.instruction;
916 ih.setPosition(index);
917 pos[count++] = index;
918 index += i.getLength();
919 }
920 byte_positions = new int[count]; // Trim to proper size
921 System.arraycopy(pos, 0, byte_positions, 0, count);
922 }
923
924
925 /**
926 * When everything is finished, use this method to convert the instruction
927 * list into an array of bytes.
928 *
929 * @return the byte code ready to be dumped
930 */
931 public byte[] getByteCode() {
932 // Update position indices of instructions
933 setPositions();
934 ByteArrayOutputStream b = new ByteArrayOutputStream();
935 DataOutputStream out = new DataOutputStream(b);
936 try {
937 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
938 Instruction i = ih.instruction;
939 i.dump(out); // Traverse list
940 }
941 } catch (IOException e) {
942 System.err.println(e);
943 return null;
944 }
945 return b.toByteArray();
946 }
947
948
949 /**
950 * @return an array of instructions without target information for branch instructions.
951 */
952 public Instruction[] getInstructions() {
953 ByteSequence bytes = new ByteSequence(getByteCode());
954 List instructions = new ArrayList();
955 try {
956 while (bytes.available() > 0) {
957 instructions.add(Instruction.readInstruction(bytes));
958 }
959 } catch (IOException e) {
960 throw new ClassGenException(e.toString());
961 }
962 return (Instruction[]) instructions.toArray(new Instruction[instructions.size()]);
963 }
964
965
966 public String toString() {
967 return toString(true);
968 }
969
970
971 /**
972 * @param verbose toggle output format
973 * @return String containing all instructions in this list.
974 */
975 public String toString( boolean verbose ) {
976 StringBuffer buf = new StringBuffer();
977 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
978 buf.append(ih.toString(verbose)).append("\n");
979 }
980 return buf.toString();
981 }
982
983
984 /**
985 * @return Enumeration that lists all instructions (handles)
986 */
987 public Iterator iterator() {
988 return new Iterator() {
989
990 private InstructionHandle ih = start;
991
992
993 public Object next() {
994 InstructionHandle i = ih;
995 ih = ih.next;
996 return i;
997 }
998
999
1000 public void remove() {
1001 throw new UnsupportedOperationException();
1002 }
1003
1004
1005 public boolean hasNext() {
1006 return ih != null;
1007 }
1008 };
1009 }
1010
1011
1012 /**
1013 * @return array containing all instructions (handles)
1014 */
1015 public InstructionHandle[] getInstructionHandles() {
1016 InstructionHandle[] ihs = new InstructionHandle[length];
1017 InstructionHandle ih = start;
1018 for (int i = 0; i < length; i++) {
1019 ihs[i] = ih;
1020 ih = ih.next;
1021 }
1022 return ihs;
1023 }
1024
1025
1026 /**
1027 * Get positions (offsets) of all instructions in the list. This relies on that
1028 * the list has been freshly created from an byte code array, or that setPositions()
1029 * has been called. Otherwise this may be inaccurate.
1030 *
1031 * @return array containing all instruction's offset in byte code
1032 */
1033 public int[] getInstructionPositions() {
1034 return byte_positions;
1035 }
1036
1037
1038 /**
1039 * @return complete, i.e., deep copy of this list
1040 */
1041 public InstructionList copy() {
1042 Map map = new HashMap();
1043 InstructionList il = new InstructionList();
1044 /* Pass 1: Make copies of all instructions, append them to the new list
1045 * and associate old instruction references with the new ones, i.e.,
1046 * a 1:1 mapping.
1047 */
1048 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
1049 Instruction i = ih.instruction;
1050 Instruction c = i.copy(); // Use clone for shallow copy
1051 if (c instanceof BranchInstruction) {
1052 map.put(ih, il.append((BranchInstruction) c));
1053 } else {
1054 map.put(ih, il.append(c));
1055 }
1056 }
1057 /* Pass 2: Update branch targets.
1058 */
1059 InstructionHandle ih = start;
1060 InstructionHandle ch = il.start;
1061 while (ih != null) {
1062 Instruction i = ih.instruction;
1063 Instruction c = ch.instruction;
1064 if (i instanceof BranchInstruction) {
1065 BranchInstruction bi = (BranchInstruction) i;
1066 BranchInstruction bc = (BranchInstruction) c;
1067 InstructionHandle itarget = bi.getTarget(); // old target
1068 // New target is in hash map
1069 bc.setTarget((InstructionHandle) map.get(itarget));
1070 if (bi instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH
1071 InstructionHandle[] itargets = ((Select) bi).getTargets();
1072 InstructionHandle[] ctargets = ((Select) bc).getTargets();
1073 for (int j = 0; j < itargets.length; j++) { // Update all targets
1074 ctargets[j] = (InstructionHandle) map.get(itargets[j]);
1075 }
1076 }
1077 }
1078 ih = ih.next;
1079 ch = ch.next;
1080 }
1081 return il;
1082 }
1083
1084
1085 /** Replace all references to the old constant pool with references to the new
1086 * constant pool
1087 */
1088 public void replaceConstantPool( ConstantPoolGen old_cp, ConstantPoolGen new_cp ) {
1089 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
1090 Instruction i = ih.instruction;
1091 if (i instanceof CPInstruction) {
1092 CPInstruction ci = (CPInstruction) i;
1093 Constant c = old_cp.getConstant(ci.getIndex());
1094 ci.setIndex(new_cp.addConstant(c, old_cp));
1095 }
1096 }
1097 }
1098
1099
1100 private void clear() {
1101 start = end = null;
1102 length = 0;
1103 }
1104
1105
1106 /**
1107 * Delete contents of list. Provides besser memory utilization,
1108 * because the system then may reuse the instruction handles. This
1109 * method is typically called right after
1110 * <href="MethodGen.html#getMethod()">MethodGen.getMethod()</a>.
1111 */
1112 public void dispose() {
1113 // Traverse in reverse order, because ih.next is overwritten
1114 for (InstructionHandle ih = end; ih != null; ih = ih.prev) {
1115 /* Causes BranchInstructions to release target and targeters, because it
1116 * calls dispose() on the contained instruction.
1117 */
1118 ih.dispose();
1119 }
1120 clear();
1121 }
1122
1123
1124 /**
1125 * @return start of list
1126 */
1127 public InstructionHandle getStart() {
1128 return start;
1129 }
1130
1131
1132 /**
1133 * @return end of list
1134 */
1135 public InstructionHandle getEnd() {
1136 return end;
1137 }
1138
1139
1140 /**
1141 * @return length of list (Number of instructions, not bytes)
1142 */
1143 public int getLength() {
1144 return length;
1145 }
1146
1147
1148 /**
1149 * @return length of list (Number of instructions, not bytes)
1150 */
1151 public int size() {
1152 return length;
1153 }
1154
1155
1156 /**
1157 * Redirect all references from old_target to new_target, i.e., update targets
1158 * of branch instructions.
1159 *
1160 * @param old_target the old target instruction handle
1161 * @param new_target the new target instruction handle
1162 */
1163 public void redirectBranches( InstructionHandle old_target, InstructionHandle new_target ) {
1164 for (InstructionHandle ih = start; ih != null; ih = ih.next) {
1165 Instruction i = ih.getInstruction();
1166 if (i instanceof BranchInstruction) {
1167 BranchInstruction b = (BranchInstruction) i;
1168 InstructionHandle target = b.getTarget();
1169 if (target == old_target) {
1170 b.setTarget(new_target);
1171 }
1172 if (b instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH
1173 InstructionHandle[] targets = ((Select) b).getTargets();
1174 for (int j = 0; j < targets.length; j++) {
1175 if (targets[j] == old_target) {
1176 ((Select) b).setTarget(j, new_target);
1177 }
1178 }
1179 }
1180 }
1181 }
1182 }
1183
1184
1185 /**
1186 * Redirect all references of local variables from old_target to new_target.
1187 *
1188 * @param lg array of local variables
1189 * @param old_target the old target instruction handle
1190 * @param new_target the new target instruction handle
1191 * @see MethodGen
1192 */
1193 public void redirectLocalVariables( LocalVariableGen[] lg, InstructionHandle old_target,
1194 InstructionHandle new_target ) {
1195 for (int i = 0; i < lg.length; i++) {
1196 InstructionHandle start = lg[i].getStart();
1197 InstructionHandle end = lg[i].getEnd();
1198 if (start == old_target) {
1199 lg[i].setStart(new_target);
1200 }
1201 if (end == old_target) {
1202 lg[i].setEnd(new_target);
1203 }
1204 }
1205 }
1206
1207
1208 /**
1209 * Redirect all references of exception handlers from old_target to new_target.
1210 *
1211 * @param exceptions array of exception handlers
1212 * @param old_target the old target instruction handle
1213 * @param new_target the new target instruction handle
1214 * @see MethodGen
1215 */
1216 public void redirectExceptionHandlers( CodeExceptionGen[] exceptions,
1217 InstructionHandle old_target, InstructionHandle new_target ) {
1218 for (int i = 0; i < exceptions.length; i++) {
1219 if (exceptions[i].getStartPC() == old_target) {
1220 exceptions[i].setStartPC(new_target);
1221 }
1222 if (exceptions[i].getEndPC() == old_target) {
1223 exceptions[i].setEndPC(new_target);
1224 }
1225 if (exceptions[i].getHandlerPC() == old_target) {
1226 exceptions[i].setHandlerPC(new_target);
1227 }
1228 }
1229 }
1230
1231 private List observers;
1232
1233
1234 /** Add observer for this object.
1235 */
1236 public void addObserver( InstructionListObserver o ) {
1237 if (observers == null) {
1238 observers = new ArrayList();
1239 }
1240 observers.add(o);
1241 }
1242
1243
1244 /** Remove observer for this object.
1245 */
1246 public void removeObserver( InstructionListObserver o ) {
1247 if (observers != null) {
1248 observers.remove(o);
1249 }
1250 }
1251
1252
1253 /** Call notify() method on all observers. This method is not called
1254 * automatically whenever the state has changed, but has to be
1255 * called by the user after he has finished editing the object.
1256 */
1257 public void update() {
1258 if (observers != null) {
1259 for (Iterator e = observers.iterator(); e.hasNext();) {
1260 ((InstructionListObserver) e.next()).notify(this);
1261 }
1262 }
1263 }
1264 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionListObserver.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Implement this interface if you're interested in changes to an InstructionList object
20 * and register yourself with addObserver().
21 *
22 * @version $Id: InstructionListObserver.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface InstructionListObserver {
26
27 public void notify( InstructionList list );
28 }
+0
-35
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InstructionTargeter.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote that a class targets InstructionHandles within an InstructionList. Namely
20 * the following implementers:
21 *
22 * @see BranchHandle
23 * @see LocalVariableGen
24 * @see CodeExceptionGen
25 * @version $Id: InstructionTargeter.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public interface InstructionTargeter {
29
30 public boolean containsTarget( InstructionHandle ih );
31
32
33 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih );
34 }
+0
-118
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/InvokeInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.StringTokenizer;
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.classfile.Constant;
21 import org.apache.bcel.classfile.ConstantPool;
22
23 /**
24 * Super class for the INVOKExxx family of instructions.
25 *
26 * @version $Id: InvokeInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public abstract class InvokeInstruction extends FieldOrMethod implements ExceptionThrower,
30 TypedInstruction, StackConsumer, StackProducer {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 InvokeInstruction() {
37 }
38
39
40 /**
41 * @param index to constant pool
42 */
43 protected InvokeInstruction(short opcode, int index) {
44 super(opcode, index);
45 }
46
47
48 /**
49 * @return mnemonic for instruction with symbolic references resolved
50 */
51 public String toString( ConstantPool cp ) {
52 Constant c = cp.getConstant(index);
53 StringTokenizer tok = new StringTokenizer(cp.constantToString(c));
54 return Constants.OPCODE_NAMES[opcode] + " " + tok.nextToken().replace('.', '/')
55 + tok.nextToken();
56 }
57
58
59 /**
60 * Also works for instructions whose stack effect depends on the
61 * constant pool entry they reference.
62 * @return Number of words consumed from stack by this instruction
63 */
64 public int consumeStack( ConstantPoolGen cpg ) {
65 String signature = getSignature(cpg);
66 Type[] args = Type.getArgumentTypes(signature);
67 int sum;
68 if (opcode == Constants.INVOKESTATIC) {
69 sum = 0;
70 } else {
71 sum = 1; // this reference
72 }
73 int n = args.length;
74 for (int i = 0; i < n; i++) {
75 sum += args[i].getSize();
76 }
77 return sum;
78 }
79
80
81 /**
82 * Also works for instructions whose stack effect depends on the
83 * constant pool entry they reference.
84 * @return Number of words produced onto stack by this instruction
85 */
86 public int produceStack( ConstantPoolGen cpg ) {
87 return getReturnType(cpg).getSize();
88 }
89
90
91 /** @return return type of referenced method.
92 */
93 public Type getType( ConstantPoolGen cpg ) {
94 return getReturnType(cpg);
95 }
96
97
98 /** @return name of referenced method.
99 */
100 public String getMethodName( ConstantPoolGen cpg ) {
101 return getName(cpg);
102 }
103
104
105 /** @return return type of referenced method.
106 */
107 public Type getReturnType( ConstantPoolGen cpg ) {
108 return Type.getReturnType(getSignature(cpg));
109 }
110
111
112 /** @return argument types of referenced method.
113 */
114 public Type[] getArgumentTypes( ConstantPoolGen cpg ) {
115 return Type.getArgumentTypes(getSignature(cpg));
116 }
117 }
+0
-86
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/JSR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20
21 /**
22 * JSR - Jump to subroutine
23 *
24 * @version $Id: JSR.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class JSR extends JsrInstruction implements VariableLengthInstruction {
28
29 /**
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 JSR() {
34 }
35
36
37 public JSR(InstructionHandle target) {
38 super(org.apache.bcel.Constants.JSR, target);
39 }
40
41
42 /**
43 * Dump instruction as byte code to stream out.
44 * @param out Output stream
45 */
46 public void dump( DataOutputStream out ) throws IOException {
47 index = getTargetOffset();
48 if (opcode == org.apache.bcel.Constants.JSR) {
49 super.dump(out);
50 } else { // JSR_W
51 index = getTargetOffset();
52 out.writeByte(opcode);
53 out.writeInt(index);
54 }
55 }
56
57
58 protected int updatePosition( int offset, int max_offset ) {
59 int i = getTargetOffset(); // Depending on old position value
60 position += offset; // Position may be shifted by preceding expansions
61 if (Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
62 opcode = org.apache.bcel.Constants.JSR_W;
63 length = 5;
64 return 2; // 5 - 3
65 }
66 return 0;
67 }
68
69
70 /**
71 * Call corresponding visitor method(s). The order is:
72 * Call visitor methods of implemented interfaces first, then
73 * call methods according to the class hierarchy in descending order,
74 * i.e., the most specific visitXXX() call comes last.
75 *
76 * @param v Visitor object
77 */
78 public void accept( Visitor v ) {
79 v.visitStackProducer(this);
80 v.visitVariableLengthInstruction(this);
81 v.visitBranchInstruction(this);
82 v.visitJsrInstruction(this);
83 v.visitJSR(this);
84 }
85 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/JSR_W.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * JSR_W - Jump to subroutine
24 *
25 * @version $Id: JSR_W.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public class JSR_W extends JsrInstruction {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 JSR_W() {
35 }
36
37
38 public JSR_W(InstructionHandle target) {
39 super(org.apache.bcel.Constants.JSR_W, target);
40 length = 5;
41 }
42
43
44 /**
45 * Dump instruction as byte code to stream out.
46 * @param out Output stream
47 */
48 public void dump( DataOutputStream out ) throws IOException {
49 index = getTargetOffset();
50 out.writeByte(opcode);
51 out.writeInt(index);
52 }
53
54
55 /**
56 * Read needed data (e.g. index) from file.
57 */
58 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
59 index = bytes.readInt();
60 length = 5;
61 }
62
63
64 /**
65 * Call corresponding visitor method(s). The order is:
66 * Call visitor methods of implemented interfaces first, then
67 * call methods according to the class hierarchy in descending order,
68 * i.e., the most specific visitXXX() call comes last.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitStackProducer(this);
74 v.visitBranchInstruction(this);
75 v.visitJsrInstruction(this);
76 v.visitJSR_W(this);
77 }
78 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/JsrInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Super class for JSR - Jump to subroutine
20 *
21 * @version $Id: JsrInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class JsrInstruction extends BranchInstruction implements UnconditionalBranch,
25 TypedInstruction, StackProducer {
26
27 JsrInstruction(short opcode, InstructionHandle target) {
28 super(opcode, target);
29 }
30
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 JsrInstruction() {
37 }
38
39
40 /** @return return address type
41 */
42 public Type getType( ConstantPoolGen cp ) {
43 return new ReturnaddressType(physicalSuccessor());
44 }
45
46
47 /**
48 * Returns an InstructionHandle to the physical successor
49 * of this JsrInstruction. <B>For this method to work,
50 * this JsrInstruction object must not be shared between
51 * multiple InstructionHandle objects!</B>
52 * Formally, there must not be InstructionHandle objects
53 * i, j where i != j and i.getInstruction() == this ==
54 * j.getInstruction().
55 * @return an InstructionHandle to the "next" instruction that
56 * will be executed when RETurned from a subroutine.
57 */
58 public InstructionHandle physicalSuccessor() {
59 InstructionHandle ih = this.target;
60 // Rewind!
61 while (ih.getPrev() != null) {
62 ih = ih.getPrev();
63 }
64 // Find the handle for "this" JsrInstruction object.
65 while (ih.getInstruction() != this) {
66 ih = ih.getNext();
67 }
68 InstructionHandle toThis = ih;
69 while (ih != null) {
70 ih = ih.getNext();
71 if ((ih != null) && (ih.getInstruction() == this)) {
72 throw new RuntimeException("physicalSuccessor() called on a shared JsrInstruction.");
73 }
74 }
75 // Return the physical successor
76 return toThis.getNext();
77 }
78 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/L2D.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * L2D - Convert long to double
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: L2D.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class L2D extends ConversionInstruction {
26
27 public L2D() {
28 super(org.apache.bcel.Constants.L2D);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitConversionInstruction(this);
45 v.visitL2D(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/L2F.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * L2F - Convert long to float
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: L2F.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class L2F extends ConversionInstruction {
26
27 public L2F() {
28 super(org.apache.bcel.Constants.L2F);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitConversionInstruction(this);
45 v.visitL2F(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/L2I.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * L2I - Convert long to int
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: L2I.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class L2I extends ConversionInstruction {
26
27 public L2I() {
28 super(org.apache.bcel.Constants.L2I);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitConversionInstruction(this);
45 v.visitL2I(this);
46 }
47 }
+0
-49
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LADD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LADD - Add longs
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: LADD.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LADD extends ArithmeticInstruction {
27
28 public LADD() {
29 super(org.apache.bcel.Constants.LADD);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitTypedInstruction(this);
43 v.visitStackProducer(this);
44 v.visitStackConsumer(this);
45 v.visitArithmeticInstruction(this);
46 v.visitLADD(this);
47 }
48 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LALOAD - Load long from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value1, value2</PRE>
21 *
22 * @version $Id: LALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LALOAD extends ArrayInstruction implements StackProducer {
26
27 /** Load long from array
28 */
29 public LALOAD() {
30 super(org.apache.bcel.Constants.LALOAD);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackProducer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitLALOAD(this);
48 }
49 }
+0
-49
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LAND.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LAND - Bitwise AND longs
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: LAND.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LAND extends ArithmeticInstruction {
27
28 public LAND() {
29 super(org.apache.bcel.Constants.LAND);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitTypedInstruction(this);
43 v.visitStackProducer(this);
44 v.visitStackConsumer(this);
45 v.visitArithmeticInstruction(this);
46 v.visitLAND(this);
47 }
48 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LASTORE - Store into long array
20 * <PRE>Stack: ..., arrayref, index, value.word1, value.word2 -&gt; ...</PRE>
21 *
22 * @version $Id: LASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LASTORE extends ArrayInstruction implements StackConsumer {
26
27 /** Store long into array
28 */
29 public LASTORE() {
30 super(org.apache.bcel.Constants.LASTORE);
31 }
32
33
34 /**
35 * Call corresponding visitor method(s). The order is:
36 * Call visitor methods of implemented interfaces first, then
37 * call methods according to the class hierarchy in descending order,
38 * i.e., the most specific visitXXX() call comes last.
39 *
40 * @param v Visitor object
41 */
42 public void accept( Visitor v ) {
43 v.visitStackConsumer(this);
44 v.visitExceptionThrower(this);
45 v.visitTypedInstruction(this);
46 v.visitArrayInstruction(this);
47 v.visitLASTORE(this);
48 }
49 }
+0
-55
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LCMP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LCMP - Compare longs:
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result <= -1, 0, 1>
22 *
23 * @version $Id: LCMP.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LCMP extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
27
28 public LCMP() {
29 super(org.apache.bcel.Constants.LCMP, (short) 1);
30 }
31
32
33 /** @return Type.LONG
34 */
35 public Type getType( ConstantPoolGen cp ) {
36 return Type.LONG;
37 }
38
39
40 /**
41 * Call corresponding visitor method(s). The order is:
42 * Call visitor methods of implemented interfaces first, then
43 * call methods according to the class hierarchy in descending order,
44 * i.e., the most specific visitXXX() call comes last.
45 *
46 * @param v Visitor object
47 */
48 public void accept( Visitor v ) {
49 v.visitTypedInstruction(this);
50 v.visitStackProducer(this);
51 v.visitStackConsumer(this);
52 v.visitLCMP(this);
53 }
54 }
+0
-80
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LCONST.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LCONST - Push 0 or 1, other values cause an exception
20 *
21 * <PRE>Stack: ... -&gt; ..., </PRE>
22 *
23 * @version $Id: LCONST.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LCONST extends Instruction implements ConstantPushInstruction, TypedInstruction {
27
28 private long value;
29
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 LCONST() {
36 }
37
38
39 public LCONST(long l) {
40 super(org.apache.bcel.Constants.LCONST_0, (short) 1);
41 if (l == 0) {
42 opcode = org.apache.bcel.Constants.LCONST_0;
43 } else if (l == 1) {
44 opcode = org.apache.bcel.Constants.LCONST_1;
45 } else {
46 throw new ClassGenException("LCONST can be used only for 0 and 1: " + l);
47 }
48 value = l;
49 }
50
51
52 public Number getValue() {
53 return new Long(value);
54 }
55
56
57 /** @return Type.LONG
58 */
59 public Type getType( ConstantPoolGen cp ) {
60 return Type.LONG;
61 }
62
63
64 /**
65 * Call corresponding visitor method(s). The order is:
66 * Call visitor methods of implemented interfaces first, then
67 * call methods according to the class hierarchy in descending order,
68 * i.e., the most specific visitXXX() call comes last.
69 *
70 * @param v Visitor object
71 */
72 public void accept( Visitor v ) {
73 v.visitPushInstruction(this);
74 v.visitStackProducer(this);
75 v.visitTypedInstruction(this);
76 v.visitConstantPushInstruction(this);
77 v.visitLCONST(this);
78 }
79 }
+0
-148
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LDC.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * LDC - Push item from constant pool.
24 *
25 * <PRE>Stack: ... -&gt; ..., item</PRE>
26 *
27 * @version $Id: LDC.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class LDC extends CPInstruction implements PushInstruction, ExceptionThrower,
31 TypedInstruction {
32
33 /**
34 * Empty constructor needed for the Class.newInstance() statement in
35 * Instruction.readInstruction(). Not to be used otherwise.
36 */
37 LDC() {
38 }
39
40
41 public LDC(int index) {
42 super(org.apache.bcel.Constants.LDC_W, index);
43 setSize();
44 }
45
46
47 // Adjust to proper size
48 protected final void setSize() {
49 if (index <= org.apache.bcel.Constants.MAX_BYTE) { // Fits in one byte?
50 opcode = org.apache.bcel.Constants.LDC;
51 length = 2;
52 } else {
53 opcode = org.apache.bcel.Constants.LDC_W;
54 length = 3;
55 }
56 }
57
58
59 /**
60 * Dump instruction as byte code to stream out.
61 * @param out Output stream
62 */
63 public void dump( DataOutputStream out ) throws IOException {
64 out.writeByte(opcode);
65 if (length == 2) {
66 out.writeByte(index);
67 } else {
68 out.writeShort(index);
69 }
70 }
71
72
73 /**
74 * Set the index to constant pool and adjust size.
75 */
76 public final void setIndex( int index ) {
77 super.setIndex(index);
78 setSize();
79 }
80
81
82 /**
83 * Read needed data (e.g. index) from file.
84 */
85 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
86 length = 2;
87 index = bytes.readUnsignedByte();
88 }
89
90
91 public Object getValue( ConstantPoolGen cpg ) {
92 org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index);
93 switch (c.getTag()) {
94 case org.apache.bcel.Constants.CONSTANT_String:
95 int i = ((org.apache.bcel.classfile.ConstantString) c).getStringIndex();
96 c = cpg.getConstantPool().getConstant(i);
97 return ((org.apache.bcel.classfile.ConstantUtf8) c).getBytes();
98 case org.apache.bcel.Constants.CONSTANT_Float:
99 return new Float(((org.apache.bcel.classfile.ConstantFloat) c).getBytes());
100 case org.apache.bcel.Constants.CONSTANT_Integer:
101 return new Integer(((org.apache.bcel.classfile.ConstantInteger) c).getBytes());
102 case org.apache.bcel.Constants.CONSTANT_Class:
103 return c;
104 default: // Never reached
105 throw new RuntimeException("Unknown or invalid constant type at " + index);
106 }
107 }
108
109
110 public Type getType( ConstantPoolGen cpg ) {
111 switch (cpg.getConstantPool().getConstant(index).getTag()) {
112 case org.apache.bcel.Constants.CONSTANT_String:
113 return Type.STRING;
114 case org.apache.bcel.Constants.CONSTANT_Float:
115 return Type.FLOAT;
116 case org.apache.bcel.Constants.CONSTANT_Integer:
117 return Type.INT;
118 case org.apache.bcel.Constants.CONSTANT_Class:
119 return Type.CLASS;
120 default: // Never reached
121 throw new RuntimeException("Unknown or invalid constant type at " + index);
122 }
123 }
124
125
126 public Class[] getExceptions() {
127 return org.apache.bcel.ExceptionConstants.EXCS_STRING_RESOLUTION;
128 }
129
130
131 /**
132 * Call corresponding visitor method(s). The order is:
133 * Call visitor methods of implemented interfaces first, then
134 * call methods according to the class hierarchy in descending order,
135 * i.e., the most specific visitXXX() call comes last.
136 *
137 * @param v Visitor object
138 */
139 public void accept( Visitor v ) {
140 v.visitStackProducer(this);
141 v.visitPushInstruction(this);
142 v.visitExceptionThrower(this);
143 v.visitTypedInstruction(this);
144 v.visitCPInstruction(this);
145 v.visitLDC(this);
146 }
147 }
+0
-82
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LDC2_W.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LDC2_W - Push long or double from constant pool
20 *
21 * <PRE>Stack: ... -&gt; ..., item.word1, item.word2</PRE>
22 *
23 * @version $Id: LDC2_W.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LDC2_W extends CPInstruction implements PushInstruction, TypedInstruction {
27
28 /**
29 * Empty constructor needed for the Class.newInstance() statement in
30 * Instruction.readInstruction(). Not to be used otherwise.
31 */
32 LDC2_W() {
33 }
34
35
36 public LDC2_W(int index) {
37 super(org.apache.bcel.Constants.LDC2_W, index);
38 }
39
40
41 public Type getType( ConstantPoolGen cpg ) {
42 switch (cpg.getConstantPool().getConstant(index).getTag()) {
43 case org.apache.bcel.Constants.CONSTANT_Long:
44 return Type.LONG;
45 case org.apache.bcel.Constants.CONSTANT_Double:
46 return Type.DOUBLE;
47 default: // Never reached
48 throw new RuntimeException("Unknown constant type " + opcode);
49 }
50 }
51
52
53 public Number getValue( ConstantPoolGen cpg ) {
54 org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index);
55 switch (c.getTag()) {
56 case org.apache.bcel.Constants.CONSTANT_Long:
57 return new Long(((org.apache.bcel.classfile.ConstantLong) c).getBytes());
58 case org.apache.bcel.Constants.CONSTANT_Double:
59 return new Double(((org.apache.bcel.classfile.ConstantDouble) c).getBytes());
60 default: // Never reached
61 throw new RuntimeException("Unknown or invalid constant type at " + index);
62 }
63 }
64
65
66 /**
67 * Call corresponding visitor method(s). The order is:
68 * Call visitor methods of implemented interfaces first, then
69 * call methods according to the class hierarchy in descending order,
70 * i.e., the most specific visitXXX() call comes last.
71 *
72 * @param v Visitor object
73 */
74 public void accept( Visitor v ) {
75 v.visitStackProducer(this);
76 v.visitPushInstruction(this);
77 v.visitTypedInstruction(this);
78 v.visitCPInstruction(this);
79 v.visitLDC2_W(this);
80 }
81 }
+0
-54
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LDC_W.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.IOException;
19 import org.apache.bcel.util.ByteSequence;
20
21 /**
22 * LDC_W - Push item from constant pool (wide index)
23 *
24 * <PRE>Stack: ... -&gt; ..., item.word1, item.word2</PRE>
25 *
26 * @version $Id: LDC_W.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public class LDC_W extends LDC {
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 LDC_W() {
36 }
37
38
39 public LDC_W(int index) {
40 super(index);
41 }
42
43
44 /**
45 * Read needed data (i.e., index) from file.
46 */
47 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
48 setIndex(bytes.readUnsignedShort());
49 // Override just in case it has been changed
50 opcode = org.apache.bcel.Constants.LDC_W;
51 length = 3;
52 }
53 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LDIV.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LDIV - Divide longs
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: LDIV.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LDIV extends ArithmeticInstruction implements ExceptionThrower {
27
28 public LDIV() {
29 super(org.apache.bcel.Constants.LDIV);
30 }
31
32
33 public Class[] getExceptions() {
34 return new Class[] {
35 org.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION
36 };
37 }
38
39
40 /**
41 * Call corresponding visitor method(s). The order is:
42 * Call visitor methods of implemented interfaces first, then
43 * call methods according to the class hierarchy in descending order,
44 * i.e., the most specific visitXXX() call comes last.
45 *
46 * @param v Visitor object
47 */
48 public void accept( Visitor v ) {
49 v.visitExceptionThrower(this);
50 v.visitTypedInstruction(this);
51 v.visitStackProducer(this);
52 v.visitStackConsumer(this);
53 v.visitArithmeticInstruction(this);
54 v.visitLDIV(this);
55 }
56 }
+0
-54
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LLOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LLOAD - Load long from local variable
20 *<PRE>Stack ... -&GT; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: LLOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LLOAD extends LoadInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 LLOAD() {
32 super(org.apache.bcel.Constants.LLOAD, org.apache.bcel.Constants.LLOAD_0);
33 }
34
35
36 public LLOAD(int n) {
37 super(org.apache.bcel.Constants.LLOAD, org.apache.bcel.Constants.LLOAD_0, n);
38 }
39
40
41 /**
42 * Call corresponding visitor method(s). The order is:
43 * Call visitor methods of implemented interfaces first, then
44 * call methods according to the class hierarchy in descending order,
45 * i.e., the most specific visitXXX() call comes last.
46 *
47 * @param v Visitor object
48 */
49 public void accept( Visitor v ) {
50 super.accept(v);
51 v.visitLLOAD(this);
52 }
53 }
+0
-49
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LMUL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LMUL - Multiply longs
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: LMUL.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LMUL extends ArithmeticInstruction {
27
28 public LMUL() {
29 super(org.apache.bcel.Constants.LMUL);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitTypedInstruction(this);
43 v.visitStackProducer(this);
44 v.visitStackConsumer(this);
45 v.visitArithmeticInstruction(this);
46 v.visitLMUL(this);
47 }
48 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LNEG.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LNEG - Negate long
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: LNEG.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LNEG extends ArithmeticInstruction {
26
27 public LNEG() {
28 super(org.apache.bcel.Constants.LNEG);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLNEG(this);
46 }
47 }
+0
-95
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LOOKUPSWITCH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * LOOKUPSWITCH - Switch with unordered set of values
24 *
25 * @version $Id: LOOKUPSWITCH.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 * @see SWITCH
28 */
29 public class LOOKUPSWITCH extends Select {
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 LOOKUPSWITCH() {
36 }
37
38
39 public LOOKUPSWITCH(int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget) {
40 super(org.apache.bcel.Constants.LOOKUPSWITCH, match, targets, defaultTarget);
41 length = (short) (9 + match_length * 8); /* alignment remainder assumed
42 * 0 here, until dump time. */
43 fixed_length = length;
44 }
45
46
47 /**
48 * Dump instruction as byte code to stream out.
49 * @param out Output stream
50 */
51 public void dump( DataOutputStream out ) throws IOException {
52 super.dump(out);
53 out.writeInt(match_length); // npairs
54 for (int i = 0; i < match_length; i++) {
55 out.writeInt(match[i]); // match-offset pairs
56 out.writeInt(indices[i] = getTargetOffset(targets[i]));
57 }
58 }
59
60
61 /**
62 * Read needed data (e.g. index) from file.
63 */
64 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
65 super.initFromFile(bytes, wide); // reads padding
66 match_length = bytes.readInt();
67 fixed_length = (short) (9 + match_length * 8);
68 length = (short) (fixed_length + padding);
69 match = new int[match_length];
70 indices = new int[match_length];
71 targets = new InstructionHandle[match_length];
72 for (int i = 0; i < match_length; i++) {
73 match[i] = bytes.readInt();
74 indices[i] = bytes.readInt();
75 }
76 }
77
78
79 /**
80 * Call corresponding visitor method(s). The order is:
81 * Call visitor methods of implemented interfaces first, then
82 * call methods according to the class hierarchy in descending order,
83 * i.e., the most specific visitXXX() call comes last.
84 *
85 * @param v Visitor object
86 */
87 public void accept( Visitor v ) {
88 v.visitVariableLengthInstruction(this);
89 v.visitStackProducer(this);
90 v.visitBranchInstruction(this);
91 v.visitSelect(this);
92 v.visitLOOKUPSWITCH(this);
93 }
94 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LOR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LOR - Bitwise OR long
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: LOR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LOR extends ArithmeticInstruction {
26
27 public LOR() {
28 super(org.apache.bcel.Constants.LOR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLOR(this);
46 }
47 }
+0
-56
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LREM.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LREM - Remainder of long
20 * <PRE>Stack: ..., value1, value2 -&gt; result</PRE>
21 *
22 * @version $Id: LREM.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LREM extends ArithmeticInstruction implements ExceptionThrower {
26
27 public LREM() {
28 super(org.apache.bcel.Constants.LREM);
29 }
30
31
32 public Class[] getExceptions() {
33 return new Class[] {
34 org.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION
35 };
36 }
37
38
39 /**
40 * Call corresponding visitor method(s). The order is:
41 * Call visitor methods of implemented interfaces first, then
42 * call methods according to the class hierarchy in descending order,
43 * i.e., the most specific visitXXX() call comes last.
44 *
45 * @param v Visitor object
46 */
47 public void accept( Visitor v ) {
48 v.visitExceptionThrower(this);
49 v.visitTypedInstruction(this);
50 v.visitStackProducer(this);
51 v.visitStackConsumer(this);
52 v.visitArithmeticInstruction(this);
53 v.visitLREM(this);
54 }
55 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LRETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LRETURN - Return long from method
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: LRETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LRETURN extends ReturnInstruction {
26
27 public LRETURN() {
28 super(org.apache.bcel.Constants.LRETURN);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitExceptionThrower(this);
42 v.visitTypedInstruction(this);
43 v.visitStackConsumer(this);
44 v.visitReturnInstruction(this);
45 v.visitLRETURN(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LSHL.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LSHL - Arithmetic shift left long
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: LSHL.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LSHL extends ArithmeticInstruction {
26
27 public LSHL() {
28 super(org.apache.bcel.Constants.LSHL);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLSHL(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LSHR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LSHR - Arithmetic shift right long
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2 -&gt; ..., result.word1, result.word2</PRE>
21 *
22 * @version $Id: LSHR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LSHR extends ArithmeticInstruction {
26
27 public LSHR() {
28 super(org.apache.bcel.Constants.LSHR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLSHR(this);
46 }
47 }
+0
-54
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LSTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LSTORE - Store long into local variable
20 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ... </PRE>
21 *
22 * @version $Id: LSTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LSTORE extends StoreInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 */
31 LSTORE() {
32 super(org.apache.bcel.Constants.LSTORE, org.apache.bcel.Constants.LSTORE_0);
33 }
34
35
36 public LSTORE(int n) {
37 super(org.apache.bcel.Constants.LSTORE, org.apache.bcel.Constants.LSTORE_0, n);
38 }
39
40
41 /**
42 * Call corresponding visitor method(s). The order is:
43 * Call visitor methods of implemented interfaces first, then
44 * call methods according to the class hierarchy in descending order,
45 * i.e., the most specific visitXXX() call comes last.
46 *
47 * @param v Visitor object
48 */
49 public void accept( Visitor v ) {
50 super.accept(v);
51 v.visitLSTORE(this);
52 }
53 }
+0
-49
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LSUB.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LSUB - Substract longs
20 * <PRE>Stack: ..., value1.word1, value1.word2, value2.word1, value2.word2 -&gt;</PRE>
21 * ..., result.word1, result.word2
22 *
23 * @version $Id: LSUB.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class LSUB extends ArithmeticInstruction {
27
28 public LSUB() {
29 super(org.apache.bcel.Constants.LSUB);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitTypedInstruction(this);
43 v.visitStackProducer(this);
44 v.visitStackConsumer(this);
45 v.visitArithmeticInstruction(this);
46 v.visitLSUB(this);
47 }
48 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LUSHR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LUSHR - Logical shift right long
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: LUSHR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LUSHR extends ArithmeticInstruction {
26
27 public LUSHR() {
28 super(org.apache.bcel.Constants.LUSHR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLUSHR(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LXOR.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * LXOR - Bitwise XOR long
20 * <PRE>Stack: ..., value1, value2 -&gt; ..., result</PRE>
21 *
22 * @version $Id: LXOR.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class LXOR extends ArithmeticInstruction {
26
27 public LXOR() {
28 super(org.apache.bcel.Constants.LXOR);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitTypedInstruction(this);
42 v.visitStackProducer(this);
43 v.visitStackConsumer(this);
44 v.visitArithmeticInstruction(this);
45 v.visitLXOR(this);
46 }
47 }
+0
-108
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LineNumberGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.classfile.LineNumber;
19
20 /**
21 * This class represents a line number within a method, i.e., give an instruction
22 * a line number corresponding to the source code line.
23 *
24 * @version $Id: LineNumberGen.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 * @see LineNumber
27 * @see MethodGen
28 */
29 public class LineNumberGen implements InstructionTargeter, Cloneable, java.io.Serializable {
30
31 private InstructionHandle ih;
32 private int src_line;
33
34
35 /**
36 * Create a line number.
37 *
38 * @param ih instruction handle to reference
39 */
40 public LineNumberGen(InstructionHandle ih, int src_line) {
41 setInstruction(ih);
42 setSourceLine(src_line);
43 }
44
45
46 /**
47 * @return true, if ih is target of this line number
48 */
49 public boolean containsTarget( InstructionHandle ih ) {
50 return this.ih == ih;
51 }
52
53
54 /**
55 * @param old_ih old target
56 * @param new_ih new target
57 */
58 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
59 if (old_ih != ih) {
60 throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}");
61 } else {
62 setInstruction(new_ih);
63 }
64 }
65
66
67 /**
68 * Get LineNumber attribute .
69 *
70 * This relies on that the instruction list has already been dumped to byte code or
71 * or that the `setPositions' methods has been called for the instruction list.
72 */
73 public LineNumber getLineNumber() {
74 return new LineNumber(ih.getPosition(), src_line);
75 }
76
77
78 public void setInstruction( InstructionHandle ih ) {
79 BranchInstruction.notifyTarget(this.ih, ih, this);
80 this.ih = ih;
81 }
82
83
84 public Object clone() {
85 try {
86 return super.clone();
87 } catch (CloneNotSupportedException e) {
88 System.err.println(e);
89 return null;
90 }
91 }
92
93
94 public InstructionHandle getInstruction() {
95 return ih;
96 }
97
98
99 public void setSourceLine( int src_line ) {
100 this.src_line = src_line;
101 }
102
103
104 public int getSourceLine() {
105 return src_line;
106 }
107 }
+0
-50
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LoadClass.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes that an instruction may start the process of loading and resolving
20 * the referenced class in the Virtual Machine.
21 *
22 * @version $Id: LoadClass.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface LoadClass {
26
27 /**
28 * Returns the ObjectType of the referenced class or interface
29 * that may be loaded and resolved.
30 * @return object type that may be loaded or null if a primitive is
31 * referenced
32 */
33 public ObjectType getLoadClassType( ConstantPoolGen cpg );
34
35
36 /**
37 * Returns the type associated with this instruction.
38 * LoadClass instances are always typed, but this type
39 * does not always refer to the type of the class or interface
40 * that it possibly forces to load. For example, GETFIELD would
41 * return the type of the field and not the type of the class
42 * where the field is defined.
43 * If no class is forced to be loaded, <B>null</B> is returned.
44 * An example for this is an ANEWARRAY instruction that creates
45 * an int[][].
46 * @see #getLoadClassType(ConstantPoolGen)
47 */
48 public Type getType( ConstantPoolGen cpg );
49 }
+0
-63
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LoadInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an unparameterized instruction to load a value from a local
20 * variable, e.g. ILOAD.
21 *
22 * @version $Id: LoadInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public abstract class LoadInstruction extends LocalVariableInstruction implements PushInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 * tag and length are defined in readInstruction and initFromFile, respectively.
31 */
32 LoadInstruction(short canon_tag, short c_tag) {
33 super(canon_tag, c_tag);
34 }
35
36
37 /**
38 * @param opcode Instruction opcode
39 * @param c_tag Instruction number for compact version, ALOAD_0, e.g.
40 * @param n local variable index (unsigned short)
41 */
42 protected LoadInstruction(short opcode, short c_tag, int n) {
43 super(opcode, c_tag, n);
44 }
45
46
47 /**
48 * Call corresponding visitor method(s). The order is:
49 * Call visitor methods of implemented interfaces first, then
50 * call methods according to the class hierarchy in descending order,
51 * i.e., the most specific visitXXX() call comes last.
52 *
53 * @param v Visitor object
54 */
55 public void accept( Visitor v ) {
56 v.visitStackProducer(this);
57 v.visitPushInstruction(this);
58 v.visitTypedInstruction(this);
59 v.visitLocalVariableInstruction(this);
60 v.visitLoadInstruction(this);
61 }
62 }
+0
-208
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LocalVariableGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.classfile.LocalVariable;
20
21 /**
22 * This class represents a local variable within a method. It contains its
23 * scope, name and type. The generated LocalVariable object can be obtained
24 * with getLocalVariable which needs the instruction list and the constant
25 * pool as parameters.
26 *
27 * @version $Id: LocalVariableGen.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see LocalVariable
30 * @see MethodGen
31 */
32 public class LocalVariableGen implements InstructionTargeter, NamedAndTyped, Cloneable,
33 java.io.Serializable {
34
35 private int index;
36 private String name;
37 private Type type;
38 private InstructionHandle start, end;
39
40
41 /**
42 * Generate a local variable that with index `index'. Note that double and long
43 * variables need two indexs. Index indices have to be provided by the user.
44 *
45 * @param index index of local variable
46 * @param name its name
47 * @param type its type
48 * @param start from where the instruction is valid (null means from the start)
49 * @param end until where the instruction is valid (null means to the end)
50 */
51 public LocalVariableGen(int index, String name, Type type, InstructionHandle start,
52 InstructionHandle end) {
53 if ((index < 0) || (index > Constants.MAX_SHORT)) {
54 throw new ClassGenException("Invalid index index: " + index);
55 }
56 this.name = name;
57 this.type = type;
58 this.index = index;
59 setStart(start);
60 setEnd(end);
61 }
62
63
64 /**
65 * Get LocalVariable object.
66 *
67 * This relies on that the instruction list has already been dumped to byte code or
68 * or that the `setPositions' methods has been called for the instruction list.
69 *
70 * Note that for local variables whose scope end at the last
71 * instruction of the method's code, the JVM specification is ambiguous:
72 * both a start_pc+length ending at the last instruction and
73 * start_pc+length ending at first index beyond the end of the code are
74 * valid.
75 *
76 * @param cp constant pool
77 */
78 public LocalVariable getLocalVariable( ConstantPoolGen cp ) {
79 int start_pc = start.getPosition();
80 int length = end.getPosition() - start_pc;
81 if (length > 0) {
82 length += end.getInstruction().getLength();
83 }
84 int name_index = cp.addUtf8(name);
85 int signature_index = cp.addUtf8(type.getSignature());
86 return new LocalVariable(start_pc, length, name_index, signature_index, index, cp
87 .getConstantPool());
88 }
89
90
91 public void setIndex( int index ) {
92 this.index = index;
93 }
94
95
96 public int getIndex() {
97 return index;
98 }
99
100
101 public void setName( String name ) {
102 this.name = name;
103 }
104
105
106 public String getName() {
107 return name;
108 }
109
110
111 public void setType( Type type ) {
112 this.type = type;
113 }
114
115
116 public Type getType() {
117 return type;
118 }
119
120
121 public InstructionHandle getStart() {
122 return start;
123 }
124
125
126 public InstructionHandle getEnd() {
127 return end;
128 }
129
130
131 public void setStart( InstructionHandle start ) {
132 BranchInstruction.notifyTarget(this.start, start, this);
133 this.start = start;
134 }
135
136
137 public void setEnd( InstructionHandle end ) {
138 BranchInstruction.notifyTarget(this.end, end, this);
139 this.end = end;
140 }
141
142
143 /**
144 * @param old_ih old target, either start or end
145 * @param new_ih new target
146 */
147 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
148 boolean targeted = false;
149 if (start == old_ih) {
150 targeted = true;
151 setStart(new_ih);
152 }
153 if (end == old_ih) {
154 targeted = true;
155 setEnd(new_ih);
156 }
157 if (!targeted) {
158 throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + end
159 + "}");
160 }
161 }
162
163
164 /**
165 * @return true, if ih is target of this variable
166 */
167 public boolean containsTarget( InstructionHandle ih ) {
168 return (start == ih) || (end == ih);
169 }
170
171
172 /** @return a hash code value for the object.
173 */
174 public int hashCode() {
175 //If the user changes the name or type, problems with the targeter hashmap will occur
176 int hc = index ^ name.hashCode() ^ type.hashCode();
177 return hc;
178 }
179
180
181 /**
182 * We consider to local variables to be equal, if the use the same index and
183 * are valid in the same range.
184 */
185 public boolean equals( Object o ) {
186 if (!(o instanceof LocalVariableGen)) {
187 return false;
188 }
189 LocalVariableGen l = (LocalVariableGen) o;
190 return (l.index == index) && (l.start == start) && (l.end == end);
191 }
192
193
194 public String toString() {
195 return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")";
196 }
197
198
199 public Object clone() {
200 try {
201 return super.clone();
202 } catch (CloneNotSupportedException e) {
203 System.err.println(e);
204 return null;
205 }
206 }
207 }
+0
-202
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/LocalVariableInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.util.ByteSequence;
22
23 /**
24 * Abstract super class for instructions dealing with local variables.
25 *
26 * @version $Id: LocalVariableInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public abstract class LocalVariableInstruction extends Instruction implements TypedInstruction,
30 IndexedInstruction {
31
32 protected int n = -1; // index of referenced variable
33 private short c_tag = -1; // compact version, such as ILOAD_0
34 private short canon_tag = -1; // canonical tag such as ILOAD
35
36
37 private final boolean wide() {
38 return n > Constants.MAX_BYTE;
39 }
40
41
42 /**
43 * Empty constructor needed for the Class.newInstance() statement in
44 * Instruction.readInstruction(). Not to be used otherwise.
45 * tag and length are defined in readInstruction and initFromFile, respectively.
46 */
47 LocalVariableInstruction(short canon_tag, short c_tag) {
48 super();
49 this.canon_tag = canon_tag;
50 this.c_tag = c_tag;
51 }
52
53
54 /**
55 * Empty constructor needed for the Class.newInstance() statement in
56 * Instruction.readInstruction(). Also used by IINC()!
57 */
58 LocalVariableInstruction() {
59 }
60
61
62 /**
63 * @param opcode Instruction opcode
64 * @param c_tag Instruction number for compact version, ALOAD_0, e.g.
65 * @param n local variable index (unsigned short)
66 */
67 protected LocalVariableInstruction(short opcode, short c_tag, int n) {
68 super(opcode, (short) 2);
69 this.c_tag = c_tag;
70 canon_tag = opcode;
71 setIndex(n);
72 }
73
74
75 /**
76 * Dump instruction as byte code to stream out.
77 * @param out Output stream
78 */
79 public void dump( DataOutputStream out ) throws IOException {
80 if (wide()) {
81 out.writeByte(Constants.WIDE);
82 }
83 out.writeByte(opcode);
84 if (length > 1) { // Otherwise ILOAD_n, instruction, e.g.
85 if (wide()) {
86 out.writeShort(n);
87 } else {
88 out.writeByte(n);
89 }
90 }
91 }
92
93
94 /**
95 * Long output format:
96 *
97 * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
98 * "("&lt;length of instruction&gt;")" "&lt;"&lt; local variable index&gt;"&gt;"
99 *
100 * @param verbose long/short format switch
101 * @return mnemonic for instruction
102 */
103 public String toString( boolean verbose ) {
104 if (((opcode >= Constants.ILOAD_0) && (opcode <= Constants.ALOAD_3))
105 || ((opcode >= Constants.ISTORE_0) && (opcode <= Constants.ASTORE_3))) {
106 return super.toString(verbose);
107 } else {
108 return super.toString(verbose) + " " + n;
109 }
110 }
111
112
113 /**
114 * Read needed data (e.g. index) from file.
115 * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
116 */
117 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
118 if (wide) {
119 n = bytes.readUnsignedShort();
120 length = 4;
121 } else if (((opcode >= Constants.ILOAD) && (opcode <= Constants.ALOAD))
122 || ((opcode >= Constants.ISTORE) && (opcode <= Constants.ASTORE))) {
123 n = bytes.readUnsignedByte();
124 length = 2;
125 } else if (opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
126 n = (opcode - Constants.ILOAD_0) % 4;
127 length = 1;
128 } else { // Assert ISTORE_0 <= tag <= ASTORE_3
129 n = (opcode - Constants.ISTORE_0) % 4;
130 length = 1;
131 }
132 }
133
134
135 /**
136 * @return local variable index referred by this instruction.
137 */
138 public final int getIndex() {
139 return n;
140 }
141
142
143 /**
144 * Set the local variable index
145 */
146 public void setIndex( int n ) {
147 if ((n < 0) || (n > Constants.MAX_SHORT)) {
148 throw new ClassGenException("Illegal value: " + n);
149 }
150 this.n = n;
151 if (n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n
152 opcode = (short) (c_tag + n);
153 length = 1;
154 } else {
155 opcode = canon_tag;
156 if (wide()) {
157 length = 4;
158 } else {
159 length = 2;
160 }
161 }
162 }
163
164
165 /** @return canonical tag for instruction, e.g., ALOAD for ALOAD_0
166 */
167 public short getCanonicalTag() {
168 return canon_tag;
169 }
170
171
172 /**
173 * Returns the type associated with the instruction -
174 * in case of ALOAD or ASTORE Type.OBJECT is returned.
175 * This is just a bit incorrect, because ALOAD and ASTORE
176 * may work on every ReferenceType (including Type.NULL) and
177 * ASTORE may even work on a ReturnaddressType .
178 * @return type associated with the instruction
179 */
180 public Type getType( ConstantPoolGen cp ) {
181 switch (canon_tag) {
182 case Constants.ILOAD:
183 case Constants.ISTORE:
184 return Type.INT;
185 case Constants.LLOAD:
186 case Constants.LSTORE:
187 return Type.LONG;
188 case Constants.DLOAD:
189 case Constants.DSTORE:
190 return Type.DOUBLE;
191 case Constants.FLOAD:
192 case Constants.FSTORE:
193 return Type.FLOAT;
194 case Constants.ALOAD:
195 case Constants.ASTORE:
196 return Type.OBJECT;
197 default:
198 throw new ClassGenException("Oops: unknown case in switch" + canon_tag);
199 }
200 }
201 }
+0
-53
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/MONITORENTER.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * MONITORENTER - Enter monitor for object
20 * <PRE>Stack: ..., objectref -&gt; ...</PRE>
21 *
22 * @version $Id: MONITORENTER.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class MONITORENTER extends Instruction implements ExceptionThrower, StackConsumer {
26
27 public MONITORENTER() {
28 super(org.apache.bcel.Constants.MONITORENTER, (short) 1);
29 }
30
31
32 public Class[] getExceptions() {
33 return new Class[] {
34 org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION
35 };
36 }
37
38
39 /**
40 * Call corresponding visitor method(s). The order is:
41 * Call visitor methods of implemented interfaces first, then
42 * call methods according to the class hierarchy in descending order,
43 * i.e., the most specific visitXXX() call comes last.
44 *
45 * @param v Visitor object
46 */
47 public void accept( Visitor v ) {
48 v.visitExceptionThrower(this);
49 v.visitStackConsumer(this);
50 v.visitMONITORENTER(this);
51 }
52 }
+0
-53
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/MONITOREXIT.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * MONITOREXIT - Exit monitor for object
20 * <PRE>Stack: ..., objectref -&gt; ...</PRE>
21 *
22 * @version $Id: MONITOREXIT.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class MONITOREXIT extends Instruction implements ExceptionThrower, StackConsumer {
26
27 public MONITOREXIT() {
28 super(org.apache.bcel.Constants.MONITOREXIT, (short) 1);
29 }
30
31
32 public Class[] getExceptions() {
33 return new Class[] {
34 org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION
35 };
36 }
37
38
39 /**
40 * Call corresponding visitor method(s). The order is:
41 * Call visitor methods of implemented interfaces first, then
42 * call methods according to the class hierarchy in descending order,
43 * i.e., the most specific visitXXX() call comes last.
44 *
45 * @param v Visitor object
46 */
47 public void accept( Visitor v ) {
48 v.visitExceptionThrower(this);
49 v.visitStackConsumer(this);
50 v.visitMONITOREXIT(this);
51 }
52 }
+0
-146
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/MULTIANEWARRAY.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.ExceptionConstants;
21 import org.apache.bcel.classfile.ConstantPool;
22 import org.apache.bcel.util.ByteSequence;
23
24 /**
25 * MULTIANEWARRAY - Create new mutidimensional array of references
26 * <PRE>Stack: ..., count1, [count2, ...] -&gt; ..., arrayref</PRE>
27 *
28 * @version $Id: MULTIANEWARRAY.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction,
32 ExceptionThrower {
33
34 private short dimensions;
35
36
37 /**
38 * Empty constructor needed for the Class.newInstance() statement in
39 * Instruction.readInstruction(). Not to be used otherwise.
40 */
41 MULTIANEWARRAY() {
42 }
43
44
45 public MULTIANEWARRAY(int index, short dimensions) {
46 super(org.apache.bcel.Constants.MULTIANEWARRAY, index);
47 if (dimensions < 1) {
48 throw new ClassGenException("Invalid dimensions value: " + dimensions);
49 }
50 this.dimensions = dimensions;
51 length = 4;
52 }
53
54
55 /**
56 * Dump instruction as byte code to stream out.
57 * @param out Output stream
58 */
59 public void dump( DataOutputStream out ) throws IOException {
60 out.writeByte(opcode);
61 out.writeShort(index);
62 out.writeByte(dimensions);
63 }
64
65
66 /**
67 * Read needed data (i.e., no. dimension) from file.
68 */
69 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
70 super.initFromFile(bytes, wide);
71 dimensions = bytes.readByte();
72 length = 4;
73 }
74
75
76 /**
77 * @return number of dimensions to be created
78 */
79 public final short getDimensions() {
80 return dimensions;
81 }
82
83
84 /**
85 * @return mnemonic for instruction
86 */
87 public String toString( boolean verbose ) {
88 return super.toString(verbose) + " " + index + " " + dimensions;
89 }
90
91
92 /**
93 * @return mnemonic for instruction with symbolic references resolved
94 */
95 public String toString( ConstantPool cp ) {
96 return super.toString(cp) + " " + dimensions;
97 }
98
99
100 /**
101 * Also works for instructions whose stack effect depends on the
102 * constant pool entry they reference.
103 * @return Number of words consumed from stack by this instruction
104 */
105 public int consumeStack( ConstantPoolGen cpg ) {
106 return dimensions;
107 }
108
109
110 public Class[] getExceptions() {
111 Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
112 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, cs, 0,
113 ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
114 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length + 1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
115 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
116 return cs;
117 }
118
119
120 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
121 Type t = getType(cpg);
122 if (t instanceof ArrayType) {
123 t = ((ArrayType) t).getBasicType();
124 }
125 return (t instanceof ObjectType) ? (ObjectType) t : null;
126 }
127
128
129 /**
130 * Call corresponding visitor method(s). The order is:
131 * Call visitor methods of implemented interfaces first, then
132 * call methods according to the class hierarchy in descending order,
133 * i.e., the most specific visitXXX() call comes last.
134 *
135 * @param v Visitor object
136 */
137 public void accept( Visitor v ) {
138 v.visitLoadClass(this);
139 v.visitAllocationInstruction(this);
140 v.visitExceptionThrower(this);
141 v.visitTypedInstruction(this);
142 v.visitCPInstruction(this);
143 v.visitMULTIANEWARRAY(this);
144 }
145 }
+0
-1086
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/MethodGen.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.ArrayList;
19 import java.util.Hashtable;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Stack;
23 import org.apache.bcel.Constants;
24 import org.apache.bcel.classfile.Attribute;
25 import org.apache.bcel.classfile.Code;
26 import org.apache.bcel.classfile.CodeException;
27 import org.apache.bcel.classfile.ExceptionTable;
28 import org.apache.bcel.classfile.LineNumber;
29 import org.apache.bcel.classfile.LineNumberTable;
30 import org.apache.bcel.classfile.LocalVariable;
31 import org.apache.bcel.classfile.LocalVariableTable;
32 import org.apache.bcel.classfile.Method;
33 import org.apache.bcel.classfile.Utility;
34 import org.apache.bcel.util.BCELComparator;
35
36 /**
37 * Template class for building up a method. This is done by defining exception
38 * handlers, adding thrown exceptions, local variables and attributes, whereas
39 * the `LocalVariableTable' and `LineNumberTable' attributes will be set
40 * automatically for the code. Use stripAttributes() if you don't like this.
41 *
42 * While generating code it may be necessary to insert NOP operations. You can
43 * use the `removeNOPs' method to get rid off them.
44 * The resulting method object can be obtained via the `getMethod()' method.
45 *
46 * @version $Id: MethodGen.java 386056 2006-03-15 11:31:56Z tcurdt $
47 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
48 * @author <A HREF="http://www.vmeng.com/beard">Patrick C. Beard</A> [setMaxStack()]
49 * @see InstructionList
50 * @see Method
51 */
52 public class MethodGen extends FieldGenOrMethodGen {
53
54 private String class_name;
55 private Type[] arg_types;
56 private String[] arg_names;
57 private int max_locals;
58 private int max_stack;
59 private InstructionList il;
60 private boolean strip_attributes;
61 private List variable_vec = new ArrayList();
62 private List line_number_vec = new ArrayList();
63 private List exception_vec = new ArrayList();
64 private List throws_vec = new ArrayList();
65 private List code_attrs_vec = new ArrayList();
66 private static BCELComparator _cmp = new BCELComparator() {
67
68 public boolean equals( Object o1, Object o2 ) {
69 MethodGen THIS = (MethodGen) o1;
70 MethodGen THAT = (MethodGen) o2;
71 return THIS.getName().equals(THAT.getName())
72 && THIS.getSignature().equals(THAT.getSignature());
73 }
74
75
76 public int hashCode( Object o ) {
77 MethodGen THIS = (MethodGen) o;
78 return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
79 }
80 };
81
82
83 /**
84 * Declare method. If the method is non-static the constructor
85 * automatically declares a local variable `$this' in slot 0. The
86 * actual code is contained in the `il' parameter, which may further
87 * manipulated by the user. But he must take care not to remove any
88 * instruction (handles) that are still referenced from this object.
89 *
90 * For example one may not add a local variable and later remove the
91 * instructions it refers to without causing havoc. It is safe
92 * however if you remove that local variable, too.
93 *
94 * @param access_flags access qualifiers
95 * @param return_type method type
96 * @param arg_types argument types
97 * @param arg_names argument names (if this is null, default names will be provided
98 * for them)
99 * @param method_name name of method
100 * @param class_name class name containing this method (may be null, if you don't care)
101 * @param il instruction list associated with this method, may be null only for
102 * abstract or native methods
103 * @param cp constant pool
104 */
105 public MethodGen(int access_flags, Type return_type, Type[] arg_types, String[] arg_names,
106 String method_name, String class_name, InstructionList il, ConstantPoolGen cp) {
107 setAccessFlags(access_flags);
108 setType(return_type);
109 setArgumentTypes(arg_types);
110 setArgumentNames(arg_names);
111 setName(method_name);
112 setClassName(class_name);
113 setInstructionList(il);
114 setConstantPool(cp);
115 boolean abstract_ = isAbstract() || isNative();
116 InstructionHandle start = null;
117 InstructionHandle end = null;
118 if (!abstract_) {
119 start = il.getStart();
120 end = il.getEnd();
121 /* Add local variables, namely the implicit `this' and the arguments
122 */
123 if (!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0
124 addLocalVariable("this", ObjectType.getInstance(class_name), start, end);
125 }
126 }
127 if (arg_types != null) {
128 int size = arg_types.length;
129 for (int i = 0; i < size; i++) {
130 if (Type.VOID == arg_types[i]) {
131 throw new ClassGenException("'void' is an illegal argument type for a method");
132 }
133 }
134 if (arg_names != null) { // Names for variables provided?
135 if (size != arg_names.length) {
136 throw new ClassGenException("Mismatch in argument array lengths: " + size
137 + " vs. " + arg_names.length);
138 }
139 } else { // Give them dummy names
140 arg_names = new String[size];
141 for (int i = 0; i < size; i++) {
142 arg_names[i] = "arg" + i;
143 }
144 setArgumentNames(arg_names);
145 }
146 if (!abstract_) {
147 for (int i = 0; i < size; i++) {
148 addLocalVariable(arg_names[i], arg_types[i], start, end);
149 }
150 }
151 }
152 }
153
154
155 /**
156 * Instantiate from existing method.
157 *
158 * @param m method
159 * @param class_name class name containing this method
160 * @param cp constant pool
161 */
162 public MethodGen(Method m, String class_name, ConstantPoolGen cp) {
163 this(m.getAccessFlags(), Type.getReturnType(m.getSignature()), Type.getArgumentTypes(m
164 .getSignature()), null /* may be overridden anyway */
165 , m.getName(), class_name,
166 ((m.getAccessFlags() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0)
167 ? new InstructionList(m.getCode().getCode())
168 : null, cp);
169 Attribute[] attributes = m.getAttributes();
170 for (int i = 0; i < attributes.length; i++) {
171 Attribute a = attributes[i];
172 if (a instanceof Code) {
173 Code c = (Code) a;
174 setMaxStack(c.getMaxStack());
175 setMaxLocals(c.getMaxLocals());
176 CodeException[] ces = c.getExceptionTable();
177 if (ces != null) {
178 for (int j = 0; j < ces.length; j++) {
179 CodeException ce = ces[j];
180 int type = ce.getCatchType();
181 ObjectType c_type = null;
182 if (type > 0) {
183 String cen = m.getConstantPool().getConstantString(type,
184 Constants.CONSTANT_Class);
185 c_type = ObjectType.getInstance(cen);
186 }
187 int end_pc = ce.getEndPC();
188 int length = m.getCode().getCode().length;
189 InstructionHandle end;
190 if (length == end_pc) { // May happen, because end_pc is exclusive
191 end = il.getEnd();
192 } else {
193 end = il.findHandle(end_pc);
194 end = end.getPrev(); // Make it inclusive
195 }
196 addExceptionHandler(il.findHandle(ce.getStartPC()), end, il.findHandle(ce
197 .getHandlerPC()), c_type);
198 }
199 }
200 Attribute[] c_attributes = c.getAttributes();
201 for (int j = 0; j < c_attributes.length; j++) {
202 a = c_attributes[j];
203 if (a instanceof LineNumberTable) {
204 LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
205 for (int k = 0; k < ln.length; k++) {
206 LineNumber l = ln[k];
207 InstructionHandle ih = il.findHandle(l.getStartPC());
208 if (ih != null) {
209 addLineNumber(ih, l.getLineNumber());
210 }
211 }
212 } else if (a instanceof LocalVariableTable) {
213 LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable();
214 removeLocalVariables();
215 for (int k = 0; k < lv.length; k++) {
216 LocalVariable l = lv[k];
217 InstructionHandle start = il.findHandle(l.getStartPC());
218 InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength());
219 // Repair malformed handles
220 if (null == start) {
221 start = il.getStart();
222 }
223 if (null == end) {
224 end = il.getEnd();
225 }
226 addLocalVariable(l.getName(), Type.getType(l.getSignature()), l
227 .getIndex(), start, end);
228 }
229 } else {
230 addCodeAttribute(a);
231 }
232 }
233 } else if (a instanceof ExceptionTable) {
234 String[] names = ((ExceptionTable) a).getExceptionNames();
235 for (int j = 0; j < names.length; j++) {
236 addException(names[j]);
237 }
238 } else {
239 addAttribute(a);
240 }
241 }
242 }
243
244
245 /**
246 * Adds a local variable to this method.
247 *
248 * @param name variable name
249 * @param type variable type
250 * @param slot the index of the local variable, if type is long or double, the next available
251 * index is slot+2
252 * @param start from where the variable is valid
253 * @param end until where the variable is valid
254 * @return new local variable object
255 * @see LocalVariable
256 */
257 public LocalVariableGen addLocalVariable( String name, Type type, int slot,
258 InstructionHandle start, InstructionHandle end ) {
259 byte t = type.getType();
260 if (t != Constants.T_ADDRESS) {
261 int add = type.getSize();
262 if (slot + add > max_locals) {
263 max_locals = slot + add;
264 }
265 LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end);
266 int i;
267 if ((i = variable_vec.indexOf(l)) >= 0) {
268 variable_vec.set(i, l);
269 } else {
270 variable_vec.add(l);
271 }
272 return l;
273 } else {
274 throw new IllegalArgumentException("Can not use " + type
275 + " as type for local variable");
276 }
277 }
278
279
280 /**
281 * Adds a local variable to this method and assigns an index automatically.
282 *
283 * @param name variable name
284 * @param type variable type
285 * @param start from where the variable is valid, if this is null,
286 * it is valid from the start
287 * @param end until where the variable is valid, if this is null,
288 * it is valid to the end
289 * @return new local variable object
290 * @see LocalVariable
291 */
292 public LocalVariableGen addLocalVariable( String name, Type type, InstructionHandle start,
293 InstructionHandle end ) {
294 return addLocalVariable(name, type, max_locals, start, end);
295 }
296
297
298 /**
299 * Remove a local variable, its slot will not be reused, if you do not use addLocalVariable
300 * with an explicit index argument.
301 */
302 public void removeLocalVariable( LocalVariableGen l ) {
303 variable_vec.remove(l);
304 }
305
306
307 /**
308 * Remove all local variables.
309 */
310 public void removeLocalVariables() {
311 variable_vec.clear();
312 }
313
314
315 /**
316 * Sort local variables by index
317 */
318 private static final void sort( LocalVariableGen[] vars, int l, int r ) {
319 int i = l, j = r;
320 int m = vars[(l + r) / 2].getIndex();
321 LocalVariableGen h;
322 do {
323 while (vars[i].getIndex() < m) {
324 i++;
325 }
326 while (m < vars[j].getIndex()) {
327 j--;
328 }
329 if (i <= j) {
330 h = vars[i];
331 vars[i] = vars[j];
332 vars[j] = h; // Swap elements
333 i++;
334 j--;
335 }
336 } while (i <= j);
337 if (l < j) {
338 sort(vars, l, j);
339 }
340 if (i < r) {
341 sort(vars, i, r);
342 }
343 }
344
345
346 /*
347 * If the range of the variable has not been set yet, it will be set to be valid from
348 * the start to the end of the instruction list.
349 *
350 * @return array of declared local variables sorted by index
351 */
352 public LocalVariableGen[] getLocalVariables() {
353 int size = variable_vec.size();
354 LocalVariableGen[] lg = new LocalVariableGen[size];
355 variable_vec.toArray(lg);
356 for (int i = 0; i < size; i++) {
357 if (lg[i].getStart() == null) {
358 lg[i].setStart(il.getStart());
359 }
360 if (lg[i].getEnd() == null) {
361 lg[i].setEnd(il.getEnd());
362 }
363 }
364 if (size > 1) {
365 sort(lg, 0, size - 1);
366 }
367 return lg;
368 }
369
370
371 /**
372 * @return `LocalVariableTable' attribute of all the local variables of this method.
373 */
374 public LocalVariableTable getLocalVariableTable( ConstantPoolGen cp ) {
375 LocalVariableGen[] lg = getLocalVariables();
376 int size = lg.length;
377 LocalVariable[] lv = new LocalVariable[size];
378 for (int i = 0; i < size; i++) {
379 lv[i] = lg[i].getLocalVariable(cp);
380 }
381 return new LocalVariableTable(cp.addUtf8("LocalVariableTable"), 2 + lv.length * 10, lv, cp
382 .getConstantPool());
383 }
384
385
386 /**
387 * Give an instruction a line number corresponding to the source code line.
388 *
389 * @param ih instruction to tag
390 * @return new line number object
391 * @see LineNumber
392 */
393 public LineNumberGen addLineNumber( InstructionHandle ih, int src_line ) {
394 LineNumberGen l = new LineNumberGen(ih, src_line);
395 line_number_vec.add(l);
396 return l;
397 }
398
399
400 /**
401 * Remove a line number.
402 */
403 public void removeLineNumber( LineNumberGen l ) {
404 line_number_vec.remove(l);
405 }
406
407
408 /**
409 * Remove all line numbers.
410 */
411 public void removeLineNumbers() {
412 line_number_vec.clear();
413 }
414
415
416 /*
417 * @return array of line numbers
418 */
419 public LineNumberGen[] getLineNumbers() {
420 LineNumberGen[] lg = new LineNumberGen[line_number_vec.size()];
421 line_number_vec.toArray(lg);
422 return lg;
423 }
424
425
426 /**
427 * @return `LineNumberTable' attribute of all the local variables of this method.
428 */
429 public LineNumberTable getLineNumberTable( ConstantPoolGen cp ) {
430 int size = line_number_vec.size();
431 LineNumber[] ln = new LineNumber[size];
432 try {
433 for (int i = 0; i < size; i++) {
434 ln[i] = ((LineNumberGen) line_number_vec.get(i)).getLineNumber();
435 }
436 } catch (ArrayIndexOutOfBoundsException e) {
437 } // Never occurs
438 return new LineNumberTable(cp.addUtf8("LineNumberTable"), 2 + ln.length * 4, ln, cp
439 .getConstantPool());
440 }
441
442
443 /**
444 * Add an exception handler, i.e., specify region where a handler is active and an
445 * instruction where the actual handling is done.
446 *
447 * @param start_pc Start of region (inclusive)
448 * @param end_pc End of region (inclusive)
449 * @param handler_pc Where handling is done
450 * @param catch_type class type of handled exception or null if any
451 * exception is handled
452 * @return new exception handler object
453 */
454 public CodeExceptionGen addExceptionHandler( InstructionHandle start_pc,
455 InstructionHandle end_pc, InstructionHandle handler_pc, ObjectType catch_type ) {
456 if ((start_pc == null) || (end_pc == null) || (handler_pc == null)) {
457 throw new ClassGenException("Exception handler target is null instruction");
458 }
459 CodeExceptionGen c = new CodeExceptionGen(start_pc, end_pc, handler_pc, catch_type);
460 exception_vec.add(c);
461 return c;
462 }
463
464
465 /**
466 * Remove an exception handler.
467 */
468 public void removeExceptionHandler( CodeExceptionGen c ) {
469 exception_vec.remove(c);
470 }
471
472
473 /**
474 * Remove all line numbers.
475 */
476 public void removeExceptionHandlers() {
477 exception_vec.clear();
478 }
479
480
481 /*
482 * @return array of declared exception handlers
483 */
484 public CodeExceptionGen[] getExceptionHandlers() {
485 CodeExceptionGen[] cg = new CodeExceptionGen[exception_vec.size()];
486 exception_vec.toArray(cg);
487 return cg;
488 }
489
490
491 /**
492 * @return code exceptions for `Code' attribute
493 */
494 private CodeException[] getCodeExceptions() {
495 int size = exception_vec.size();
496 CodeException[] c_exc = new CodeException[size];
497 try {
498 for (int i = 0; i < size; i++) {
499 CodeExceptionGen c = (CodeExceptionGen) exception_vec.get(i);
500 c_exc[i] = c.getCodeException(cp);
501 }
502 } catch (ArrayIndexOutOfBoundsException e) {
503 }
504 return c_exc;
505 }
506
507
508 /**
509 * Add an exception possibly thrown by this method.
510 *
511 * @param class_name (fully qualified) name of exception
512 */
513 public void addException( String class_name ) {
514 throws_vec.add(class_name);
515 }
516
517
518 /**
519 * Remove an exception.
520 */
521 public void removeException( String c ) {
522 throws_vec.remove(c);
523 }
524
525
526 /**
527 * Remove all exceptions.
528 */
529 public void removeExceptions() {
530 throws_vec.clear();
531 }
532
533
534 /*
535 * @return array of thrown exceptions
536 */
537 public String[] getExceptions() {
538 String[] e = new String[throws_vec.size()];
539 throws_vec.toArray(e);
540 return e;
541 }
542
543
544 /**
545 * @return `Exceptions' attribute of all the exceptions thrown by this method.
546 */
547 private ExceptionTable getExceptionTable( ConstantPoolGen cp ) {
548 int size = throws_vec.size();
549 int[] ex = new int[size];
550 try {
551 for (int i = 0; i < size; i++) {
552 ex[i] = cp.addClass((String) throws_vec.get(i));
553 }
554 } catch (ArrayIndexOutOfBoundsException e) {
555 }
556 return new ExceptionTable(cp.addUtf8("Exceptions"), 2 + 2 * size, ex, cp.getConstantPool());
557 }
558
559
560 /**
561 * Add an attribute to the code. Currently, the JVM knows about the
562 * LineNumberTable, LocalVariableTable and StackMap attributes,
563 * where the former two will be generated automatically and the
564 * latter is used for the MIDP only. Other attributes will be
565 * ignored by the JVM but do no harm.
566 *
567 * @param a attribute to be added
568 */
569 public void addCodeAttribute( Attribute a ) {
570 code_attrs_vec.add(a);
571 }
572
573
574 /**
575 * Remove a code attribute.
576 */
577 public void removeCodeAttribute( Attribute a ) {
578 code_attrs_vec.remove(a);
579 }
580
581
582 /**
583 * Remove all code attributes.
584 */
585 public void removeCodeAttributes() {
586 code_attrs_vec.clear();
587 }
588
589
590 /**
591 * @return all attributes of this method.
592 */
593 public Attribute[] getCodeAttributes() {
594 Attribute[] attributes = new Attribute[code_attrs_vec.size()];
595 code_attrs_vec.toArray(attributes);
596 return attributes;
597 }
598
599
600 /**
601 * Get method object. Never forget to call setMaxStack() or setMaxStack(max), respectively,
602 * before calling this method (the same applies for max locals).
603 *
604 * @return method object
605 */
606 public Method getMethod() {
607 String signature = getSignature();
608 int name_index = cp.addUtf8(name);
609 int signature_index = cp.addUtf8(signature);
610 /* Also updates positions of instructions, i.e., their indices
611 */
612 byte[] byte_code = null;
613 if (il != null) {
614 byte_code = il.getByteCode();
615 }
616 LineNumberTable lnt = null;
617 LocalVariableTable lvt = null;
618 /* Create LocalVariableTable and LineNumberTable attributes (for debuggers, e.g.)
619 */
620 if ((variable_vec.size() > 0) && !strip_attributes) {
621 addCodeAttribute(lvt = getLocalVariableTable(cp));
622 }
623 if ((line_number_vec.size() > 0) && !strip_attributes) {
624 addCodeAttribute(lnt = getLineNumberTable(cp));
625 }
626 Attribute[] code_attrs = getCodeAttributes();
627 /* Each attribute causes 6 additional header bytes
628 */
629 int attrs_len = 0;
630 for (int i = 0; i < code_attrs.length; i++) {
631 attrs_len += (code_attrs[i].getLength() + 6);
632 }
633 CodeException[] c_exc = getCodeExceptions();
634 int exc_len = c_exc.length * 8; // Every entry takes 8 bytes
635 Code code = null;
636 if ((il != null) && !isAbstract() && !isNative()) {
637 // Remove any stale code attribute
638 Attribute[] attributes = getAttributes();
639 for (int i = 0; i < attributes.length; i++) {
640 Attribute a = attributes[i];
641 if (a instanceof Code) {
642 removeAttribute(a);
643 }
644 }
645 code = new Code(cp.addUtf8("Code"), 8 + byte_code.length + // prologue byte code
646 2 + exc_len + // exceptions
647 2 + attrs_len, // attributes
648 max_stack, max_locals, byte_code, c_exc, code_attrs, cp.getConstantPool());
649 addAttribute(code);
650 }
651 ExceptionTable et = null;
652 if (throws_vec.size() > 0) {
653 addAttribute(et = getExceptionTable(cp));
654 // Add `Exceptions' if there are "throws" clauses
655 }
656 Method m = new Method(access_flags, name_index, signature_index, getAttributes(), cp
657 .getConstantPool());
658 // Undo effects of adding attributes
659 if (lvt != null) {
660 removeCodeAttribute(lvt);
661 }
662 if (lnt != null) {
663 removeCodeAttribute(lnt);
664 }
665 if (code != null) {
666 removeAttribute(code);
667 }
668 if (et != null) {
669 removeAttribute(et);
670 }
671 return m;
672 }
673
674
675 /**
676 * Remove all NOPs from the instruction list (if possible) and update every
677 * object refering to them, i.e., branch instructions, local variables and
678 * exception handlers.
679 */
680 public void removeNOPs() {
681 if (il != null) {
682 InstructionHandle next;
683 /* Check branch instructions.
684 */
685 for (InstructionHandle ih = il.getStart(); ih != null; ih = next) {
686 next = ih.next;
687 if ((next != null) && (ih.getInstruction() instanceof NOP)) {
688 try {
689 il.delete(ih);
690 } catch (TargetLostException e) {
691 InstructionHandle[] targets = e.getTargets();
692 for (int i = 0; i < targets.length; i++) {
693 InstructionTargeter[] targeters = targets[i].getTargeters();
694 for (int j = 0; j < targeters.length; j++) {
695 targeters[j].updateTarget(targets[i], next);
696 }
697 }
698 }
699 }
700 }
701 }
702 }
703
704
705 /**
706 * Set maximum number of local variables.
707 */
708 public void setMaxLocals( int m ) {
709 max_locals = m;
710 }
711
712
713 public int getMaxLocals() {
714 return max_locals;
715 }
716
717
718 /**
719 * Set maximum stack size for this method.
720 */
721 public void setMaxStack( int m ) {
722 max_stack = m;
723 }
724
725
726 public int getMaxStack() {
727 return max_stack;
728 }
729
730
731 /** @return class that contains this method
732 */
733 public String getClassName() {
734 return class_name;
735 }
736
737
738 public void setClassName( String class_name ) {
739 this.class_name = class_name;
740 }
741
742
743 public void setReturnType( Type return_type ) {
744 setType(return_type);
745 }
746
747
748 public Type getReturnType() {
749 return getType();
750 }
751
752
753 public void setArgumentTypes( Type[] arg_types ) {
754 this.arg_types = arg_types;
755 }
756
757
758 public Type[] getArgumentTypes() {
759 return (Type[]) arg_types.clone();
760 }
761
762
763 public void setArgumentType( int i, Type type ) {
764 arg_types[i] = type;
765 }
766
767
768 public Type getArgumentType( int i ) {
769 return arg_types[i];
770 }
771
772
773 public void setArgumentNames( String[] arg_names ) {
774 this.arg_names = arg_names;
775 }
776
777
778 public String[] getArgumentNames() {
779 return (String[]) arg_names.clone();
780 }
781
782
783 public void setArgumentName( int i, String name ) {
784 arg_names[i] = name;
785 }
786
787
788 public String getArgumentName( int i ) {
789 return arg_names[i];
790 }
791
792
793 public InstructionList getInstructionList() {
794 return il;
795 }
796
797
798 public void setInstructionList( InstructionList il ) {
799 this.il = il;
800 }
801
802
803 public String getSignature() {
804 return Type.getMethodSignature(type, arg_types);
805 }
806
807
808 /**
809 * Computes max. stack size by performing control flow analysis.
810 */
811 public void setMaxStack() {
812 if (il != null) {
813 max_stack = getMaxStack(cp, il, getExceptionHandlers());
814 } else {
815 max_stack = 0;
816 }
817 }
818
819
820 /**
821 * Compute maximum number of local variables.
822 */
823 public void setMaxLocals() {
824 if (il != null) {
825 int max = isStatic() ? 0 : 1;
826 if (arg_types != null) {
827 for (int i = 0; i < arg_types.length; i++) {
828 max += arg_types[i].getSize();
829 }
830 }
831 for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
832 Instruction ins = ih.getInstruction();
833 if ((ins instanceof LocalVariableInstruction) || (ins instanceof RET)
834 || (ins instanceof IINC)) {
835 int index = ((IndexedInstruction) ins).getIndex()
836 + ((TypedInstruction) ins).getType(cp).getSize();
837 if (index > max) {
838 max = index;
839 }
840 }
841 }
842 max_locals = max;
843 } else {
844 max_locals = 0;
845 }
846 }
847
848
849 /** Do not/Do produce attributes code attributesLineNumberTable and
850 * LocalVariableTable, like javac -O
851 */
852 public void stripAttributes( boolean flag ) {
853 strip_attributes = flag;
854 }
855
856 static final class BranchTarget {
857
858 InstructionHandle target;
859 int stackDepth;
860
861
862 BranchTarget(InstructionHandle target, int stackDepth) {
863 this.target = target;
864 this.stackDepth = stackDepth;
865 }
866 }
867
868 static final class BranchStack {
869
870 Stack branchTargets = new Stack();
871 Hashtable visitedTargets = new Hashtable();
872
873
874 public void push( InstructionHandle target, int stackDepth ) {
875 if (visited(target)) {
876 return;
877 }
878 branchTargets.push(visit(target, stackDepth));
879 }
880
881
882 public BranchTarget pop() {
883 if (!branchTargets.empty()) {
884 BranchTarget bt = (BranchTarget) branchTargets.pop();
885 return bt;
886 }
887 return null;
888 }
889
890
891 private final BranchTarget visit( InstructionHandle target, int stackDepth ) {
892 BranchTarget bt = new BranchTarget(target, stackDepth);
893 visitedTargets.put(target, bt);
894 return bt;
895 }
896
897
898 private final boolean visited( InstructionHandle target ) {
899 return (visitedTargets.get(target) != null);
900 }
901 }
902
903
904 /**
905 * Computes stack usage of an instruction list by performing control flow analysis.
906 *
907 * @return maximum stack depth used by method
908 */
909 public static int getMaxStack( ConstantPoolGen cp, InstructionList il, CodeExceptionGen[] et ) {
910 BranchStack branchTargets = new BranchStack();
911 /* Initially, populate the branch stack with the exception
912 * handlers, because these aren't (necessarily) branched to
913 * explicitly. in each case, the stack will have depth 1,
914 * containing the exception object.
915 */
916 for (int i = 0; i < et.length; i++) {
917 InstructionHandle handler_pc = et[i].getHandlerPC();
918 if (handler_pc != null) {
919 branchTargets.push(handler_pc, 1);
920 }
921 }
922 int stackDepth = 0, maxStackDepth = 0;
923 InstructionHandle ih = il.getStart();
924 while (ih != null) {
925 Instruction instruction = ih.getInstruction();
926 short opcode = instruction.getOpcode();
927 int delta = instruction.produceStack(cp) - instruction.consumeStack(cp);
928 stackDepth += delta;
929 if (stackDepth > maxStackDepth) {
930 maxStackDepth = stackDepth;
931 }
932 // choose the next instruction based on whether current is a branch.
933 if (instruction instanceof BranchInstruction) {
934 BranchInstruction branch = (BranchInstruction) instruction;
935 if (instruction instanceof Select) {
936 // explore all of the select's targets. the default target is handled below.
937 Select select = (Select) branch;
938 InstructionHandle[] targets = select.getTargets();
939 for (int i = 0; i < targets.length; i++) {
940 branchTargets.push(targets[i], stackDepth);
941 }
942 // nothing to fall through to.
943 ih = null;
944 } else if (!(branch instanceof IfInstruction)) {
945 // if an instruction that comes back to following PC,
946 // push next instruction, with stack depth reduced by 1.
947 if (opcode == Constants.JSR || opcode == Constants.JSR_W) {
948 branchTargets.push(ih.getNext(), stackDepth - 1);
949 }
950 ih = null;
951 }
952 // for all branches, the target of the branch is pushed on the branch stack.
953 // conditional branches have a fall through case, selects don't, and
954 // jsr/jsr_w return to the next instruction.
955 branchTargets.push(branch.getTarget(), stackDepth);
956 } else {
957 // check for instructions that terminate the method.
958 if (opcode == Constants.ATHROW || opcode == Constants.RET
959 || (opcode >= Constants.IRETURN && opcode <= Constants.RETURN)) {
960 ih = null;
961 }
962 }
963 // normal case, go to the next instruction.
964 if (ih != null) {
965 ih = ih.getNext();
966 }
967 // if we have no more instructions, see if there are any deferred branches to explore.
968 if (ih == null) {
969 BranchTarget bt = branchTargets.pop();
970 if (bt != null) {
971 ih = bt.target;
972 stackDepth = bt.stackDepth;
973 }
974 }
975 }
976 return maxStackDepth;
977 }
978
979 private List observers;
980
981
982 /** Add observer for this object.
983 */
984 public void addObserver( MethodObserver o ) {
985 if (observers == null) {
986 observers = new ArrayList();
987 }
988 observers.add(o);
989 }
990
991
992 /** Remove observer for this object.
993 */
994 public void removeObserver( MethodObserver o ) {
995 if (observers != null) {
996 observers.remove(o);
997 }
998 }
999
1000
1001 /** Call notify() method on all observers. This method is not called
1002 * automatically whenever the state has changed, but has to be
1003 * called by the user after he has finished editing the object.
1004 */
1005 public void update() {
1006 if (observers != null) {
1007 for (Iterator e = observers.iterator(); e.hasNext();) {
1008 ((MethodObserver) e.next()).notify(this);
1009 }
1010 }
1011 }
1012
1013
1014 /**
1015 * Return string representation close to declaration format,
1016 * `public static void main(String[]) throws IOException', e.g.
1017 *
1018 * @return String representation of the method.
1019 */
1020 public final String toString() {
1021 String access = Utility.accessToString(access_flags);
1022 String signature = Type.getMethodSignature(type, arg_types);
1023 signature = Utility.methodSignatureToString(signature, name, access, true,
1024 getLocalVariableTable(cp));
1025 StringBuffer buf = new StringBuffer(signature);
1026 if (throws_vec.size() > 0) {
1027 for (Iterator e = throws_vec.iterator(); e.hasNext();) {
1028 buf.append("\n\t\tthrows ").append(e.next());
1029 }
1030 }
1031 return buf.toString();
1032 }
1033
1034
1035 /** @return deep copy of this method
1036 */
1037 public MethodGen copy( String class_name, ConstantPoolGen cp ) {
1038 Method m = ((MethodGen) clone()).getMethod();
1039 MethodGen mg = new MethodGen(m, class_name, this.cp);
1040 if (this.cp != cp) {
1041 mg.setConstantPool(cp);
1042 mg.getInstructionList().replaceConstantPool(this.cp, cp);
1043 }
1044 return mg;
1045 }
1046
1047
1048 /**
1049 * @return Comparison strategy object
1050 */
1051 public static BCELComparator getComparator() {
1052 return _cmp;
1053 }
1054
1055
1056 /**
1057 * @param comparator Comparison strategy object
1058 */
1059 public static void setComparator( BCELComparator comparator ) {
1060 _cmp = comparator;
1061 }
1062
1063
1064 /**
1065 * Return value as defined by given BCELComparator strategy.
1066 * By default two MethodGen objects are said to be equal when
1067 * their names and signatures are equal.
1068 *
1069 * @see java.lang.Object#equals(java.lang.Object)
1070 */
1071 public boolean equals( Object obj ) {
1072 return _cmp.equals(this, obj);
1073 }
1074
1075
1076 /**
1077 * Return value as defined by given BCELComparator strategy.
1078 * By default return the hashcode of the method's name XOR signature.
1079 *
1080 * @see java.lang.Object#hashCode()
1081 */
1082 public int hashCode() {
1083 return _cmp.hashCode(this);
1084 }
1085 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/MethodObserver.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Implement this interface if you're interested in changes to a MethodGen object
20 * and register yourself with addObserver().
21 *
22 * @version $Id: MethodObserver.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface MethodObserver {
26
27 public void notify( MethodGen method );
28 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/NEW.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.ExceptionConstants;
19
20 /**
21 * NEW - Create new object
22 * <PRE>Stack: ... -&gt; ..., objectref</PRE>
23 *
24 * @version $Id: NEW.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class NEW extends CPInstruction implements LoadClass, AllocationInstruction,
28 ExceptionThrower, StackProducer {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 NEW() {
35 }
36
37
38 public NEW(int index) {
39 super(org.apache.bcel.Constants.NEW, index);
40 }
41
42
43 public Class[] getExceptions() {
44 Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
45 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, cs, 0,
46 ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
47 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length + 1] = ExceptionConstants.INSTANTIATION_ERROR;
48 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
49 return cs;
50 }
51
52
53 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
54 return (ObjectType) getType(cpg);
55 }
56
57
58 /**
59 * Call corresponding visitor method(s). The order is:
60 * Call visitor methods of implemented interfaces first, then
61 * call methods according to the class hierarchy in descending order,
62 * i.e., the most specific visitXXX() call comes last.
63 *
64 * @param v Visitor object
65 */
66 public void accept( Visitor v ) {
67 v.visitLoadClass(this);
68 v.visitAllocationInstruction(this);
69 v.visitExceptionThrower(this);
70 v.visitStackProducer(this);
71 v.visitTypedInstruction(this);
72 v.visitCPInstruction(this);
73 v.visitNEW(this);
74 }
75 }
+0
-120
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/NEWARRAY.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * NEWARRAY - Create new array of basic type (int, short, ...)
24 * <PRE>Stack: ..., count -&gt; ..., arrayref</PRE>
25 * type must be one of T_INT, T_SHORT, ...
26 *
27 * @version $Id: NEWARRAY.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class NEWARRAY extends Instruction implements AllocationInstruction, ExceptionThrower,
31 StackProducer {
32
33 private byte type;
34
35
36 /**
37 * Empty constructor needed for the Class.newInstance() statement in
38 * Instruction.readInstruction(). Not to be used otherwise.
39 */
40 NEWARRAY() {
41 }
42
43
44 public NEWARRAY(byte type) {
45 super(org.apache.bcel.Constants.NEWARRAY, (short) 2);
46 this.type = type;
47 }
48
49
50 public NEWARRAY(BasicType type) {
51 this(type.getType());
52 }
53
54
55 /**
56 * Dump instruction as byte code to stream out.
57 * @param out Output stream
58 */
59 public void dump( DataOutputStream out ) throws IOException {
60 out.writeByte(opcode);
61 out.writeByte(type);
62 }
63
64
65 /**
66 * @return numeric code for basic element type
67 */
68 public final byte getTypecode() {
69 return type;
70 }
71
72
73 /**
74 * @return type of constructed array
75 */
76 public final Type getType() {
77 return new ArrayType(BasicType.getType(type), 1);
78 }
79
80
81 /**
82 * @return mnemonic for instruction
83 */
84 public String toString( boolean verbose ) {
85 return super.toString(verbose) + " " + org.apache.bcel.Constants.TYPE_NAMES[type];
86 }
87
88
89 /**
90 * Read needed data (e.g. index) from file.
91 */
92 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
93 type = bytes.readByte();
94 length = 2;
95 }
96
97
98 public Class[] getExceptions() {
99 return new Class[] {
100 org.apache.bcel.ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION
101 };
102 }
103
104
105 /**
106 * Call corresponding visitor method(s). The order is:
107 * Call visitor methods of implemented interfaces first, then
108 * call methods according to the class hierarchy in descending order,
109 * i.e., the most specific visitXXX() call comes last.
110 *
111 * @param v Visitor object
112 */
113 public void accept( Visitor v ) {
114 v.visitAllocationInstruction(this);
115 v.visitExceptionThrower(this);
116 v.visitStackProducer(this);
117 v.visitNEWARRAY(this);
118 }
119 }
+0
-43
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/NOP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * NOP - Do nothing
20 *
21 * @version $Id: NOP.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public class NOP extends Instruction {
25
26 public NOP() {
27 super(org.apache.bcel.Constants.NOP, (short) 1);
28 }
29
30
31 /**
32 * Call corresponding visitor method(s). The order is:
33 * Call visitor methods of implemented interfaces first, then
34 * call methods according to the class hierarchy in descending order,
35 * i.e., the most specific visitXXX() call comes last.
36 *
37 * @param v Visitor object
38 */
39 public void accept( Visitor v ) {
40 v.visitNOP(this);
41 }
42 }
+0
-38
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/NamedAndTyped.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote entity that has both name and type. This is true for local variables,
20 * methods and fields.
21 *
22 * @version $Id: NamedAndTyped.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface NamedAndTyped {
26
27 public String getName();
28
29
30 public Type getType();
31
32
33 public void setName( String name );
34
35
36 public void setType( Type type );
37 }
+0
-179
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ObjectType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.HashMap;
19 import java.util.LinkedHashMap;
20 import java.util.Map;
21
22 import org.apache.bcel.Constants;
23 import org.apache.bcel.Repository;
24 import org.apache.bcel.classfile.JavaClass;
25
26
27 /**
28 * Denotes reference such as java.lang.String.
29 *
30 * @version $Id: ObjectType.java 386056 2006-03-15 11:31:56Z tcurdt $
31 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32 */
33 public class ObjectType extends ReferenceType {
34
35 private static final int MAX_CACHE_ENTRIES = 200;
36 private static final int INITIAL_CACHE_CAPACITY = (int)(MAX_CACHE_ENTRIES/0.75);
37 private static HashMap<String, ObjectType> cache;
38 public synchronized static ObjectType getInstance(String class_name) {
39 if (cache == null)
40 cache = new LinkedHashMap<String, ObjectType>(INITIAL_CACHE_CAPACITY, 0.75f, true) {
41
42
43 protected boolean removeEldestEntry(Map.Entry eldest) {
44 return size() > MAX_CACHE_ENTRIES;
45 }
46
47 };
48 ObjectType result = cache.get(class_name);
49 if (result != null) return result;
50 result = new ObjectType(class_name);
51 cache.put(class_name, result);
52 return result;
53 }
54
55 final private String class_name; // Class name of type
56
57 /**
58 * @param class_name fully qualified class name, e.g. java.lang.String
59 */
60 public ObjectType(String class_name) {
61 super(Constants.T_REFERENCE, "L" + class_name.replace('.', '/') + ";");
62 this.class_name = class_name.replace('/', '.');
63 }
64
65
66 /** @return name of referenced class
67 */
68 public String getClassName() {
69 return class_name;
70 }
71
72
73 /** @return a hash code value for the object.
74 */
75 public int hashCode() {
76 return class_name.hashCode();
77 }
78
79
80 /** @return true if both type objects refer to the same class.
81 */
82 public boolean equals( Object type ) {
83 return (type instanceof ObjectType)
84 ? ((ObjectType) type).class_name.equals(class_name)
85 : false;
86 }
87
88
89 /**
90 * If "this" doesn't reference a class, it references an interface
91 * or a non-existant entity.
92 * @deprecated this method returns an inaccurate result
93 * if the class or interface referenced cannot
94 * be found: use referencesClassExact() instead
95 */
96 public boolean referencesClass() {
97 try {
98 JavaClass jc = Repository.lookupClass(class_name);
99 return jc.isClass();
100 } catch (ClassNotFoundException e) {
101 return false;
102 }
103 }
104
105
106 /**
107 * If "this" doesn't reference an interface, it references a class
108 * or a non-existant entity.
109 * @deprecated this method returns an inaccurate result
110 * if the class or interface referenced cannot
111 * be found: use referencesInterfaceExact() instead
112 */
113 public boolean referencesInterface() {
114 try {
115 JavaClass jc = Repository.lookupClass(class_name);
116 return !jc.isClass();
117 } catch (ClassNotFoundException e) {
118 return false;
119 }
120 }
121
122
123 /**
124 * Return true if this type references a class,
125 * false if it references an interface.
126 * @return true if the type references a class, false if
127 * it references an interface
128 * @throws ClassNotFoundException if the class or interface
129 * referenced by this type can't be found
130 */
131 public boolean referencesClassExact() throws ClassNotFoundException {
132 JavaClass jc = Repository.lookupClass(class_name);
133 return jc.isClass();
134 }
135
136
137 /**
138 * Return true if this type references an interface,
139 * false if it references a class.
140 * @return true if the type references an interface, false if
141 * it references a class
142 * @throws ClassNotFoundException if the class or interface
143 * referenced by this type can't be found
144 */
145 public boolean referencesInterfaceExact() throws ClassNotFoundException {
146 JavaClass jc = Repository.lookupClass(class_name);
147 return !jc.isClass();
148 }
149
150
151 /**
152 * Return true if this type is a subclass of given ObjectType.
153 * @throws ClassNotFoundException if any of this class's superclasses
154 * can't be found
155 */
156 public boolean subclassOf( ObjectType superclass ) throws ClassNotFoundException {
157 if (this.referencesInterface() || superclass.referencesInterface()) {
158 return false;
159 }
160 return Repository.instanceOf(this.class_name, superclass.class_name);
161 }
162
163
164 /**
165 * Java Virtual Machine Specification edition 2, § 5.4.4 Access Control
166 * @throws ClassNotFoundException if the class referenced by this type
167 * can't be found
168 */
169 public boolean accessibleTo( ObjectType accessor ) throws ClassNotFoundException {
170 JavaClass jc = Repository.lookupClass(class_name);
171 if (jc.isPublic()) {
172 return true;
173 } else {
174 JavaClass acc = Repository.lookupClass(accessor.class_name);
175 return acc.getPackageName().equals(jc.getPackageName());
176 }
177 }
178 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/POP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * POP - Pop top operand stack word
20 *
21 * <PRE>Stack: ..., word -&gt; ...</PRE>
22 *
23 * @version $Id: POP.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class POP extends StackInstruction implements PopInstruction {
27
28 public POP() {
29 super(org.apache.bcel.Constants.POP);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitStackConsumer(this);
43 v.visitPopInstruction(this);
44 v.visitStackInstruction(this);
45 v.visitPOP(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/POP2.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * POP2 - Pop two top operand stack words
20 *
21 * <PRE>Stack: ..., word2, word1 -&gt; ...</PRE>
22 *
23 * @version $Id: POP2.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public class POP2 extends StackInstruction implements PopInstruction {
27
28 public POP2() {
29 super(org.apache.bcel.Constants.POP2);
30 }
31
32
33 /**
34 * Call corresponding visitor method(s). The order is:
35 * Call visitor methods of implemented interfaces first, then
36 * call methods according to the class hierarchy in descending order,
37 * i.e., the most specific visitXXX() call comes last.
38 *
39 * @param v Visitor object
40 */
41 public void accept( Visitor v ) {
42 v.visitStackConsumer(this);
43 v.visitPopInstruction(this);
44 v.visitStackInstruction(this);
45 v.visitPOP2(this);
46 }
47 }
+0
-178
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/PUSH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Wrapper class for push operations, which are implemented either as BIPUSH,
22 * LDC or xCONST_n instructions.
23 *
24 * @version $Id: PUSH.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public final class PUSH implements CompoundInstruction, VariableLengthInstruction,
28 InstructionConstants {
29
30 private Instruction instruction;
31
32
33 /**
34 * This constructor also applies for values of type short, char, byte
35 *
36 * @param cp Constant pool
37 * @param value to be pushed
38 */
39 public PUSH(ConstantPoolGen cp, int value) {
40 if ((value >= -1) && (value <= 5)) {
41 instruction = INSTRUCTIONS[Constants.ICONST_0 + value];
42 } else if ((value >= -128) && (value <= 127)) {
43 instruction = new BIPUSH((byte) value);
44 } else if ((value >= -32768) && (value <= 32767)) {
45 instruction = new SIPUSH((short) value);
46 } else {
47 instruction = new LDC(cp.addInteger(value));
48 }
49 }
50
51
52 /**
53 * @param cp Constant pool
54 * @param value to be pushed
55 */
56 public PUSH(ConstantPoolGen cp, boolean value) {
57 instruction = INSTRUCTIONS[Constants.ICONST_0 + (value ? 1 : 0)];
58 }
59
60
61 /**
62 * @param cp Constant pool
63 * @param value to be pushed
64 */
65 public PUSH(ConstantPoolGen cp, float value) {
66 if (value == 0.0) {
67 instruction = FCONST_0;
68 } else if (value == 1.0) {
69 instruction = FCONST_1;
70 } else if (value == 2.0) {
71 instruction = FCONST_2;
72 } else {
73 instruction = new LDC(cp.addFloat(value));
74 }
75 }
76
77
78 /**
79 * @param cp Constant pool
80 * @param value to be pushed
81 */
82 public PUSH(ConstantPoolGen cp, long value) {
83 if (value == 0) {
84 instruction = LCONST_0;
85 } else if (value == 1) {
86 instruction = LCONST_1;
87 } else {
88 instruction = new LDC2_W(cp.addLong(value));
89 }
90 }
91
92
93 /**
94 * @param cp Constant pool
95 * @param value to be pushed
96 */
97 public PUSH(ConstantPoolGen cp, double value) {
98 if (value == 0.0) {
99 instruction = DCONST_0;
100 } else if (value == 1.0) {
101 instruction = DCONST_1;
102 } else {
103 instruction = new LDC2_W(cp.addDouble(value));
104 }
105 }
106
107
108 /**
109 * @param cp Constant pool
110 * @param value to be pushed
111 */
112 public PUSH(ConstantPoolGen cp, String value) {
113 if (value == null) {
114 instruction = ACONST_NULL;
115 } else {
116 instruction = new LDC(cp.addString(value));
117 }
118 }
119
120
121 /**
122 * @param cp Constant pool
123 * @param value to be pushed
124 */
125 public PUSH(ConstantPoolGen cp, Number value) {
126 if ((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)) {
127 instruction = new PUSH(cp, value.intValue()).instruction;
128 } else if (value instanceof Double) {
129 instruction = new PUSH(cp, value.doubleValue()).instruction;
130 } else if (value instanceof Float) {
131 instruction = new PUSH(cp, value.floatValue()).instruction;
132 } else if (value instanceof Long) {
133 instruction = new PUSH(cp, value.longValue()).instruction;
134 } else {
135 throw new ClassGenException("What's this: " + value);
136 }
137 }
138
139
140 /**
141 * creates a push object from a Character value. Warning: Make sure not to attempt to allow
142 * autoboxing to create this value parameter, as an alternative constructor will be called
143 *
144 * @param cp Constant pool
145 * @param value to be pushed
146 */
147 public PUSH(ConstantPoolGen cp, Character value) {
148 this(cp, value.charValue());
149 }
150
151
152 /**
153 * @param cp Constant pool
154 * @param value to be pushed
155 */
156 public PUSH(ConstantPoolGen cp, Boolean value) {
157 this(cp, value.booleanValue());
158 }
159
160
161 public final InstructionList getInstructionList() {
162 return new InstructionList(instruction);
163 }
164
165
166 public final Instruction getInstruction() {
167 return instruction;
168 }
169
170
171 /**
172 * @return mnemonic for instruction
173 */
174 public String toString() {
175 return instruction.toString() + " (PUSH)";
176 }
177 }
+0
-80
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/PUTFIELD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * PUTFIELD - Put field in object
23 * <PRE>Stack: ..., objectref, value -&gt; ...</PRE>
24 * OR
25 * <PRE>Stack: ..., objectref, value.word1, value.word2 -&gt; ...</PRE>
26 *
27 * @version $Id: PUTFIELD.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class PUTFIELD extends FieldInstruction implements PopInstruction, ExceptionThrower {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 PUTFIELD() {
37 }
38
39
40 public PUTFIELD(int index) {
41 super(Constants.PUTFIELD, index);
42 }
43
44
45 public int consumeStack( ConstantPoolGen cpg ) {
46 return getFieldSize(cpg) + 1;
47 }
48
49
50 public Class[] getExceptions() {
51 Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
52 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
53 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
54 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
55 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
56 return cs;
57 }
58
59
60 /**
61 * Call corresponding visitor method(s). The order is:
62 * Call visitor methods of implemented interfaces first, then
63 * call methods according to the class hierarchy in descending order,
64 * i.e., the most specific visitXXX() call comes last.
65 *
66 * @param v Visitor object
67 */
68 public void accept( Visitor v ) {
69 v.visitExceptionThrower(this);
70 v.visitStackConsumer(this);
71 v.visitPopInstruction(this);
72 v.visitTypedInstruction(this);
73 v.visitLoadClass(this);
74 v.visitCPInstruction(this);
75 v.visitFieldOrMethod(this);
76 v.visitFieldInstruction(this);
77 v.visitPUTFIELD(this);
78 }
79 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/PUTSTATIC.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * PUTSTATIC - Put static field in class
23 * <PRE>Stack: ..., value -&gt; ...</PRE>
24 * OR
25 * <PRE>Stack: ..., value.word1, value.word2 -&gt; ...</PRE>
26 *
27 * @version $Id: PUTSTATIC.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class PUTSTATIC extends FieldInstruction implements ExceptionThrower, PopInstruction {
31
32 /**
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 PUTSTATIC() {
37 }
38
39
40 public PUTSTATIC(int index) {
41 super(Constants.PUTSTATIC, index);
42 }
43
44
45 public int consumeStack( ConstantPoolGen cpg ) {
46 return getFieldSize(cpg);
47 }
48
49
50 public Class[] getExceptions() {
51 Class[] cs = new Class[1 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
52 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
53 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
54 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
55 return cs;
56 }
57
58
59 /**
60 * Call corresponding visitor method(s). The order is:
61 * Call visitor methods of implemented interfaces first, then
62 * call methods according to the class hierarchy in descending order,
63 * i.e., the most specific visitXXX() call comes last.
64 *
65 * @param v Visitor object
66 */
67 public void accept( Visitor v ) {
68 v.visitExceptionThrower(this);
69 v.visitStackConsumer(this);
70 v.visitPopInstruction(this);
71 v.visitTypedInstruction(this);
72 v.visitLoadClass(this);
73 v.visitCPInstruction(this);
74 v.visitFieldOrMethod(this);
75 v.visitFieldInstruction(this);
76 v.visitPUTSTATIC(this);
77 }
78 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/PopInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an unparameterized instruction to pop a value on top from the stack,
20 * such as ISTORE, POP, PUTSTATIC.
21 *
22 * @version $Id: PopInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 * @see ISTORE
25 * @see POP
26 */
27 public interface PopInstruction extends StackConsumer {
28 }
+0
-34
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/PushInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an unparameterized instruction to produce a value on top of the stack,
20 * such as ILOAD, LDC, SIPUSH, DUP, ICONST, etc.
21 *
22 * @version $Id: PushInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
25 * @see ILOAD
26 * @see ICONST
27 * @see LDC
28 * @see DUP
29 * @see SIPUSH
30 * @see GETSTATIC
31 */
32 public interface PushInstruction extends StackProducer {
33 }
+0
-139
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/RET.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * RET - Return from subroutine
24 *
25 * <PRE>Stack: ... -&gt; ...</PRE>
26 *
27 * @version $Id: RET.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class RET extends Instruction implements IndexedInstruction, TypedInstruction {
31
32 private boolean wide;
33 private int index; // index to local variable containg the return address
34
35
36 /**
37 * Empty constructor needed for the Class.newInstance() statement in
38 * Instruction.readInstruction(). Not to be used otherwise.
39 */
40 RET() {
41 }
42
43
44 public RET(int index) {
45 super(org.apache.bcel.Constants.RET, (short) 2);
46 setIndex(index); // May set wide as side effect
47 }
48
49
50 /**
51 * Dump instruction as byte code to stream out.
52 * @param out Output stream
53 */
54 public void dump( DataOutputStream out ) throws IOException {
55 if (wide) {
56 out.writeByte(org.apache.bcel.Constants.WIDE);
57 }
58 out.writeByte(opcode);
59 if (wide) {
60 out.writeShort(index);
61 } else {
62 out.writeByte(index);
63 }
64 }
65
66
67 private final void setWide() {
68 wide = index > org.apache.bcel.Constants.MAX_BYTE;
69 if (wide) {
70 length = 4; // Including the wide byte
71 } else {
72 length = 2;
73 }
74 }
75
76
77 /**
78 * Read needed data (e.g. index) from file.
79 */
80 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
81 this.wide = wide;
82 if (wide) {
83 index = bytes.readUnsignedShort();
84 length = 4;
85 } else {
86 index = bytes.readUnsignedByte();
87 length = 2;
88 }
89 }
90
91
92 /**
93 * @return index of local variable containg the return address
94 */
95 public final int getIndex() {
96 return index;
97 }
98
99
100 /**
101 * Set index of local variable containg the return address
102 */
103 public final void setIndex( int n ) {
104 if (n < 0) {
105 throw new ClassGenException("Negative index value: " + n);
106 }
107 index = n;
108 setWide();
109 }
110
111
112 /**
113 * @return mnemonic for instruction
114 */
115 public String toString( boolean verbose ) {
116 return super.toString(verbose) + " " + index;
117 }
118
119
120 /** @return return address type
121 */
122 public Type getType( ConstantPoolGen cp ) {
123 return ReturnaddressType.NO_TARGET;
124 }
125
126
127 /**
128 * Call corresponding visitor method(s). The order is:
129 * Call visitor methods of implemented interfaces first, then
130 * call methods according to the class hierarchy in descending order,
131 * i.e., the most specific visitXXX() call comes last.
132 *
133 * @param v Visitor object
134 */
135 public void accept( Visitor v ) {
136 v.visitRET(this);
137 }
138 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/RETURN.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * RETURN - Return from void method
20 * <PRE>Stack: ... -&gt; &lt;empty&gt;</PRE>
21 *
22 * @version $Id: RETURN.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class RETURN extends ReturnInstruction {
26
27 public RETURN() {
28 super(org.apache.bcel.Constants.RETURN);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitExceptionThrower(this);
42 v.visitTypedInstruction(this);
43 v.visitStackConsumer(this);
44 v.visitReturnInstruction(this);
45 v.visitRETURN(this);
46 }
47 }
+0
-330
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ReferenceType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.Repository;
20 import org.apache.bcel.classfile.JavaClass;
21
22 /**
23 * Super class for object and array types.
24 *
25 * @version $Id: ReferenceType.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public abstract class ReferenceType extends Type {
29
30 protected ReferenceType(byte t, String s) {
31 super(t, s);
32 }
33
34
35 /** Class is non-abstract but not instantiable from the outside
36 */
37 ReferenceType() {
38 super(Constants.T_OBJECT, "<null object>");
39 }
40
41
42 /**
43 * Return true iff this type is castable to another type t as defined in
44 * the JVM specification. The case where this is Type.NULL is not
45 * defined (see the CHECKCAST definition in the JVM specification).
46 * However, because e.g. CHECKCAST doesn't throw a
47 * ClassCastException when casting a null reference to any Object,
48 * true is returned in this case.
49 *
50 * @throws ClassNotFoundException if any classes or interfaces required
51 * to determine assignment compatibility can't be found
52 */
53 public boolean isCastableTo( Type t ) throws ClassNotFoundException {
54 if (this.equals(Type.NULL)) {
55 return true; // If this is ever changed in isAssignmentCompatible()
56 }
57 return isAssignmentCompatibleWith(t);
58 /* Yes, it's true: It's the same definition.
59 * See vmspec2 AASTORE / CHECKCAST definitions.
60 */
61 }
62
63
64 /**
65 * Return true iff this is assignment compatible with another type t
66 * as defined in the JVM specification; see the AASTORE definition
67 * there.
68 * @throws ClassNotFoundException if any classes or interfaces required
69 * to determine assignment compatibility can't be found
70 */
71 public boolean isAssignmentCompatibleWith( Type t ) throws ClassNotFoundException {
72 if (!(t instanceof ReferenceType)) {
73 return false;
74 }
75 ReferenceType T = (ReferenceType) t;
76 if (this.equals(Type.NULL)) {
77 return true; // This is not explicitely stated, but clear. Isn't it?
78 }
79 /* If this is a class type then
80 */
81 if ((this instanceof ObjectType) && (((ObjectType) this).referencesClassExact())) {
82 /* If T is a class type, then this must be the same class as T,
83 or this must be a subclass of T;
84 */
85 if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
86 if (this.equals(T)) {
87 return true;
88 }
89 if (Repository.instanceOf(((ObjectType) this).getClassName(), ((ObjectType) T)
90 .getClassName())) {
91 return true;
92 }
93 }
94 /* If T is an interface type, this must implement interface T.
95 */
96 if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
97 if (Repository.implementationOf(((ObjectType) this).getClassName(),
98 ((ObjectType) T).getClassName())) {
99 return true;
100 }
101 }
102 }
103 /* If this is an interface type, then:
104 */
105 if ((this instanceof ObjectType) && (((ObjectType) this).referencesInterfaceExact())) {
106 /* If T is a class type, then T must be Object (§2.4.7).
107 */
108 if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
109 if (T.equals(Type.OBJECT)) {
110 return true;
111 }
112 }
113 /* If T is an interface type, then T must be the same interface
114 * as this or a superinterface of this (§2.13.2).
115 */
116 if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
117 if (this.equals(T)) {
118 return true;
119 }
120 if (Repository.implementationOf(((ObjectType) this).getClassName(),
121 ((ObjectType) T).getClassName())) {
122 return true;
123 }
124 }
125 }
126 /* If this is an array type, namely, the type SC[], that is, an
127 * array of components of type SC, then:
128 */
129 if (this instanceof ArrayType) {
130 /* If T is a class type, then T must be Object (§2.4.7).
131 */
132 if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
133 if (T.equals(Type.OBJECT)) {
134 return true;
135 }
136 }
137 /* If T is an array type TC[], that is, an array of components
138 * of type TC, then one of the following must be true:
139 */
140 if (T instanceof ArrayType) {
141 /* TC and SC are the same primitive type (§2.4.1).
142 */
143 Type sc = ((ArrayType) this).getElementType();
144 Type tc = ((ArrayType) T).getElementType();
145 if (sc instanceof BasicType && tc instanceof BasicType && sc.equals(tc)) {
146 return true;
147 }
148 /* TC and SC are reference types (§2.4.6), and type SC is
149 * assignable to TC by these runtime rules.
150 */
151 if (tc instanceof ReferenceType && sc instanceof ReferenceType
152 && ((ReferenceType) sc).isAssignmentCompatibleWith(tc)) {
153 return true;
154 }
155 }
156 /* If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15). */
157 // TODO: Check if this is still valid or find a way to dynamically find out which
158 // interfaces arrays implement. However, as of the JVM specification edition 2, there
159 // are at least two different pages where assignment compatibility is defined and
160 // on one of them "interfaces implemented by arrays" is exchanged with "'Cloneable' or
161 // 'java.io.Serializable'"
162 if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
163 for (int ii = 0; ii < Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS.length; ii++) {
164 if (T.equals(ObjectType.getInstance(Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS[ii]))) {
165 return true;
166 }
167 }
168 }
169 }
170 return false; // default.
171 }
172
173
174 /**
175 * This commutative operation returns the first common superclass (narrowest ReferenceType
176 * referencing a class, not an interface).
177 * If one of the types is a superclass of the other, the former is returned.
178 * If "this" is Type.NULL, then t is returned.
179 * If t is Type.NULL, then "this" is returned.
180 * If "this" equals t ['this.equals(t)'] "this" is returned.
181 * If "this" or t is an ArrayType, then Type.OBJECT is returned;
182 * unless their dimensions match. Then an ArrayType of the same
183 * number of dimensions is returned, with its basic type being the
184 * first common super class of the basic types of "this" and t.
185 * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
186 * If not all of the two classes' superclasses cannot be found, "null" is returned.
187 * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier".
188 *
189 * @throws ClassNotFoundException on failure to find superclasses of this
190 * type, or the type passed as a parameter
191 */
192 public ReferenceType getFirstCommonSuperclass( ReferenceType t ) throws ClassNotFoundException {
193 if (this.equals(Type.NULL)) {
194 return t;
195 }
196 if (t.equals(Type.NULL)) {
197 return this;
198 }
199 if (this.equals(t)) {
200 return this;
201 /*
202 * TODO: Above sounds a little arbitrary. On the other hand, there is
203 * no object referenced by Type.NULL so we can also say all the objects
204 * referenced by Type.NULL were derived from java.lang.Object.
205 * However, the Java Language's "instanceof" operator proves us wrong:
206 * "null" is not referring to an instance of java.lang.Object :)
207 */
208 }
209 /* This code is from a bug report by Konstantin Shagin <konst@cs.technion.ac.il> */
210 if ((this instanceof ArrayType) && (t instanceof ArrayType)) {
211 ArrayType arrType1 = (ArrayType) this;
212 ArrayType arrType2 = (ArrayType) t;
213 if ((arrType1.getDimensions() == arrType2.getDimensions())
214 && arrType1.getBasicType() instanceof ObjectType
215 && arrType2.getBasicType() instanceof ObjectType) {
216 return new ArrayType(((ObjectType) arrType1.getBasicType())
217 .getFirstCommonSuperclass((ObjectType) arrType2.getBasicType()), arrType1
218 .getDimensions());
219 }
220 }
221 if ((this instanceof ArrayType) || (t instanceof ArrayType)) {
222 return Type.OBJECT;
223 // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
224 }
225 if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface())
226 || ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) {
227 return Type.OBJECT;
228 // TODO: The above line is correct comparing to the vmspec2. But one could
229 // make class file verification a bit stronger here by using the notion of
230 // superinterfaces or even castability or assignment compatibility.
231 }
232 // this and t are ObjectTypes, see above.
233 ObjectType thiz = (ObjectType) this;
234 ObjectType other = (ObjectType) t;
235 JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
236 JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
237 if ((thiz_sups == null) || (other_sups == null)) {
238 return null;
239 }
240 // Waaahh...
241 JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
242 JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
243 System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
244 System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
245 this_sups[0] = Repository.lookupClass(thiz.getClassName());
246 t_sups[0] = Repository.lookupClass(other.getClassName());
247 for (int i = 0; i < t_sups.length; i++) {
248 for (int j = 0; j < this_sups.length; j++) {
249 if (this_sups[j].equals(t_sups[i])) {
250 return ObjectType.getInstance(this_sups[j].getClassName());
251 }
252 }
253 }
254 // Huh? Did you ask for Type.OBJECT's superclass??
255 return null;
256 }
257
258
259 /**
260 * This commutative operation returns the first common superclass (narrowest ReferenceType
261 * referencing a class, not an interface).
262 * If one of the types is a superclass of the other, the former is returned.
263 * If "this" is Type.NULL, then t is returned.
264 * If t is Type.NULL, then "this" is returned.
265 * If "this" equals t ['this.equals(t)'] "this" is returned.
266 * If "this" or t is an ArrayType, then Type.OBJECT is returned.
267 * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
268 * If not all of the two classes' superclasses cannot be found, "null" is returned.
269 * See the JVM specification edition 2, "§4.9.2 The Bytecode Verifier".
270 *
271 * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has
272 * slightly changed semantics.
273 * @throws ClassNotFoundException on failure to find superclasses of this
274 * type, or the type passed as a parameter
275 */
276 public ReferenceType firstCommonSuperclass( ReferenceType t ) throws ClassNotFoundException {
277 if (this.equals(Type.NULL)) {
278 return t;
279 }
280 if (t.equals(Type.NULL)) {
281 return this;
282 }
283 if (this.equals(t)) {
284 return this;
285 /*
286 * TODO: Above sounds a little arbitrary. On the other hand, there is
287 * no object referenced by Type.NULL so we can also say all the objects
288 * referenced by Type.NULL were derived from java.lang.Object.
289 * However, the Java Language's "instanceof" operator proves us wrong:
290 * "null" is not referring to an instance of java.lang.Object :)
291 */
292 }
293 if ((this instanceof ArrayType) || (t instanceof ArrayType)) {
294 return Type.OBJECT;
295 // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
296 }
297 if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface())
298 || ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) {
299 return Type.OBJECT;
300 // TODO: The above line is correct comparing to the vmspec2. But one could
301 // make class file verification a bit stronger here by using the notion of
302 // superinterfaces or even castability or assignment compatibility.
303 }
304 // this and t are ObjectTypes, see above.
305 ObjectType thiz = (ObjectType) this;
306 ObjectType other = (ObjectType) t;
307 JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
308 JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
309 if ((thiz_sups == null) || (other_sups == null)) {
310 return null;
311 }
312 // Waaahh...
313 JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
314 JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
315 System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
316 System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
317 this_sups[0] = Repository.lookupClass(thiz.getClassName());
318 t_sups[0] = Repository.lookupClass(other.getClassName());
319 for (int i = 0; i < t_sups.length; i++) {
320 for (int j = 0; j < this_sups.length; j++) {
321 if (this_sups[j].equals(t_sups[i])) {
322 return ObjectType.getInstance(this_sups[j].getClassName());
323 }
324 }
325 }
326 // Huh? Did you ask for Type.OBJECT's superclass??
327 return null;
328 }
329 }
+0
-79
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ReturnInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19 import org.apache.bcel.ExceptionConstants;
20
21 /**
22 * Super class for the xRETURN family of instructions.
23 *
24 * @version $Id: ReturnInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public abstract class ReturnInstruction extends Instruction implements ExceptionThrower,
28 TypedInstruction, StackConsumer {
29
30 /**
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 ReturnInstruction() {
35 }
36
37
38 /**
39 * @param opcode of instruction
40 */
41 protected ReturnInstruction(short opcode) {
42 super(opcode, (short) 1);
43 }
44
45
46 public Type getType() {
47 switch (opcode) {
48 case Constants.IRETURN:
49 return Type.INT;
50 case Constants.LRETURN:
51 return Type.LONG;
52 case Constants.FRETURN:
53 return Type.FLOAT;
54 case Constants.DRETURN:
55 return Type.DOUBLE;
56 case Constants.ARETURN:
57 return Type.OBJECT;
58 case Constants.RETURN:
59 return Type.VOID;
60 default: // Never reached
61 throw new ClassGenException("Unknown type " + opcode);
62 }
63 }
64
65
66 public Class[] getExceptions() {
67 return new Class[] {
68 ExceptionConstants.ILLEGAL_MONITOR_STATE
69 };
70 }
71
72
73 /** @return type associated with the instruction
74 */
75 public Type getType( ConstantPoolGen cp ) {
76 return getType();
77 }
78 }
+0
-82
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/ReturnaddressType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import org.apache.bcel.Constants;
19
20 /**
21 * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
22 *
23 * see vmspec2 §3.3.3
24 * @version $Id: ReturnaddressType.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author Enver Haase
26 */
27 public class ReturnaddressType extends Type {
28
29 public static final ReturnaddressType NO_TARGET = new ReturnaddressType();
30 private InstructionHandle returnTarget;
31
32
33 /**
34 * A Returnaddress [that doesn't know where to return to].
35 */
36 private ReturnaddressType() {
37 super(Constants.T_ADDRESS, "<return address>");
38 }
39
40
41 /**
42 * Creates a ReturnaddressType object with a target.
43 */
44 public ReturnaddressType(InstructionHandle returnTarget) {
45 super(Constants.T_ADDRESS, "<return address targeting " + returnTarget + ">");
46 this.returnTarget = returnTarget;
47 }
48
49
50 /** @return a hash code value for the object.
51 */
52 public int hashCode() {
53 if (returnTarget == null) {
54 return 0;
55 }
56 return returnTarget.hashCode();
57 }
58
59
60 /**
61 * Returns if the two Returnaddresses refer to the same target.
62 */
63 public boolean equals( Object rat ) {
64 if (!(rat instanceof ReturnaddressType)) {
65 return false;
66 }
67 ReturnaddressType that = (ReturnaddressType) rat;
68 if (this.returnTarget == null || that.returnTarget == null) {
69 return that.returnTarget == this.returnTarget;
70 }
71 return that.returnTarget.equals(this.returnTarget);
72 }
73
74
75 /**
76 * @return the target of this ReturnaddressType
77 */
78 public InstructionHandle getTarget() {
79 return returnTarget;
80 }
81 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/SALOAD.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * SALOAD - Load short from array
20 * <PRE>Stack: ..., arrayref, index -&gt; ..., value</PRE>
21 *
22 * @version $Id: SALOAD.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class SALOAD extends ArrayInstruction implements StackProducer {
26
27 public SALOAD() {
28 super(org.apache.bcel.Constants.SALOAD);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackProducer(this);
42 v.visitExceptionThrower(this);
43 v.visitTypedInstruction(this);
44 v.visitArrayInstruction(this);
45 v.visitSALOAD(this);
46 }
47 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/SASTORE.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * SASTORE - Store into short array
20 * <PRE>Stack: ..., arrayref, index, value -&gt; ...</PRE>
21 *
22 * @version $Id: SASTORE.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class SASTORE extends ArrayInstruction implements StackConsumer {
26
27 public SASTORE() {
28 super(org.apache.bcel.Constants.SASTORE);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackConsumer(this);
42 v.visitExceptionThrower(this);
43 v.visitTypedInstruction(this);
44 v.visitArrayInstruction(this);
45 v.visitSASTORE(this);
46 }
47 }
+0
-103
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/SIPUSH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * SIPUSH - Push short
24 *
25 * <PRE>Stack: ... -&gt; ..., value</PRE>
26 *
27 * @version $Id: SIPUSH.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 */
30 public class SIPUSH extends Instruction implements ConstantPushInstruction {
31
32 private short b;
33
34
35 /**
36 * Empty constructor needed for the Class.newInstance() statement in
37 * Instruction.readInstruction(). Not to be used otherwise.
38 */
39 SIPUSH() {
40 }
41
42
43 public SIPUSH(short b) {
44 super(org.apache.bcel.Constants.SIPUSH, (short) 3);
45 this.b = b;
46 }
47
48
49 /**
50 * Dump instruction as short code to stream out.
51 */
52 public void dump( DataOutputStream out ) throws IOException {
53 super.dump(out);
54 out.writeShort(b);
55 }
56
57
58 /**
59 * @return mnemonic for instruction
60 */
61 public String toString( boolean verbose ) {
62 return super.toString(verbose) + " " + b;
63 }
64
65
66 /**
67 * Read needed data (e.g. index) from file.
68 */
69 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
70 length = 3;
71 b = bytes.readShort();
72 }
73
74
75 public Number getValue() {
76 return new Integer(b);
77 }
78
79
80 /** @return Type.SHORT
81 */
82 public Type getType( ConstantPoolGen cp ) {
83 return Type.SHORT;
84 }
85
86
87 /**
88 * Call corresponding visitor method(s). The order is:
89 * Call visitor methods of implemented interfaces first, then
90 * call methods according to the class hierarchy in descending order,
91 * i.e., the most specific visitXXX() call comes last.
92 *
93 * @param v Visitor object
94 */
95 public void accept( Visitor v ) {
96 v.visitPushInstruction(this);
97 v.visitStackProducer(this);
98 v.visitTypedInstruction(this);
99 v.visitConstantPushInstruction(this);
100 v.visitSIPUSH(this);
101 }
102 }
+0
-47
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/SWAP.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * SWAP - Swa top operand stack word
20 * <PRE>Stack: ..., word2, word1 -&gt; ..., word1, word2</PRE>
21 *
22 * @version $Id: SWAP.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public class SWAP extends StackInstruction implements StackConsumer, StackProducer {
26
27 public SWAP() {
28 super(org.apache.bcel.Constants.SWAP);
29 }
30
31
32 /**
33 * Call corresponding visitor method(s). The order is:
34 * Call visitor methods of implemented interfaces first, then
35 * call methods according to the class hierarchy in descending order,
36 * i.e., the most specific visitXXX() call comes last.
37 *
38 * @param v Visitor object
39 */
40 public void accept( Visitor v ) {
41 v.visitStackConsumer(this);
42 v.visitStackProducer(this);
43 v.visitStackInstruction(this);
44 v.visitSWAP(this);
45 }
46 }
+0
-153
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/SWITCH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or
20 * TABLESWITCH instruction, depending on whether the match values (int[]) can be
21 * sorted with no gaps between the numbers.
22 *
23 * @version $Id: SWITCH.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25 */
26 public final class SWITCH implements CompoundInstruction {
27
28 private int[] match;
29 private InstructionHandle[] targets;
30 private Select instruction;
31 private int match_length;
32
33
34 /**
35 * Template for switch() constructs. If the match array can be
36 * sorted in ascending order with gaps no larger than max_gap
37 * between the numbers, a TABLESWITCH instruction is generated, and
38 * a LOOKUPSWITCH otherwise. The former may be more efficient, but
39 * needs more space.
40 *
41 * Note, that the key array always will be sorted, though we leave
42 * the original arrays unaltered.
43 *
44 * @param match array of match values (case 2: ... case 7: ..., etc.)
45 * @param targets the instructions to be branched to for each case
46 * @param target the default target
47 * @param max_gap maximum gap that may between case branches
48 */
49 public SWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target, int max_gap) {
50 this.match = (int[]) match.clone();
51 this.targets = (InstructionHandle[]) targets.clone();
52 if ((match_length = match.length) < 2) {
53 instruction = new TABLESWITCH(match, targets, target);
54 } else {
55 sort(0, match_length - 1);
56 if (matchIsOrdered(max_gap)) {
57 fillup(max_gap, target);
58 instruction = new TABLESWITCH(this.match, this.targets, target);
59 } else {
60 instruction = new LOOKUPSWITCH(this.match, this.targets, target);
61 }
62 }
63 }
64
65
66 public SWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target) {
67 this(match, targets, target, 1);
68 }
69
70
71 private final void fillup( int max_gap, InstructionHandle target ) {
72 int max_size = match_length + match_length * max_gap;
73 int[] m_vec = new int[max_size];
74 InstructionHandle[] t_vec = new InstructionHandle[max_size];
75 int count = 1;
76 m_vec[0] = match[0];
77 t_vec[0] = targets[0];
78 for (int i = 1; i < match_length; i++) {
79 int prev = match[i - 1];
80 int gap = match[i] - prev;
81 for (int j = 1; j < gap; j++) {
82 m_vec[count] = prev + j;
83 t_vec[count] = target;
84 count++;
85 }
86 m_vec[count] = match[i];
87 t_vec[count] = targets[i];
88 count++;
89 }
90 match = new int[count];
91 targets = new InstructionHandle[count];
92 System.arraycopy(m_vec, 0, match, 0, count);
93 System.arraycopy(t_vec, 0, targets, 0, count);
94 }
95
96
97 /**
98 * Sort match and targets array with QuickSort.
99 */
100 private final void sort( int l, int r ) {
101 int i = l, j = r;
102 int h, m = match[(l + r) / 2];
103 InstructionHandle h2;
104 do {
105 while (match[i] < m) {
106 i++;
107 }
108 while (m < match[j]) {
109 j--;
110 }
111 if (i <= j) {
112 h = match[i];
113 match[i] = match[j];
114 match[j] = h; // Swap elements
115 h2 = targets[i];
116 targets[i] = targets[j];
117 targets[j] = h2; // Swap instructions, too
118 i++;
119 j--;
120 }
121 } while (i <= j);
122 if (l < j) {
123 sort(l, j);
124 }
125 if (i < r) {
126 sort(i, r);
127 }
128 }
129
130
131 /**
132 * @return match is sorted in ascending order with no gap bigger than max_gap?
133 */
134 private final boolean matchIsOrdered( int max_gap ) {
135 for (int i = 1; i < match_length; i++) {
136 if (match[i] - match[i - 1] > max_gap) {
137 return false;
138 }
139 }
140 return true;
141 }
142
143
144 public final InstructionList getInstructionList() {
145 return new InstructionList(instruction);
146 }
147
148
149 public final Instruction getInstruction() {
150 return instruction;
151 }
152 }
+0
-236
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/Select.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions.
24 *
25 * <p>We use our super's <code>target</code> property as the default target.
26 *
27 * @version $Id: Select.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29 * @see LOOKUPSWITCH
30 * @see TABLESWITCH
31 * @see InstructionList
32 */
33 public abstract class Select extends BranchInstruction implements VariableLengthInstruction,
34 StackProducer {
35
36 protected int[] match; // matches, i.e., case 1: ...
37 protected int[] indices; // target offsets
38 protected InstructionHandle[] targets; // target objects in instruction list
39 protected int fixed_length; // fixed length defined by subclasses
40 protected int match_length; // number of cases
41 protected int padding = 0; // number of pad bytes for alignment
42
43
44 /**
45 * Empty constructor needed for the Class.newInstance() statement in
46 * Instruction.readInstruction(). Not to be used otherwise.
47 */
48 Select() {
49 }
50
51
52 /**
53 * (Match, target) pairs for switch.
54 * `Match' and `targets' must have the same length of course.
55 *
56 * @param match array of matching values
57 * @param targets instruction targets
58 * @param defaultTarget default instruction target
59 */
60 Select(short opcode, int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget) {
61 super(opcode, defaultTarget);
62 this.targets = targets;
63 for (int i = 0; i < targets.length; i++) {
64 notifyTarget(null, targets[i], this);
65 }
66 this.match = match;
67 if ((match_length = match.length) != targets.length) {
68 throw new ClassGenException("Match and target array have not the same length");
69 }
70 indices = new int[match_length];
71 }
72
73
74 /**
75 * Since this is a variable length instruction, it may shift the following
76 * instructions which then need to update their position.
77 *
78 * Called by InstructionList.setPositions when setting the position for every
79 * instruction. In the presence of variable length instructions `setPositions'
80 * performs multiple passes over the instruction list to calculate the
81 * correct (byte) positions and offsets by calling this function.
82 *
83 * @param offset additional offset caused by preceding (variable length) instructions
84 * @param max_offset the maximum offset that may be caused by these instructions
85 * @return additional offset caused by possible change of this instruction's length
86 */
87 protected int updatePosition( int offset, int max_offset ) {
88 position += offset; // Additional offset caused by preceding SWITCHs, GOTOs, etc.
89 short old_length = length;
90 /* Alignment on 4-byte-boundary, + 1, because of tag byte.
91 */
92 padding = (4 - ((position + 1) % 4)) % 4;
93 length = (short) (fixed_length + padding); // Update length
94 return length - old_length;
95 }
96
97
98 /**
99 * Dump instruction as byte code to stream out.
100 * @param out Output stream
101 */
102 public void dump( DataOutputStream out ) throws IOException {
103 out.writeByte(opcode);
104 for (int i = 0; i < padding; i++) {
105 out.writeByte(0);
106 }
107 index = getTargetOffset(); // Write default target offset
108 out.writeInt(index);
109 }
110
111
112 /**
113 * Read needed data (e.g. index) from file.
114 */
115 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
116 padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes
117 for (int i = 0; i < padding; i++) {
118 bytes.readByte();
119 }
120 // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH)
121 index = bytes.readInt();
122 }
123
124
125 /**
126 * @return mnemonic for instruction
127 */
128 public String toString( boolean verbose ) {
129 StringBuffer buf = new StringBuffer(super.toString(verbose));
130 if (verbose) {
131 for (int i = 0; i < match_length; i++) {
132 String s = "null";
133 if (targets[i] != null) {
134 s = targets[i].getInstruction().toString();
135 }
136 buf.append("(").append(match[i]).append(", ").append(s).append(" = {").append(
137 indices[i]).append("})");
138 }
139 } else {
140 buf.append(" ...");
141 }
142 return buf.toString();
143 }
144
145
146 /**
147 * Set branch target for `i'th case
148 */
149 public void setTarget( int i, InstructionHandle target ) {
150 notifyTarget(targets[i], target, this);
151 targets[i] = target;
152 }
153
154
155 /**
156 * @param old_ih old target
157 * @param new_ih new target
158 */
159 public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
160 boolean targeted = false;
161 if (target == old_ih) {
162 targeted = true;
163 setTarget(new_ih);
164 }
165 for (int i = 0; i < targets.length; i++) {
166 if (targets[i] == old_ih) {
167 targeted = true;
168 setTarget(i, new_ih);
169 }
170 }
171 if (!targeted) {
172 throw new ClassGenException("Not targeting " + old_ih);
173 }
174 }
175
176
177 /**
178 * @return true, if ih is target of this instruction
179 */
180 public boolean containsTarget( InstructionHandle ih ) {
181 if (target == ih) {
182 return true;
183 }
184 for (int i = 0; i < targets.length; i++) {
185 if (targets[i] == ih) {
186 return true;
187 }
188 }
189 return false;
190 }
191
192
193 protected Object clone() throws CloneNotSupportedException {
194 Select copy = (Select) super.clone();
195 copy.match = (int[]) match.clone();
196 copy.indices = (int[]) indices.clone();
197 copy.targets = (InstructionHandle[]) targets.clone();
198 return copy;
199 }
200
201
202 /**
203 * Inform targets that they're not targeted anymore.
204 */
205 void dispose() {
206 super.dispose();
207 for (int i = 0; i < targets.length; i++) {
208 targets[i].removeTargeter(this);
209 }
210 }
211
212
213 /**
214 * @return array of match indices
215 */
216 public int[] getMatchs() {
217 return match;
218 }
219
220
221 /**
222 * @return array of match target offsets
223 */
224 public int[] getIndices() {
225 return indices;
226 }
227
228
229 /**
230 * @return array of match targets
231 */
232 public InstructionHandle[] getTargets() {
233 return targets;
234 }
235 }
+0
-30
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/StackConsumer.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote an instruction that may consume a value from the stack.
20 *
21 * @version $Id: StackConsumer.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public interface StackConsumer {
25
26 /** @return how many words are consumed from stack
27 */
28 public int consumeStack( ConstantPoolGen cpg );
29 }
+0
-48
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/StackInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Super class for stack operations like DUP and POP.
20 *
21 * @version $Id: StackInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23 */
24 public abstract class StackInstruction extends Instruction {
25
26 /**
27 * Empty constructor needed for the Class.newInstance() statement in
28 * Instruction.readInstruction(). Not to be used otherwise.
29 */
30 StackInstruction() {
31 }
32
33
34 /**
35 * @param opcode instruction opcode
36 */
37 protected StackInstruction(short opcode) {
38 super(opcode, (short) 1);
39 }
40
41
42 /** @return Type.UNKNOWN
43 */
44 public Type getType( ConstantPoolGen cp ) {
45 return Type.UNKNOWN;
46 }
47 }
+0
-31
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/StackProducer.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denote an instruction that may produce a value on top of the stack
20 * (this excludes DUP_X1, e.g.)
21 *
22 * @version $Id: StackProducer.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface StackProducer {
26
27 /** @return how many words are produced on stack
28 */
29 public int produceStack( ConstantPoolGen cpg );
30 }
+0
-63
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/StoreInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an unparameterized instruction to store a value into a local variable,
20 * e.g. ISTORE.
21 *
22 * @version $Id: StoreInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public abstract class StoreInstruction extends LocalVariableInstruction implements PopInstruction {
26
27 /**
28 * Empty constructor needed for the Class.newInstance() statement in
29 * Instruction.readInstruction(). Not to be used otherwise.
30 * tag and length are defined in readInstruction and initFromFile, respectively.
31 */
32 StoreInstruction(short canon_tag, short c_tag) {
33 super(canon_tag, c_tag);
34 }
35
36
37 /**
38 * @param opcode Instruction opcode
39 * @param c_tag Instruction number for compact version, ASTORE_0, e.g.
40 * @param n local variable index (unsigned short)
41 */
42 protected StoreInstruction(short opcode, short c_tag, int n) {
43 super(opcode, c_tag, n);
44 }
45
46
47 /**
48 * Call corresponding visitor method(s). The order is:
49 * Call visitor methods of implemented interfaces first, then
50 * call methods according to the class hierarchy in descending order,
51 * i.e., the most specific visitXXX() call comes last.
52 *
53 * @param v Visitor object
54 */
55 public void accept( Visitor v ) {
56 v.visitStackConsumer(this);
57 v.visitPopInstruction(this);
58 v.visitTypedInstruction(this);
59 v.visitLocalVariableInstruction(this);
60 v.visitStoreInstruction(this);
61 }
62 }
+0
-107
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/TABLESWITCH.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import org.apache.bcel.util.ByteSequence;
21
22 /**
23 * TABLESWITCH - Switch within given range of values, i.e., low..high
24 *
25 * @version $Id: TABLESWITCH.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 * @see SWITCH
28 */
29 public class TABLESWITCH extends Select {
30
31 /**
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 TABLESWITCH() {
36 }
37
38
39 /**
40 * @param match sorted array of match values, match[0] must be low value,
41 * match[match_length - 1] high value
42 * @param targets where to branch for matched values
43 * @param defaultTarget default branch
44 */
45 public TABLESWITCH(int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget) {
46 super(org.apache.bcel.Constants.TABLESWITCH, match, targets, defaultTarget);
47 length = (short) (13 + match_length * 4); /* Alignment remainder assumed
48 * 0 here, until dump time */
49 fixed_length = length;
50 }
51
52
53 /**
54 * Dump instruction as byte code to stream out.
55 * @param out Output stream
56 */
57 public void dump( DataOutputStream out ) throws IOException {
58 super.dump(out);
59 int low = (match_length > 0) ? match[0] : 0;
60 out.writeInt(low);
61 int high = (match_length > 0) ? match[match_length - 1] : 0;
62 out.writeInt(high);
63 for (int i = 0; i < match_length; i++) {
64 out.writeInt(indices[i] = getTargetOffset(targets[i]));
65 }
66 }
67
68
69 /**
70 * Read needed data (e.g. index) from file.
71 */
72 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
73 super.initFromFile(bytes, wide);
74 int low = bytes.readInt();
75 int high = bytes.readInt();
76 match_length = high - low + 1;
77 fixed_length = (short) (13 + match_length * 4);
78 length = (short) (fixed_length + padding);
79 match = new int[match_length];
80 indices = new int[match_length];
81 targets = new InstructionHandle[match_length];
82 for (int i = low; i <= high; i++) {
83 match[i - low] = i;
84 }
85 for (int i = 0; i < match_length; i++) {
86 indices[i] = bytes.readInt();
87 }
88 }
89
90
91 /**
92 * Call corresponding visitor method(s). The order is:
93 * Call visitor methods of implemented interfaces first, then
94 * call methods according to the class hierarchy in descending order,
95 * i.e., the most specific visitXXX() call comes last.
96 *
97 * @param v Visitor object
98 */
99 public void accept( Visitor v ) {
100 v.visitVariableLengthInstruction(this);
101 v.visitStackProducer(this);
102 v.visitBranchInstruction(this);
103 v.visitSelect(this);
104 v.visitTABLESWITCH(this);
105 }
106 }
+0
-67
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/TargetLostException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Thrown by InstructionList.remove() when one or multiple disposed instruction
20 * are still being referenced by a InstructionTargeter object. I.e. the
21 * InstructionTargeter has to be notified that (one of) the InstructionHandle it
22 * is referencing is being removed from the InstructionList and thus not valid anymore.
23 *
24 * Making this an exception instead of a return value forces the user to handle
25 * these case explicitely in a try { ... } catch. The following code illustrates
26 * how this may be done:
27 *
28 * <PRE>
29 * ...
30 * try {
31 * il.delete(start_ih, end_ih);
32 * } catch(TargetLostException e) {
33 * InstructionHandle[] targets = e.getTargets();
34 * for(int i=0; i < targets.length; i++) {
35 * InstructionTargeter[] targeters = targets[i].getTargeters();
36 *
37 * for(int j=0; j < targeters.length; j++)
38 * targeters[j].updateTarget(targets[i], new_target);
39 * }
40 * }
41 * </PRE>
42 *
43 * @see InstructionHandle
44 * @see InstructionList
45 * @see InstructionTargeter
46 * @version $Id: TargetLostException.java 386056 2006-03-15 11:31:56Z tcurdt $
47 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
48 */
49 public final class TargetLostException extends Exception {
50
51 private InstructionHandle[] targets;
52
53
54 TargetLostException(InstructionHandle[] t, String mesg) {
55 super(mesg);
56 targets = t;
57 }
58
59
60 /**
61 * @return list of instructions still being targeted.
62 */
63 public InstructionHandle[] getTargets() {
64 return targets;
65 }
66 }
+0
-310
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/Type.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.classfile.ClassFormatException;
22 import org.apache.bcel.classfile.Utility;
23
24 /**
25 * Abstract super class for all possible java types, namely basic types
26 * such as int, object types like String and array types, e.g. int[]
27 *
28 * @version $Id: Type.java 393344 2006-04-12 00:38:34Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public abstract class Type implements java.io.Serializable {
32
33 final protected byte type;
34 protected String signature; // signature for the type
35 /** Predefined constants
36 */
37 public static final BasicType VOID = new BasicType(Constants.T_VOID);
38 public static final BasicType BOOLEAN = new BasicType(Constants.T_BOOLEAN);
39 public static final BasicType INT = new BasicType(Constants.T_INT);
40 public static final BasicType SHORT = new BasicType(Constants.T_SHORT);
41 public static final BasicType BYTE = new BasicType(Constants.T_BYTE);
42 public static final BasicType LONG = new BasicType(Constants.T_LONG);
43 public static final BasicType DOUBLE = new BasicType(Constants.T_DOUBLE);
44 public static final BasicType FLOAT = new BasicType(Constants.T_FLOAT);
45 public static final BasicType CHAR = new BasicType(Constants.T_CHAR);
46 public static final ObjectType OBJECT = ObjectType.getInstance("java.lang.Object");
47 public static final ObjectType CLASS = ObjectType.getInstance("java.lang.Class");
48 public static final ObjectType STRING = ObjectType.getInstance("java.lang.String");
49 public static final ObjectType STRINGBUFFER = ObjectType.getInstance("java.lang.StringBuffer");
50 public static final ObjectType THROWABLE = ObjectType.getInstance("java.lang.Throwable");
51 public static final Type[] NO_ARGS = new Type[0];
52 public static final ReferenceType NULL = new ReferenceType() {
53 };
54 public static final Type UNKNOWN = new Type(Constants.T_UNKNOWN, "<unknown object>") {
55 };
56
57
58 protected Type(byte t, String s) {
59 type = t;
60 signature = s;
61 }
62
63
64 /**
65 * @return hashcode of Type
66 */
67 public int hashCode() {
68 return type ^ signature.hashCode();
69 }
70
71
72 /**
73 * @return whether the Types are equal
74 */
75 public boolean equals(Object o) {
76 if (o instanceof Type) {
77 Type t = (Type)o;
78 return (type == t.type) && signature.equals(t.signature);
79 }
80 return false;
81 }
82
83
84 /**
85 * @return signature for given type.
86 */
87 public String getSignature() {
88 return signature;
89 }
90
91
92 /**
93 * @return type as defined in Constants
94 */
95 public byte getType() {
96 return type;
97 }
98
99
100 /**
101 * @return stack size of this type (2 for long and double, 0 for void, 1 otherwise)
102 */
103 public int getSize() {
104 switch (type) {
105 case Constants.T_DOUBLE:
106 case Constants.T_LONG:
107 return 2;
108 case Constants.T_VOID:
109 return 0;
110 default:
111 return 1;
112 }
113 }
114
115
116 /**
117 * @return Type string, e.g. `int[]'
118 */
119 public String toString() {
120 return ((this.equals(Type.NULL) || (type >= Constants.T_UNKNOWN))) ? signature : Utility
121 .signatureToString(signature, false);
122 }
123
124
125 /**
126 * Convert type to Java method signature, e.g. int[] f(java.lang.String x)
127 * becomes (Ljava/lang/String;)[I
128 *
129 * @param return_type what the method returns
130 * @param arg_types what are the argument types
131 * @return method signature for given type(s).
132 */
133 public static String getMethodSignature( Type return_type, Type[] arg_types ) {
134 StringBuffer buf = new StringBuffer("(");
135 int length = (arg_types == null) ? 0 : arg_types.length;
136 for (int i = 0; i < length; i++) {
137 buf.append(arg_types[i].getSignature());
138 }
139 buf.append(')');
140 buf.append(return_type.getSignature());
141 return buf.toString();
142 }
143
144 private static ThreadLocal consumed_chars = new ThreadLocal() {
145
146 protected Object initialValue() {
147 return new Integer(0);
148 }
149 };//int consumed_chars=0; // Remember position in string, see getArgumentTypes
150
151
152 private static int unwrap( ThreadLocal tl ) {
153 return ((Integer) tl.get()).intValue();
154 }
155
156
157 private static void wrap( ThreadLocal tl, int value ) {
158 tl.set(new Integer(value));
159 }
160
161
162 /**
163 * Convert signature to a Type object.
164 * @param signature signature string such as Ljava/lang/String;
165 * @return type object
166 */
167 public static final Type getType( String signature ) throws StringIndexOutOfBoundsException {
168 byte type = Utility.typeOfSignature(signature);
169 if (type <= Constants.T_VOID) {
170 //corrected concurrent private static field acess
171 wrap(consumed_chars, 1);
172 return BasicType.getType(type);
173 } else if (type == Constants.T_ARRAY) {
174 int dim = 0;
175 do { // Count dimensions
176 dim++;
177 } while (signature.charAt(dim) == '[');
178 // Recurse, but just once, if the signature is ok
179 Type t = getType(signature.substring(dim));
180 //corrected concurrent private static field acess
181 // consumed_chars += dim; // update counter - is replaced by
182 int _temp = unwrap(consumed_chars) + dim;
183 wrap(consumed_chars, _temp);
184 return new ArrayType(t, dim);
185 } else { // type == T_REFERENCE
186 int index = signature.indexOf(';'); // Look for closing `;'
187 if (index < 0) {
188 throw new ClassFormatException("Invalid signature: " + signature);
189 }
190 //corrected concurrent private static field acess
191 wrap(consumed_chars, index + 1); // "Lblabla;" `L' and `;' are removed
192 return ObjectType.getInstance(signature.substring(1, index).replace('/', '.'));
193 }
194 }
195
196
197 /**
198 * Convert return value of a method (signature) to a Type object.
199 *
200 * @param signature signature string such as (Ljava/lang/String;)V
201 * @return return type
202 */
203 public static Type getReturnType( String signature ) {
204 try {
205 // Read return type after `)'
206 int index = signature.lastIndexOf(')') + 1;
207 return getType(signature.substring(index));
208 } catch (StringIndexOutOfBoundsException e) { // Should never occur
209 throw new ClassFormatException("Invalid method signature: " + signature);
210 }
211 }
212
213
214 /**
215 * Convert arguments of a method (signature) to an array of Type objects.
216 * @param signature signature string such as (Ljava/lang/String;)V
217 * @return array of argument types
218 */
219 public static Type[] getArgumentTypes( String signature ) {
220 List vec = new ArrayList();
221 int index;
222 Type[] types;
223 try { // Read all declarations between for `(' and `)'
224 if (signature.charAt(0) != '(') {
225 throw new ClassFormatException("Invalid method signature: " + signature);
226 }
227 index = 1; // current string position
228 while (signature.charAt(index) != ')') {
229 vec.add(getType(signature.substring(index)));
230 //corrected concurrent private static field acess
231 index += unwrap(consumed_chars); // update position
232 }
233 } catch (StringIndexOutOfBoundsException e) { // Should never occur
234 throw new ClassFormatException("Invalid method signature: " + signature);
235 }
236 types = new Type[vec.size()];
237 vec.toArray(types);
238 return types;
239 }
240
241
242 /** Convert runtime java.lang.Class to BCEL Type object.
243 * @param cl Java class
244 * @return corresponding Type object
245 */
246 public static Type getType( java.lang.Class cl ) {
247 if (cl == null) {
248 throw new IllegalArgumentException("Class must not be null");
249 }
250 /* That's an amzingly easy case, because getName() returns
251 * the signature. That's what we would have liked anyway.
252 */
253 if (cl.isArray()) {
254 return getType(cl.getName());
255 } else if (cl.isPrimitive()) {
256 if (cl == Integer.TYPE) {
257 return INT;
258 } else if (cl == Void.TYPE) {
259 return VOID;
260 } else if (cl == Double.TYPE) {
261 return DOUBLE;
262 } else if (cl == Float.TYPE) {
263 return FLOAT;
264 } else if (cl == Boolean.TYPE) {
265 return BOOLEAN;
266 } else if (cl == Byte.TYPE) {
267 return BYTE;
268 } else if (cl == Short.TYPE) {
269 return SHORT;
270 } else if (cl == Byte.TYPE) {
271 return BYTE;
272 } else if (cl == Long.TYPE) {
273 return LONG;
274 } else if (cl == Character.TYPE) {
275 return CHAR;
276 } else {
277 throw new IllegalStateException("Ooops, what primitive type is " + cl);
278 }
279 } else { // "Real" class
280 return ObjectType.getInstance(cl.getName());
281 }
282 }
283
284
285 /**
286 * Convert runtime java.lang.Class[] to BCEL Type objects.
287 * @param classes an array of runtime class objects
288 * @return array of corresponding Type objects
289 */
290 public static Type[] getTypes( java.lang.Class[] classes ) {
291 Type[] ret = new Type[classes.length];
292 for (int i = 0; i < ret.length; i++) {
293 ret[i] = getType(classes[i]);
294 }
295 return ret;
296 }
297
298
299 public static String getSignature( java.lang.reflect.Method meth ) {
300 StringBuffer sb = new StringBuffer("(");
301 Class[] params = meth.getParameterTypes(); // avoid clone
302 for (int j = 0; j < params.length; j++) {
303 sb.append(getType(params[j]).getSignature());
304 }
305 sb.append(")");
306 sb.append(getType(meth.getReturnType()).getSignature());
307 return sb.toString();
308 }
309 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/TypedInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Get the type associated with an instruction, int for ILOAD, or the type
20 * of the field of a PUTFIELD instruction, e.g..
21 *
22 * @version $Id: TypedInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24 */
25 public interface TypedInstruction {
26
27 public Type getType( ConstantPoolGen cpg );
28 }
+0
-29
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/UnconditionalBranch.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an instruction to perform an unconditional branch, i.e., GOTO, JSR.
20 *
21 * @version $Id: UnconditionalBranch.java 386056 2006-03-15 11:31:56Z tcurdt $
22 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23
24 * @see GOTO
25 * @see JSR
26 */
27 public interface UnconditionalBranch {
28 }
+0
-32
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/VariableLengthInstruction.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Denotes an instruction to be a variable length instruction, such as
20 * GOTO, JSR, LOOKUPSWITCH and TABLESWITCH.
21 *
22 * @version $Id: VariableLengthInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
25 * @see GOTO
26 * @see JSR
27 * @see LOOKUPSWITCH
28 * @see TABLESWITCH
29 */
30 public interface VariableLengthInstruction {
31 }
+0
-568
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/Visitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.generic;
17
18 /**
19 * Interface implementing the Visitor pattern programming style.
20 * I.e., a class that implements this interface can handle all types of
21 * instructions with the properly typed methods just by calling the accept()
22 * method.
23 *
24 * @version $Id: Visitor.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public interface Visitor {
28
29 public void visitStackInstruction( StackInstruction obj );
30
31
32 public void visitLocalVariableInstruction( LocalVariableInstruction obj );
33
34
35 public void visitBranchInstruction( BranchInstruction obj );
36
37
38 public void visitLoadClass( LoadClass obj );
39
40
41 public void visitFieldInstruction( FieldInstruction obj );
42
43
44 public void visitIfInstruction( IfInstruction obj );
45
46
47 public void visitConversionInstruction( ConversionInstruction obj );
48
49
50 public void visitPopInstruction( PopInstruction obj );
51
52
53 public void visitStoreInstruction( StoreInstruction obj );
54
55
56 public void visitTypedInstruction( TypedInstruction obj );
57
58
59 public void visitSelect( Select obj );
60
61
62 public void visitJsrInstruction( JsrInstruction obj );
63
64
65 public void visitGotoInstruction( GotoInstruction obj );
66
67
68 public void visitUnconditionalBranch( UnconditionalBranch obj );
69
70
71 public void visitPushInstruction( PushInstruction obj );
72
73
74 public void visitArithmeticInstruction( ArithmeticInstruction obj );
75
76
77 public void visitCPInstruction( CPInstruction obj );
78
79
80 public void visitInvokeInstruction( InvokeInstruction obj );
81
82
83 public void visitArrayInstruction( ArrayInstruction obj );
84
85
86 public void visitAllocationInstruction( AllocationInstruction obj );
87
88
89 public void visitReturnInstruction( ReturnInstruction obj );
90
91
92 public void visitFieldOrMethod( FieldOrMethod obj );
93
94
95 public void visitConstantPushInstruction( ConstantPushInstruction obj );
96
97
98 public void visitExceptionThrower( ExceptionThrower obj );
99
100
101 public void visitLoadInstruction( LoadInstruction obj );
102
103
104 public void visitVariableLengthInstruction( VariableLengthInstruction obj );
105
106
107 public void visitStackProducer( StackProducer obj );
108
109
110 public void visitStackConsumer( StackConsumer obj );
111
112
113 public void visitACONST_NULL( ACONST_NULL obj );
114
115
116 public void visitGETSTATIC( GETSTATIC obj );
117
118
119 public void visitIF_ICMPLT( IF_ICMPLT obj );
120
121
122 public void visitMONITOREXIT( MONITOREXIT obj );
123
124
125 public void visitIFLT( IFLT obj );
126
127
128 public void visitLSTORE( LSTORE obj );
129
130
131 public void visitPOP2( POP2 obj );
132
133
134 public void visitBASTORE( BASTORE obj );
135
136
137 public void visitISTORE( ISTORE obj );
138
139
140 public void visitCHECKCAST( CHECKCAST obj );
141
142
143 public void visitFCMPG( FCMPG obj );
144
145
146 public void visitI2F( I2F obj );
147
148
149 public void visitATHROW( ATHROW obj );
150
151
152 public void visitDCMPL( DCMPL obj );
153
154
155 public void visitARRAYLENGTH( ARRAYLENGTH obj );
156
157
158 public void visitDUP( DUP obj );
159
160
161 public void visitINVOKESTATIC( INVOKESTATIC obj );
162
163
164 public void visitLCONST( LCONST obj );
165
166
167 public void visitDREM( DREM obj );
168
169
170 public void visitIFGE( IFGE obj );
171
172
173 public void visitCALOAD( CALOAD obj );
174
175
176 public void visitLASTORE( LASTORE obj );
177
178
179 public void visitI2D( I2D obj );
180
181
182 public void visitDADD( DADD obj );
183
184
185 public void visitINVOKESPECIAL( INVOKESPECIAL obj );
186
187
188 public void visitIAND( IAND obj );
189
190
191 public void visitPUTFIELD( PUTFIELD obj );
192
193
194 public void visitILOAD( ILOAD obj );
195
196
197 public void visitDLOAD( DLOAD obj );
198
199
200 public void visitDCONST( DCONST obj );
201
202
203 public void visitNEW( NEW obj );
204
205
206 public void visitIFNULL( IFNULL obj );
207
208
209 public void visitLSUB( LSUB obj );
210
211
212 public void visitL2I( L2I obj );
213
214
215 public void visitISHR( ISHR obj );
216
217
218 public void visitTABLESWITCH( TABLESWITCH obj );
219
220
221 public void visitIINC( IINC obj );
222
223
224 public void visitDRETURN( DRETURN obj );
225
226
227 public void visitFSTORE( FSTORE obj );
228
229
230 public void visitDASTORE( DASTORE obj );
231
232
233 public void visitIALOAD( IALOAD obj );
234
235
236 public void visitDDIV( DDIV obj );
237
238
239 public void visitIF_ICMPGE( IF_ICMPGE obj );
240
241
242 public void visitLAND( LAND obj );
243
244
245 public void visitIDIV( IDIV obj );
246
247
248 public void visitLOR( LOR obj );
249
250
251 public void visitCASTORE( CASTORE obj );
252
253
254 public void visitFREM( FREM obj );
255
256
257 public void visitLDC( LDC obj );
258
259
260 public void visitBIPUSH( BIPUSH obj );
261
262
263 public void visitDSTORE( DSTORE obj );
264
265
266 public void visitF2L( F2L obj );
267
268
269 public void visitFMUL( FMUL obj );
270
271
272 public void visitLLOAD( LLOAD obj );
273
274
275 public void visitJSR( JSR obj );
276
277
278 public void visitFSUB( FSUB obj );
279
280
281 public void visitSASTORE( SASTORE obj );
282
283
284 public void visitALOAD( ALOAD obj );
285
286
287 public void visitDUP2_X2( DUP2_X2 obj );
288
289
290 public void visitRETURN( RETURN obj );
291
292
293 public void visitDALOAD( DALOAD obj );
294
295
296 public void visitSIPUSH( SIPUSH obj );
297
298
299 public void visitDSUB( DSUB obj );
300
301
302 public void visitL2F( L2F obj );
303
304
305 public void visitIF_ICMPGT( IF_ICMPGT obj );
306
307
308 public void visitF2D( F2D obj );
309
310
311 public void visitI2L( I2L obj );
312
313
314 public void visitIF_ACMPNE( IF_ACMPNE obj );
315
316
317 public void visitPOP( POP obj );
318
319
320 public void visitI2S( I2S obj );
321
322
323 public void visitIFEQ( IFEQ obj );
324
325
326 public void visitSWAP( SWAP obj );
327
328
329 public void visitIOR( IOR obj );
330
331
332 public void visitIREM( IREM obj );
333
334
335 public void visitIASTORE( IASTORE obj );
336
337
338 public void visitNEWARRAY( NEWARRAY obj );
339
340
341 public void visitINVOKEINTERFACE( INVOKEINTERFACE obj );
342
343
344 public void visitINEG( INEG obj );
345
346
347 public void visitLCMP( LCMP obj );
348
349
350 public void visitJSR_W( JSR_W obj );
351
352
353 public void visitMULTIANEWARRAY( MULTIANEWARRAY obj );
354
355
356 public void visitDUP_X2( DUP_X2 obj );
357
358
359 public void visitSALOAD( SALOAD obj );
360
361
362 public void visitIFNONNULL( IFNONNULL obj );
363
364
365 public void visitDMUL( DMUL obj );
366
367
368 public void visitIFNE( IFNE obj );
369
370
371 public void visitIF_ICMPLE( IF_ICMPLE obj );
372
373
374 public void visitLDC2_W( LDC2_W obj );
375
376
377 public void visitGETFIELD( GETFIELD obj );
378
379
380 public void visitLADD( LADD obj );
381
382
383 public void visitNOP( NOP obj );
384
385
386 public void visitFALOAD( FALOAD obj );
387
388
389 public void visitINSTANCEOF( INSTANCEOF obj );
390
391
392 public void visitIFLE( IFLE obj );
393
394
395 public void visitLXOR( LXOR obj );
396
397
398 public void visitLRETURN( LRETURN obj );
399
400
401 public void visitFCONST( FCONST obj );
402
403
404 public void visitIUSHR( IUSHR obj );
405
406
407 public void visitBALOAD( BALOAD obj );
408
409
410 public void visitDUP2( DUP2 obj );
411
412
413 public void visitIF_ACMPEQ( IF_ACMPEQ obj );
414
415
416 public void visitIMPDEP1( IMPDEP1 obj );
417
418
419 public void visitMONITORENTER( MONITORENTER obj );
420
421
422 public void visitLSHL( LSHL obj );
423
424
425 public void visitDCMPG( DCMPG obj );
426
427
428 public void visitD2L( D2L obj );
429
430
431 public void visitIMPDEP2( IMPDEP2 obj );
432
433
434 public void visitL2D( L2D obj );
435
436
437 public void visitRET( RET obj );
438
439
440 public void visitIFGT( IFGT obj );
441
442
443 public void visitIXOR( IXOR obj );
444
445
446 public void visitINVOKEVIRTUAL( INVOKEVIRTUAL obj );
447
448
449 public void visitFASTORE( FASTORE obj );
450
451
452 public void visitIRETURN( IRETURN obj );
453
454
455 public void visitIF_ICMPNE( IF_ICMPNE obj );
456
457
458 public void visitFLOAD( FLOAD obj );
459
460
461 public void visitLDIV( LDIV obj );
462
463
464 public void visitPUTSTATIC( PUTSTATIC obj );
465
466
467 public void visitAALOAD( AALOAD obj );
468
469
470 public void visitD2I( D2I obj );
471
472
473 public void visitIF_ICMPEQ( IF_ICMPEQ obj );
474
475
476 public void visitAASTORE( AASTORE obj );
477
478
479 public void visitARETURN( ARETURN obj );
480
481
482 public void visitDUP2_X1( DUP2_X1 obj );
483
484
485 public void visitFNEG( FNEG obj );
486
487
488 public void visitGOTO_W( GOTO_W obj );
489
490
491 public void visitD2F( D2F obj );
492
493
494 public void visitGOTO( GOTO obj );
495
496
497 public void visitISUB( ISUB obj );
498
499
500 public void visitF2I( F2I obj );
501
502
503 public void visitDNEG( DNEG obj );
504
505
506 public void visitICONST( ICONST obj );
507
508
509 public void visitFDIV( FDIV obj );
510
511
512 public void visitI2B( I2B obj );
513
514
515 public void visitLNEG( LNEG obj );
516
517
518 public void visitLREM( LREM obj );
519
520
521 public void visitIMUL( IMUL obj );
522
523
524 public void visitIADD( IADD obj );
525
526
527 public void visitLSHR( LSHR obj );
528
529
530 public void visitLOOKUPSWITCH( LOOKUPSWITCH obj );
531
532
533 public void visitDUP_X1( DUP_X1 obj );
534
535
536 public void visitFCMPL( FCMPL obj );
537
538
539 public void visitI2C( I2C obj );
540
541
542 public void visitLMUL( LMUL obj );
543
544
545 public void visitLUSHR( LUSHR obj );
546
547
548 public void visitISHL( ISHL obj );
549
550
551 public void visitLALOAD( LALOAD obj );
552
553
554 public void visitASTORE( ASTORE obj );
555
556
557 public void visitANEWARRAY( ANEWARRAY obj );
558
559
560 public void visitFRETURN( FRETURN obj );
561
562
563 public void visitFADD( FADD obj );
564
565
566 public void visitBREAKPOINT( BREAKPOINT obj );
567 }
+0
-16
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/generic/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 152690 2001-10-29 19:59:54Z jvanzyl $
5 -->
6 </head>
7 <body bgcolor="white">
8 <p>
9 This package contains the "generic" part of the
10 <a href="http://jakarta.apache.org/bcel/">Byte Code Engineering
11 Library</a>, i.e., classes to dynamically modify class objects and
12 byte code instructions.
13 </p>
14 </body>
15 </html>
+0
-17
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 371539 2006-01-23 14:08:00Z tcurdt $
5 -->
6 </head>
7 <body bgcolor="white">
8 <p>
9 This package contains basic classes for the
10 <a href="http://jakarta.apache.org/bcel/">Byte Code Engineering Library</a>
11 and constants defined by the
12 <a href="http://java.sun.com/docs/books/vmspec/html/VMSpecTOC.doc.html">
13 JVM specification</a>.
14 </p>
15 </body>
16 </html>
+0
-211
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/AttributeHTML.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.FileOutputStream;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import org.apache.bcel.classfile.Attribute;
22 import org.apache.bcel.classfile.Code;
23 import org.apache.bcel.classfile.CodeException;
24 import org.apache.bcel.classfile.ConstantPool;
25 import org.apache.bcel.classfile.ConstantUtf8;
26 import org.apache.bcel.classfile.ConstantValue;
27 import org.apache.bcel.classfile.ExceptionTable;
28 import org.apache.bcel.classfile.InnerClass;
29 import org.apache.bcel.classfile.InnerClasses;
30 import org.apache.bcel.classfile.LineNumber;
31 import org.apache.bcel.classfile.LineNumberTable;
32 import org.apache.bcel.classfile.LocalVariable;
33 import org.apache.bcel.classfile.LocalVariableTable;
34 import org.apache.bcel.classfile.SourceFile;
35 import org.apache.bcel.classfile.Utility;
36
37 /**
38 * Convert found attributes into HTML file.
39 *
40 * @version $Id: AttributeHTML.java 386056 2006-03-15 11:31:56Z tcurdt $
41 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
42 *
43 */
44 final class AttributeHTML implements org.apache.bcel.Constants {
45
46 private String class_name; // name of current class
47 private PrintWriter file; // file to write to
48 private int attr_count = 0;
49 private ConstantHTML constant_html;
50 private ConstantPool constant_pool;
51
52
53 AttributeHTML(String dir, String class_name, ConstantPool constant_pool,
54 ConstantHTML constant_html) throws IOException {
55 this.class_name = class_name;
56 this.constant_pool = constant_pool;
57 this.constant_html = constant_html;
58 file = new PrintWriter(new FileOutputStream(dir + class_name + "_attributes.html"));
59 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
60 }
61
62
63 private final String codeLink( int link, int method_number ) {
64 return "<A HREF=\"" + class_name + "_code.html#code" + method_number + "@" + link
65 + "\" TARGET=Code>" + link + "</A>";
66 }
67
68
69 final void close() {
70 file.println("</TABLE></BODY></HTML>");
71 file.close();
72 }
73
74
75 final void writeAttribute( Attribute attribute, String anchor ) throws IOException {
76 writeAttribute(attribute, anchor, 0);
77 }
78
79
80 final void writeAttribute( Attribute attribute, String anchor, int method_number )
81 throws IOException {
82 byte tag = attribute.getTag();
83 int index;
84 if (tag == ATTR_UNKNOWN) {
85 return;
86 }
87 attr_count++; // Increment number of attributes found so far
88 if (attr_count % 2 == 0) {
89 file.print("<TR BGCOLOR=\"#C0C0C0\"><TD>");
90 } else {
91 file.print("<TR BGCOLOR=\"#A0A0A0\"><TD>");
92 }
93 file.println("<H4><A NAME=\"" + anchor + "\">" + attr_count + " " + ATTRIBUTE_NAMES[tag]
94 + "</A></H4>");
95 /* Handle different attributes
96 */
97 switch (tag) {
98 case ATTR_CODE:
99 Code c = (Code) attribute;
100 // Some directly printable values
101 file.print("<UL><LI>Maximum stack size = " + c.getMaxStack()
102 + "</LI>\n<LI>Number of local variables = " + c.getMaxLocals()
103 + "</LI>\n<LI><A HREF=\"" + class_name + "_code.html#method"
104 + method_number + "\" TARGET=Code>Byte code</A></LI></UL>\n");
105 // Get handled exceptions and list them
106 CodeException[] ce = c.getExceptionTable();
107 int len = ce.length;
108 if (len > 0) {
109 file.print("<P><B>Exceptions handled</B><UL>");
110 for (int i = 0; i < len; i++) {
111 int catch_type = ce[i].getCatchType(); // Index in constant pool
112 file.print("<LI>");
113 if (catch_type != 0) {
114 file.print(constant_html.referenceConstant(catch_type)); // Create Link to _cp.html
115 } else {
116 file.print("Any Exception");
117 }
118 file.print("<BR>(Ranging from lines "
119 + codeLink(ce[i].getStartPC(), method_number) + " to "
120 + codeLink(ce[i].getEndPC(), method_number) + ", handled at line "
121 + codeLink(ce[i].getHandlerPC(), method_number) + ")</LI>");
122 }
123 file.print("</UL>");
124 }
125 break;
126 case ATTR_CONSTANT_VALUE:
127 index = ((ConstantValue) attribute).getConstantValueIndex();
128 // Reference _cp.html
129 file.print("<UL><LI><A HREF=\"" + class_name + "_cp.html#cp" + index
130 + "\" TARGET=\"ConstantPool\">Constant value index(" + index
131 + ")</A></UL>\n");
132 break;
133 case ATTR_SOURCE_FILE:
134 index = ((SourceFile) attribute).getSourceFileIndex();
135 // Reference _cp.html
136 file.print("<UL><LI><A HREF=\"" + class_name + "_cp.html#cp" + index
137 + "\" TARGET=\"ConstantPool\">Source file index(" + index + ")</A></UL>\n");
138 break;
139 case ATTR_EXCEPTIONS:
140 // List thrown exceptions
141 int[] indices = ((ExceptionTable) attribute).getExceptionIndexTable();
142 file.print("<UL>");
143 for (int i = 0; i < indices.length; i++) {
144 file.print("<LI><A HREF=\"" + class_name + "_cp.html#cp" + indices[i]
145 + "\" TARGET=\"ConstantPool\">Exception class index(" + indices[i]
146 + ")</A>\n");
147 }
148 file.print("</UL>\n");
149 break;
150 case ATTR_LINE_NUMBER_TABLE:
151 LineNumber[] line_numbers = ((LineNumberTable) attribute).getLineNumberTable();
152 // List line number pairs
153 file.print("<P>");
154 for (int i = 0; i < line_numbers.length; i++) {
155 file.print("(" + line_numbers[i].getStartPC() + ",&nbsp;"
156 + line_numbers[i].getLineNumber() + ")");
157 if (i < line_numbers.length - 1) {
158 file.print(", "); // breakable
159 }
160 }
161 break;
162 case ATTR_LOCAL_VARIABLE_TABLE:
163 LocalVariable[] vars = ((LocalVariableTable) attribute).getLocalVariableTable();
164 // List name, range and type
165 file.print("<UL>");
166 for (int i = 0; i < vars.length; i++) {
167 index = vars[i].getSignatureIndex();
168 String signature = ((ConstantUtf8) constant_pool.getConstant(index,
169 CONSTANT_Utf8)).getBytes();
170 signature = Utility.signatureToString(signature, false);
171 int start = vars[i].getStartPC();
172 int end = (start + vars[i].getLength());
173 file.println("<LI>" + Class2HTML.referenceType(signature) + "&nbsp;<B>"
174 + vars[i].getName() + "</B> in slot %" + vars[i].getIndex()
175 + "<BR>Valid from lines " + "<A HREF=\"" + class_name
176 + "_code.html#code" + method_number + "@" + start + "\" TARGET=Code>"
177 + start + "</A> to " + "<A HREF=\"" + class_name + "_code.html#code"
178 + method_number + "@" + end + "\" TARGET=Code>" + end + "</A></LI>");
179 }
180 file.print("</UL>\n");
181 break;
182 case ATTR_INNER_CLASSES:
183 InnerClass[] classes = ((InnerClasses) attribute).getInnerClasses();
184 // List inner classes
185 file.print("<UL>");
186 for (int i = 0; i < classes.length; i++) {
187 String name, access;
188 index = classes[i].getInnerNameIndex();
189 if (index > 0) {
190 name = ((ConstantUtf8) constant_pool.getConstant(index, CONSTANT_Utf8))
191 .getBytes();
192 } else {
193 name = "&lt;anonymous&gt;";
194 }
195 access = Utility.accessToString(classes[i].getInnerAccessFlags());
196 file.print("<LI><FONT COLOR=\"#FF0000\">" + access + "</FONT> "
197 + constant_html.referenceConstant(classes[i].getInnerClassIndex())
198 + " in&nbsp;class "
199 + constant_html.referenceConstant(classes[i].getOuterClassIndex())
200 + " named " + name + "</LI>\n");
201 }
202 file.print("</UL>\n");
203 break;
204 default: // Such as Unknown attribute or Deprecated
205 file.print("<P>" + attribute.toString());
206 }
207 file.println("</TD></TR>");
208 file.flush();
209 }
210 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/BCELComparator.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 /**
19 * Used for BCEL comparison strategy
20 *
21 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
22 * @version $Id: BCELComparator.java 410087 2006-05-29 12:12:19Z tcurdt $
23 * @since 5.2
24 */
25 public interface BCELComparator {
26
27 /**
28 * Compare two objects and return what THIS.equals(THAT) should return
29 *
30 * @param THIS
31 * @param THAT
32 * @return true if and only if THIS equals THAT
33 */
34 public boolean equals( Object THIS, Object THAT );
35
36
37 /**
38 * Return hashcode for THIS.hashCode()
39 *
40 * @param THIS
41 * @return hashcode for THIS.hashCode()
42 */
43 public int hashCode( Object THIS );
44 }
+0
-326
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/BCELFactory.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.PrintWriter;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Locale;
24 import java.util.Map;
25 import org.apache.bcel.Constants;
26 import org.apache.bcel.classfile.Utility;
27 import org.apache.bcel.generic.AllocationInstruction;
28 import org.apache.bcel.generic.ArrayInstruction;
29 import org.apache.bcel.generic.ArrayType;
30 import org.apache.bcel.generic.BranchHandle;
31 import org.apache.bcel.generic.BranchInstruction;
32 import org.apache.bcel.generic.CHECKCAST;
33 import org.apache.bcel.generic.CPInstruction;
34 import org.apache.bcel.generic.CodeExceptionGen;
35 import org.apache.bcel.generic.ConstantPoolGen;
36 import org.apache.bcel.generic.ConstantPushInstruction;
37 import org.apache.bcel.generic.EmptyVisitor;
38 import org.apache.bcel.generic.FieldInstruction;
39 import org.apache.bcel.generic.IINC;
40 import org.apache.bcel.generic.INSTANCEOF;
41 import org.apache.bcel.generic.Instruction;
42 import org.apache.bcel.generic.InstructionConstants;
43 import org.apache.bcel.generic.InstructionHandle;
44 import org.apache.bcel.generic.InvokeInstruction;
45 import org.apache.bcel.generic.LDC;
46 import org.apache.bcel.generic.LDC2_W;
47 import org.apache.bcel.generic.LocalVariableInstruction;
48 import org.apache.bcel.generic.MULTIANEWARRAY;
49 import org.apache.bcel.generic.MethodGen;
50 import org.apache.bcel.generic.NEWARRAY;
51 import org.apache.bcel.generic.ObjectType;
52 import org.apache.bcel.generic.RET;
53 import org.apache.bcel.generic.ReturnInstruction;
54 import org.apache.bcel.generic.Select;
55 import org.apache.bcel.generic.Type;
56
57 /**
58 * Factory creates il.append() statements, and sets instruction targets.
59 * A helper class for BCELifier.
60 *
61 * @see BCELifier
62 * @version $Id: BCELFactory.java 410087 2006-05-29 12:12:19Z tcurdt $
63 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
64 */
65 class BCELFactory extends EmptyVisitor {
66
67 private MethodGen _mg;
68 private PrintWriter _out;
69 private ConstantPoolGen _cp;
70
71
72 BCELFactory(MethodGen mg, PrintWriter out) {
73 _mg = mg;
74 _cp = mg.getConstantPool();
75 _out = out;
76 }
77
78 private Map branch_map = new HashMap(); // Map<Instruction, InstructionHandle>
79
80
81 public void start() {
82 if (!_mg.isAbstract() && !_mg.isNative()) {
83 for (InstructionHandle ih = _mg.getInstructionList().getStart(); ih != null; ih = ih
84 .getNext()) {
85 Instruction i = ih.getInstruction();
86 if (i instanceof BranchInstruction) {
87 branch_map.put(i, ih); // memorize container
88 }
89 if (ih.hasTargeters()) {
90 if (i instanceof BranchInstruction) {
91 _out.println(" InstructionHandle ih_" + ih.getPosition() + ";");
92 } else {
93 _out.print(" InstructionHandle ih_" + ih.getPosition() + " = ");
94 }
95 } else {
96 _out.print(" ");
97 }
98 if (!visitInstruction(i)) {
99 i.accept(this);
100 }
101 }
102 updateBranchTargets();
103 updateExceptionHandlers();
104 }
105 }
106
107
108 private boolean visitInstruction( Instruction i ) {
109 short opcode = i.getOpcode();
110 if ((InstructionConstants.INSTRUCTIONS[opcode] != null)
111 && !(i instanceof ConstantPushInstruction) && !(i instanceof ReturnInstruction)) { // Handled below
112 _out.println("il.append(InstructionConstants."
113 + i.getName().toUpperCase(Locale.ENGLISH) + ");");
114 return true;
115 }
116 return false;
117 }
118
119
120 public void visitLocalVariableInstruction( LocalVariableInstruction i ) {
121 short opcode = i.getOpcode();
122 Type type = i.getType(_cp);
123 if (opcode == Constants.IINC) {
124 _out.println("il.append(new IINC(" + i.getIndex() + ", " + ((IINC) i).getIncrement()
125 + "));");
126 } else {
127 String kind = (opcode < Constants.ISTORE) ? "Load" : "Store";
128 _out.println("il.append(_factory.create" + kind + "(" + BCELifier.printType(type)
129 + ", " + i.getIndex() + "));");
130 }
131 }
132
133
134 public void visitArrayInstruction( ArrayInstruction i ) {
135 short opcode = i.getOpcode();
136 Type type = i.getType(_cp);
137 String kind = (opcode < Constants.IASTORE) ? "Load" : "Store";
138 _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type)
139 + "));");
140 }
141
142
143 public void visitFieldInstruction( FieldInstruction i ) {
144 short opcode = i.getOpcode();
145 String class_name = i.getClassName(_cp);
146 String field_name = i.getFieldName(_cp);
147 Type type = i.getFieldType(_cp);
148 _out.println("il.append(_factory.createFieldAccess(\"" + class_name + "\", \"" + field_name
149 + "\", " + BCELifier.printType(type) + ", " + "Constants."
150 + Constants.OPCODE_NAMES[opcode].toUpperCase(Locale.ENGLISH) + "));");
151 }
152
153
154 public void visitInvokeInstruction( InvokeInstruction i ) {
155 short opcode = i.getOpcode();
156 String class_name = i.getClassName(_cp);
157 String method_name = i.getMethodName(_cp);
158 Type type = i.getReturnType(_cp);
159 Type[] arg_types = i.getArgumentTypes(_cp);
160 _out.println("il.append(_factory.createInvoke(\"" + class_name + "\", \"" + method_name
161 + "\", " + BCELifier.printType(type) + ", "
162 + BCELifier.printArgumentTypes(arg_types) + ", " + "Constants."
163 + Constants.OPCODE_NAMES[opcode].toUpperCase(Locale.ENGLISH) + "));");
164 }
165
166
167 public void visitAllocationInstruction( AllocationInstruction i ) {
168 Type type;
169 if (i instanceof CPInstruction) {
170 type = ((CPInstruction) i).getType(_cp);
171 } else {
172 type = ((NEWARRAY) i).getType();
173 }
174 short opcode = ((Instruction) i).getOpcode();
175 int dim = 1;
176 switch (opcode) {
177 case Constants.NEW:
178 _out.println("il.append(_factory.createNew(\"" + ((ObjectType) type).getClassName()
179 + "\"));");
180 break;
181 case Constants.MULTIANEWARRAY:
182 dim = ((MULTIANEWARRAY) i).getDimensions();
183 case Constants.ANEWARRAY:
184 case Constants.NEWARRAY:
185 if (type instanceof ArrayType) {
186 type = ((ArrayType) type).getBasicType();
187 }
188 _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type)
189 + ", (short) " + dim + "));");
190 break;
191 default:
192 throw new RuntimeException("Oops: " + opcode);
193 }
194 }
195
196
197 private void createConstant( Object value ) {
198 String embed = value.toString();
199 if (value instanceof String) {
200 embed = '"' + Utility.convertString(value.toString()) + '"';
201 } else if (value instanceof Character) {
202 embed = "(char)0x" + Integer.toHexString(((Character) value).charValue());
203 }
204 _out.println("il.append(new PUSH(_cp, " + embed + "));");
205 }
206
207
208 public void visitLDC( LDC i ) {
209 createConstant(i.getValue(_cp));
210 }
211
212
213 public void visitLDC2_W( LDC2_W i ) {
214 createConstant(i.getValue(_cp));
215 }
216
217
218 public void visitConstantPushInstruction( ConstantPushInstruction i ) {
219 createConstant(i.getValue());
220 }
221
222
223 public void visitINSTANCEOF( INSTANCEOF i ) {
224 Type type = i.getType(_cp);
225 _out.println("il.append(new INSTANCEOF(_cp.addClass(" + BCELifier.printType(type) + ")));");
226 }
227
228
229 public void visitCHECKCAST( CHECKCAST i ) {
230 Type type = i.getType(_cp);
231 _out.println("il.append(_factory.createCheckCast(" + BCELifier.printType(type) + "));");
232 }
233
234
235 public void visitReturnInstruction( ReturnInstruction i ) {
236 Type type = i.getType(_cp);
237 _out.println("il.append(_factory.createReturn(" + BCELifier.printType(type) + "));");
238 }
239
240 // Memorize BranchInstructions that need an update
241 private List branches = new ArrayList();
242
243
244 public void visitBranchInstruction( BranchInstruction bi ) {
245 BranchHandle bh = (BranchHandle) branch_map.get(bi);
246 int pos = bh.getPosition();
247 String name = bi.getName() + "_" + pos;
248 if (bi instanceof Select) {
249 Select s = (Select) bi;
250 branches.add(bi);
251 StringBuffer args = new StringBuffer("new int[] { ");
252 int[] matchs = s.getMatchs();
253 for (int i = 0; i < matchs.length; i++) {
254 args.append(matchs[i]);
255 if (i < matchs.length - 1) {
256 args.append(", ");
257 }
258 }
259 args.append(" }");
260 _out.print("Select " + name + " = new " + bi.getName().toUpperCase(Locale.ENGLISH)
261 + "(" + args + ", new InstructionHandle[] { ");
262 for (int i = 0; i < matchs.length; i++) {
263 _out.print("null");
264 if (i < matchs.length - 1) {
265 _out.print(", ");
266 }
267 }
268 _out.println(" }, null);");
269 } else {
270 int t_pos = bh.getTarget().getPosition();
271 String target;
272 if (pos > t_pos) {
273 target = "ih_" + t_pos;
274 } else {
275 branches.add(bi);
276 target = "null";
277 }
278 _out.println(" BranchInstruction " + name + " = _factory.createBranchInstruction("
279 + "Constants." + bi.getName().toUpperCase(Locale.ENGLISH) + ", " + target
280 + ");");
281 }
282 if (bh.hasTargeters()) {
283 _out.println(" ih_" + pos + " = il.append(" + name + ");");
284 } else {
285 _out.println(" il.append(" + name + ");");
286 }
287 }
288
289
290 public void visitRET( RET i ) {
291 _out.println("il.append(new RET(" + i.getIndex() + ")));");
292 }
293
294
295 private void updateBranchTargets() {
296 for (Iterator i = branches.iterator(); i.hasNext();) {
297 BranchInstruction bi = (BranchInstruction) i.next();
298 BranchHandle bh = (BranchHandle) branch_map.get(bi);
299 int pos = bh.getPosition();
300 String name = bi.getName() + "_" + pos;
301 int t_pos = bh.getTarget().getPosition();
302 _out.println(" " + name + ".setTarget(ih_" + t_pos + ");");
303 if (bi instanceof Select) {
304 InstructionHandle[] ihs = ((Select) bi).getTargets();
305 for (int j = 0; j < ihs.length; j++) {
306 t_pos = ihs[j].getPosition();
307 _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");");
308 }
309 }
310 }
311 }
312
313
314 private void updateExceptionHandlers() {
315 CodeExceptionGen[] handlers = _mg.getExceptionHandlers();
316 for (int i = 0; i < handlers.length; i++) {
317 CodeExceptionGen h = handlers[i];
318 String type = (h.getCatchType() == null) ? "null" : BCELifier.printType(h
319 .getCatchType());
320 _out.println(" method.addExceptionHandler(" + "ih_" + h.getStartPC().getPosition()
321 + ", " + "ih_" + h.getEndPC().getPosition() + ", " + "ih_"
322 + h.getHandlerPC().getPosition() + ", " + type + ");");
323 }
324 }
325 }
+0
-268
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/BCELifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.OutputStream;
19 import java.io.PrintWriter;
20 import java.util.Locale;
21 import org.apache.bcel.Constants;
22 import org.apache.bcel.Repository;
23 import org.apache.bcel.classfile.ClassParser;
24 import org.apache.bcel.classfile.ConstantValue;
25 import org.apache.bcel.classfile.Field;
26 import org.apache.bcel.classfile.JavaClass;
27 import org.apache.bcel.classfile.Method;
28 import org.apache.bcel.classfile.Utility;
29 import org.apache.bcel.generic.ArrayType;
30 import org.apache.bcel.generic.ConstantPoolGen;
31 import org.apache.bcel.generic.MethodGen;
32 import org.apache.bcel.generic.Type;
33
34 /**
35 * This class takes a given JavaClass object and converts it to a
36 * Java program that creates that very class using BCEL. This
37 * gives new users of BCEL a useful example showing how things
38 * are done with BCEL. It does not cover all features of BCEL,
39 * but tries to mimic hand-written code as close as possible.
40 *
41 * @version $Id: BCELifier.java 394939 2006-04-18 13:23:49Z tcurdt $
42 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
43 */
44 public class BCELifier extends org.apache.bcel.classfile.EmptyVisitor {
45
46 private static final int FLAG_FOR_UNKNOWN = -1;
47 private static final int FLAG_FOR_CLASS = 0;
48 private static final int FLAG_FOR_METHOD = 1;
49 private JavaClass _clazz;
50 private PrintWriter _out;
51 private ConstantPoolGen _cp;
52
53
54 /** @param clazz Java class to "decompile"
55 * @param out where to output Java program
56 */
57 public BCELifier(JavaClass clazz, OutputStream out) {
58 _clazz = clazz;
59 _out = new PrintWriter(out);
60 _cp = new ConstantPoolGen(_clazz.getConstantPool());
61 }
62
63
64 /** Start Java code generation
65 */
66 public void start() {
67 visitJavaClass(_clazz);
68 _out.flush();
69 }
70
71
72 public void visitJavaClass( JavaClass clazz ) {
73 String class_name = clazz.getClassName();
74 String super_name = clazz.getSuperclassName();
75 String package_name = clazz.getPackageName();
76 String inter = Utility.printArray(clazz.getInterfaceNames(), false, true);
77 if (!"".equals(package_name)) {
78 class_name = class_name.substring(package_name.length() + 1);
79 _out.println("package " + package_name + ";");
80 _out.println();
81 }
82 _out.println("import org.apache.bcel.generic.*;");
83 _out.println("import org.apache.bcel.classfile.*;");
84 _out.println("import org.apache.bcel.*;");
85 _out.println("import java.io.*;");
86 _out.println();
87 _out.println("public class " + class_name + "Creator implements Constants {");
88 _out.println(" private InstructionFactory _factory;");
89 _out.println(" private ConstantPoolGen _cp;");
90 _out.println(" private ClassGen _cg;");
91 _out.println();
92 _out.println(" public " + class_name + "Creator() {");
93 _out.println(" _cg = new ClassGen(\""
94 + (("".equals(package_name)) ? class_name : package_name + "." + class_name)
95 + "\", \"" + super_name + "\", " + "\"" + clazz.getSourceFileName() + "\", "
96 + printFlags(clazz.getAccessFlags(), FLAG_FOR_CLASS) + ", " + "new String[] { "
97 + inter + " });");
98 _out.println();
99 _out.println(" _cp = _cg.getConstantPool();");
100 _out.println(" _factory = new InstructionFactory(_cg, _cp);");
101 _out.println(" }");
102 _out.println();
103 printCreate();
104 Field[] fields = clazz.getFields();
105 if (fields.length > 0) {
106 _out.println(" private void createFields() {");
107 _out.println(" FieldGen field;");
108 for (int i = 0; i < fields.length; i++) {
109 fields[i].accept(this);
110 }
111 _out.println(" }");
112 _out.println();
113 }
114 Method[] methods = clazz.getMethods();
115 for (int i = 0; i < methods.length; i++) {
116 _out.println(" private void createMethod_" + i + "() {");
117 methods[i].accept(this);
118 _out.println(" }");
119 _out.println();
120 }
121 printMain();
122 _out.println("}");
123 }
124
125
126 private void printCreate() {
127 _out.println(" public void create(OutputStream out) throws IOException {");
128 Field[] fields = _clazz.getFields();
129 if (fields.length > 0) {
130 _out.println(" createFields();");
131 }
132 Method[] methods = _clazz.getMethods();
133 for (int i = 0; i < methods.length; i++) {
134 _out.println(" createMethod_" + i + "();");
135 }
136 _out.println(" _cg.getJavaClass().dump(out);");
137 _out.println(" }");
138 _out.println();
139 }
140
141
142 private void printMain() {
143 String class_name = _clazz.getClassName();
144 _out.println(" public static void main(String[] args) throws Exception {");
145 _out.println(" " + class_name + "Creator creator = new " + class_name + "Creator();");
146 _out.println(" creator.create(new FileOutputStream(\"" + class_name + ".class\"));");
147 _out.println(" }");
148 }
149
150
151 public void visitField( Field field ) {
152 _out.println();
153 _out.println(" field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", "
154 + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);");
155 ConstantValue cv = field.getConstantValue();
156 if (cv != null) {
157 String value = cv.toString();
158 _out.println(" field.setInitValue(" + value + ")");
159 }
160 _out.println(" _cg.addField(field.getField());");
161 }
162
163
164 public void visitMethod( Method method ) {
165 MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);
166 Type result_type = mg.getReturnType();
167 Type[] arg_types = mg.getArgumentTypes();
168 _out.println(" InstructionList il = new InstructionList();");
169 _out.println(" MethodGen method = new MethodGen("
170 + printFlags(method.getAccessFlags(), FLAG_FOR_METHOD) + ", "
171 + printType(result_type) + ", " + printArgumentTypes(arg_types) + ", "
172 + "new String[] { " + Utility.printArray(mg.getArgumentNames(), false, true)
173 + " }, \"" + method.getName() + "\", \"" + _clazz.getClassName() + "\", il, _cp);");
174 _out.println();
175 BCELFactory factory = new BCELFactory(mg, _out);
176 factory.start();
177 _out.println(" method.setMaxStack();");
178 _out.println(" method.setMaxLocals();");
179 _out.println(" _cg.addMethod(method.getMethod());");
180 _out.println(" il.dispose();");
181 }
182
183
184 static String printFlags( int flags ) {
185 return printFlags(flags, FLAG_FOR_UNKNOWN);
186 }
187
188
189 static String printFlags( int flags, int reason ) {
190 if (flags == 0) {
191 return "0";
192 }
193 StringBuffer buf = new StringBuffer();
194 for (int i = 0, pow = 1; pow <= Constants.MAX_ACC_FLAG; i++) {
195 if ((flags & pow) != 0) {
196 if ((pow == Constants.ACC_SYNCHRONIZED) && (reason == FLAG_FOR_CLASS)) {
197 buf.append("ACC_SUPER | ");
198 } else if ((pow == Constants.ACC_VOLATILE) && (reason == FLAG_FOR_METHOD)) {
199 buf.append("ACC_BRIDGE | ");
200 } else if ((pow == Constants.ACC_TRANSIENT) && (reason == FLAG_FOR_METHOD)) {
201 buf.append("ACC_VARARGS | ");
202 } else {
203 buf.append("ACC_")
204 .append(Constants.ACCESS_NAMES[i].toUpperCase(Locale.ENGLISH)).append(
205 " | ");
206 }
207 }
208 pow <<= 1;
209 }
210 String str = buf.toString();
211 return str.substring(0, str.length() - 3);
212 }
213
214
215 static String printArgumentTypes( Type[] arg_types ) {
216 if (arg_types.length == 0) {
217 return "Type.NO_ARGS";
218 }
219 StringBuffer args = new StringBuffer();
220 for (int i = 0; i < arg_types.length; i++) {
221 args.append(printType(arg_types[i]));
222 if (i < arg_types.length - 1) {
223 args.append(", ");
224 }
225 }
226 return "new Type[] { " + args.toString() + " }";
227 }
228
229
230 static String printType( Type type ) {
231 return printType(type.getSignature());
232 }
233
234
235 static String printType( String signature ) {
236 Type type = Type.getType(signature);
237 byte t = type.getType();
238 if (t <= Constants.T_VOID) {
239 return "Type." + Constants.TYPE_NAMES[t].toUpperCase(Locale.ENGLISH);
240 } else if (type.toString().equals("java.lang.String")) {
241 return "Type.STRING";
242 } else if (type.toString().equals("java.lang.Object")) {
243 return "Type.OBJECT";
244 } else if (type.toString().equals("java.lang.StringBuffer")) {
245 return "Type.STRINGBUFFER";
246 } else if (type instanceof ArrayType) {
247 ArrayType at = (ArrayType) type;
248 return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions()
249 + ")";
250 } else {
251 return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
252 }
253 }
254
255
256 /** Default main method
257 */
258 public static void main( String[] argv ) throws Exception {
259 JavaClass java_class;
260 String name = argv[0];
261 if ((java_class = Repository.lookupClass(name)) == null) {
262 java_class = new ClassParser(name).parse(); // May throw IOException
263 }
264 BCELifier bcelifier = new BCELifier(java_class, System.out);
265 bcelifier.start();
266 }
267 }
+0
-68
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ByteSequence.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.DataInputStream;
20
21 /**
22 * Utility class that implements a sequence of bytes which can be read
23 * via the `readByte()' method. This is used to implement a wrapper for the
24 * Java byte code stream to gain some more readability.
25 *
26 * @version $Id: ByteSequence.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 */
29 public final class ByteSequence extends DataInputStream {
30
31 private ByteArrayStream byte_stream;
32
33
34 public ByteSequence(byte[] bytes) {
35 super(new ByteArrayStream(bytes));
36 byte_stream = (ByteArrayStream) in;
37 }
38
39
40 public final int getIndex() {
41 return byte_stream.getPosition();
42 }
43
44
45 final void unreadByte() {
46 byte_stream.unreadByte();
47 }
48
49 private static final class ByteArrayStream extends ByteArrayInputStream {
50
51 ByteArrayStream(byte[] bytes) {
52 super(bytes);
53 }
54
55
56 final int getPosition() {
57 return pos;
58 } // is protected in ByteArrayInputStream
59
60
61 final void unreadByte() {
62 if (pos > 0) {
63 pos--;
64 }
65 }
66 }
67 }
+0
-231
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/Class2HTML.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.File;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import org.apache.bcel.Constants;
23 import org.apache.bcel.classfile.Attribute;
24 import org.apache.bcel.classfile.ClassParser;
25 import org.apache.bcel.classfile.ConstantPool;
26 import org.apache.bcel.classfile.JavaClass;
27 import org.apache.bcel.classfile.Method;
28 import org.apache.bcel.classfile.Utility;
29
30 /**
31 * Read class file(s) and convert them into HTML files.
32 *
33 * Given a JavaClass object "class" that is in package "package" five files
34 * will be created in the specified directory.
35 *
36 * <OL>
37 * <LI> "package"."class".html as the main file which defines the frames for
38 * the following subfiles.
39 * <LI> "package"."class"_attributes.html contains all (known) attributes found in the file
40 * <LI> "package"."class"_cp.html contains the constant pool
41 * <LI> "package"."class"_code.html contains the byte code
42 * <LI> "package"."class"_methods.html contains references to all methods and fields of the class
43 * </OL>
44 *
45 * All subfiles reference each other appropiately, e.g. clicking on a
46 * method in the Method's frame will jump to the appropiate method in
47 * the Code frame.
48 *
49 * @version $Id: Class2HTML.java 386056 2006-03-15 11:31:56Z tcurdt $
50 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
51 */
52 public class Class2HTML implements Constants {
53
54 private JavaClass java_class; // current class object
55 private String dir;
56 private static String class_package; // name of package, unclean to make it static, but ...
57 private static String class_name; // name of current class, dito
58 private static ConstantPool constant_pool;
59
60
61 /**
62 * Write contents of the given JavaClass into HTML files.
63 *
64 * @param java_class The class to write
65 * @param dir The directory to put the files in
66 */
67 public Class2HTML(JavaClass java_class, String dir) throws IOException {
68 Method[] methods = java_class.getMethods();
69 this.java_class = java_class;
70 this.dir = dir;
71 class_name = java_class.getClassName(); // Remember full name
72 constant_pool = java_class.getConstantPool();
73 // Get package name by tacking off everything after the last `.'
74 int index = class_name.lastIndexOf('.');
75 if (index > -1) {
76 class_package = class_name.substring(0, index);
77 } else {
78 class_package = ""; // default package
79 }
80 ConstantHTML constant_html = new ConstantHTML(dir, class_name, class_package, methods,
81 constant_pool);
82 /* Attributes can't be written in one step, so we just open a file
83 * which will be written consequently.
84 */
85 AttributeHTML attribute_html = new AttributeHTML(dir, class_name, constant_pool,
86 constant_html);
87 MethodHTML method_html = new MethodHTML(dir, class_name, methods, java_class.getFields(),
88 constant_html, attribute_html);
89 // Write main file (with frames, yuk)
90 writeMainHTML(attribute_html);
91 new CodeHTML(dir, class_name, methods, constant_pool, constant_html);
92 attribute_html.close();
93 }
94
95
96 public static void main( String argv[] ) {
97 String[] file_name = new String[argv.length];
98 int files = 0;
99 ClassParser parser = null;
100 JavaClass java_class = null;
101 String zip_file = null;
102 char sep = System.getProperty("file.separator").toCharArray()[0];
103 String dir = "." + sep; // Where to store HTML files
104 try {
105 /* Parse command line arguments.
106 */
107 for (int i = 0; i < argv.length; i++) {
108 if (argv[i].charAt(0) == '-') { // command line switch
109 if (argv[i].equals("-d")) { // Specify target directory, default `.´
110 dir = argv[++i];
111 if (!dir.endsWith("" + sep)) {
112 dir = dir + sep;
113 }
114 new File(dir).mkdirs(); // Create target directory if necessary
115 } else if (argv[i].equals("-zip")) {
116 zip_file = argv[++i];
117 } else {
118 System.out.println("Unknown option " + argv[i]);
119 }
120 } else {
121 file_name[files++] = argv[i];
122 }
123 }
124 if (files == 0) {
125 System.err.println("Class2HTML: No input files specified.");
126 } else { // Loop through files ...
127 for (int i = 0; i < files; i++) {
128 System.out.print("Processing " + file_name[i] + "...");
129 if (zip_file == null) {
130 parser = new ClassParser(file_name[i]); // Create parser object from file
131 } else {
132 parser = new ClassParser(zip_file, file_name[i]); // Create parser object from zip file
133 }
134 java_class = parser.parse();
135 new Class2HTML(java_class, dir);
136 System.out.println("Done.");
137 }
138 }
139 } catch (Exception e) {
140 System.out.println(e);
141 e.printStackTrace(System.out);
142 }
143 }
144
145
146 /**
147 * Utility method that converts a class reference in the constant pool,
148 * i.e., an index to a string.
149 */
150 static String referenceClass( int index ) {
151 String str = constant_pool.getConstantString(index, CONSTANT_Class);
152 str = Utility.compactClassName(str);
153 str = Utility.compactClassName(str, class_package + ".", true);
154 return "<A HREF=\"" + class_name + "_cp.html#cp" + index + "\" TARGET=ConstantPool>" + str
155 + "</A>";
156 }
157
158
159 static final String referenceType( String type ) {
160 String short_type = Utility.compactClassName(type);
161 short_type = Utility.compactClassName(short_type, class_package + ".", true);
162 int index = type.indexOf('['); // Type is an array?
163 String base_type = type;
164 if (index > -1) {
165 base_type = type.substring(0, index); // Tack of the `['
166 }
167 // test for basic type
168 if (base_type.equals("int") || base_type.equals("short") || base_type.equals("boolean")
169 || base_type.equals("void") || base_type.equals("char") || base_type.equals("byte")
170 || base_type.equals("long") || base_type.equals("double")
171 || base_type.equals("float")) {
172 return "<FONT COLOR=\"#00FF00\">" + type + "</FONT>";
173 } else {
174 return "<A HREF=\"" + base_type + ".html\" TARGET=_top>" + short_type + "</A>";
175 }
176 }
177
178
179 static String toHTML( String str ) {
180 StringBuffer buf = new StringBuffer();
181 try { // Filter any characters HTML doesn't like such as < and > in particular
182 for (int i = 0; i < str.length(); i++) {
183 char ch;
184 switch (ch = str.charAt(i)) {
185 case '<':
186 buf.append("&lt;");
187 break;
188 case '>':
189 buf.append("&gt;");
190 break;
191 case '\n':
192 buf.append("\\n");
193 break;
194 case '\r':
195 buf.append("\\r");
196 break;
197 default:
198 buf.append(ch);
199 }
200 }
201 } catch (StringIndexOutOfBoundsException e) {
202 } // Never occurs
203 return buf.toString();
204 }
205
206
207 private void writeMainHTML( AttributeHTML attribute_html ) throws IOException {
208 PrintWriter file = new PrintWriter(new FileOutputStream(dir + class_name + ".html"));
209 Attribute[] attributes = java_class.getAttributes();
210 file.println("<HTML>\n" + "<HEAD><TITLE>Documentation for " + class_name + "</TITLE>"
211 + "</HEAD>\n" + "<FRAMESET BORDER=1 cols=\"30%,*\">\n"
212 + "<FRAMESET BORDER=1 rows=\"80%,*\">\n" + "<FRAME NAME=\"ConstantPool\" SRC=\""
213 + class_name + "_cp.html" + "\"\n MARGINWIDTH=\"0\" "
214 + "MARGINHEIGHT=\"0\" FRAMEBORDER=\"1\" SCROLLING=\"AUTO\">\n"
215 + "<FRAME NAME=\"Attributes\" SRC=\"" + class_name + "_attributes.html"
216 + "\"\n MARGINWIDTH=\"0\" "
217 + "MARGINHEIGHT=\"0\" FRAMEBORDER=\"1\" SCROLLING=\"AUTO\">\n" + "</FRAMESET>\n"
218 + "<FRAMESET BORDER=1 rows=\"80%,*\">\n" + "<FRAME NAME=\"Code\" SRC=\""
219 + class_name + "_code.html\"\n MARGINWIDTH=0 "
220 + "MARGINHEIGHT=0 FRAMEBORDER=1 SCROLLING=\"AUTO\">\n"
221 + "<FRAME NAME=\"Methods\" SRC=\"" + class_name
222 + "_methods.html\"\n MARGINWIDTH=0 "
223 + "MARGINHEIGHT=0 FRAMEBORDER=1 SCROLLING=\"AUTO\">\n"
224 + "</FRAMESET></FRAMESET></HTML>");
225 file.close();
226 for (int i = 0; i < attributes.length; i++) {
227 attribute_html.writeAttribute(attributes[i], "class" + i);
228 }
229 }
230 }
+0
-184
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassLoader.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.ByteArrayInputStream;
19 import java.util.Hashtable;
20 import org.apache.bcel.Constants;
21 import org.apache.bcel.classfile.ClassParser;
22 import org.apache.bcel.classfile.ConstantClass;
23 import org.apache.bcel.classfile.ConstantPool;
24 import org.apache.bcel.classfile.ConstantUtf8;
25 import org.apache.bcel.classfile.JavaClass;
26 import org.apache.bcel.classfile.Utility;
27
28 /**
29 * <p>Drop in replacement for the standard class loader of the JVM. You can use it
30 * in conjunction with the JavaWrapper to dynamically modify/create classes
31 * as they're requested.</p>
32 *
33 * <p>This class loader recognizes special requests in a distinct
34 * format, i.e., when the name of the requested class contains with
35 * "$$BCEL$$" it calls the createClass() method with that name
36 * (everything bevor the $$BCEL$$ is considered to be the package
37 * name. You can subclass the class loader and override that
38 * method. "Normal" classes class can be modified by overriding the
39 * modifyClass() method which is called just before defineClass().</p>
40 *
41 * <p>There may be a number of packages where you have to use the
42 * default class loader (which may also be faster). You can define the
43 * set of packages where to use the system class loader in the
44 * constructor. The default value contains "java.", "sun.",
45 * "javax."</p>
46 *
47 * @version $Id: ClassLoader.java 386056 2006-03-15 11:31:56Z tcurdt $
48 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
49 * @see JavaWrapper
50 * @see ClassPath
51 */
52 public class ClassLoader extends java.lang.ClassLoader {
53
54 public static final String[] DEFAULT_IGNORED_PACKAGES = {
55 "java.", "javax.", "sun."
56 };
57 private Hashtable classes = new Hashtable(); // Hashtable is synchronized thus thread-safe
58 private String[] ignored_packages;
59 private Repository repository = SyntheticRepository.getInstance();
60
61
62 /** Ignored packages are by default ( "java.", "sun.",
63 * "javax."), i.e. loaded by system class loader
64 */
65 public ClassLoader() {
66 this(DEFAULT_IGNORED_PACKAGES);
67 }
68
69
70 /** @param deferTo delegate class loader to use for ignored packages
71 */
72 public ClassLoader(java.lang.ClassLoader deferTo) {
73 super(deferTo);
74 this.ignored_packages = DEFAULT_IGNORED_PACKAGES;
75 this.repository = new ClassLoaderRepository(deferTo);
76 }
77
78
79 /** @param ignored_packages classes contained in these packages will be loaded
80 * with the system class loader
81 */
82 public ClassLoader(String[] ignored_packages) {
83 this.ignored_packages = ignored_packages;
84 }
85
86
87 /** @param ignored_packages classes contained in these packages will be loaded
88 * with the system class loader
89 * @param deferTo delegate class loader to use for ignored packages
90 */
91 public ClassLoader(java.lang.ClassLoader deferTo, String[] ignored_packages) {
92 this(ignored_packages);
93 this.repository = new ClassLoaderRepository(deferTo);
94 }
95
96
97 protected Class loadClass( String class_name, boolean resolve ) throws ClassNotFoundException {
98 Class cl = null;
99 /* First try: lookup hash table.
100 */
101 if ((cl = (Class) classes.get(class_name)) == null) {
102 /* Second try: Load system class using system class loader. You better
103 * don't mess around with them.
104 */
105 for (int i = 0; i < ignored_packages.length; i++) {
106 if (class_name.startsWith(ignored_packages[i])) {
107 cl = getParent().loadClass(class_name);
108 break;
109 }
110 }
111 if (cl == null) {
112 JavaClass clazz = null;
113 /* Third try: Special request?
114 */
115 if (class_name.indexOf("$$BCEL$$") >= 0) {
116 clazz = createClass(class_name);
117 } else { // Fourth try: Load classes via repository
118 if ((clazz = repository.loadClass(class_name)) != null) {
119 clazz = modifyClass(clazz);
120 } else {
121 throw new ClassNotFoundException(class_name);
122 }
123 }
124 if (clazz != null) {
125 byte[] bytes = clazz.getBytes();
126 cl = defineClass(class_name, bytes, 0, bytes.length);
127 } else {
128 cl = Class.forName(class_name);
129 }
130 }
131 if (resolve) {
132 resolveClass(cl);
133 }
134 }
135 classes.put(class_name, cl);
136 return cl;
137 }
138
139
140 /** Override this method if you want to alter a class before it gets actually
141 * loaded. Does nothing by default.
142 */
143 protected JavaClass modifyClass( JavaClass clazz ) {
144 return clazz;
145 }
146
147
148 /**
149 * Override this method to create you own classes on the fly. The
150 * name contains the special token $$BCEL$$. Everything before that
151 * token is consddered to be a package name. You can encode you own
152 * arguments into the subsequent string. You must regard however not
153 * to use any "illegal" characters, i.e., characters that may not
154 * appear in a Java class name too<br>
155 *
156 * The default implementation interprets the string as a encoded compressed
157 * Java class, unpacks and decodes it with the Utility.decode() method, and
158 * parses the resulting byte array and returns the resulting JavaClass object.
159 *
160 * @param class_name compressed byte code with "$$BCEL$$" in it
161 */
162 protected JavaClass createClass( String class_name ) {
163 int index = class_name.indexOf("$$BCEL$$");
164 String real_name = class_name.substring(index + 8);
165 JavaClass clazz = null;
166 try {
167 byte[] bytes = Utility.decode(real_name, true);
168 ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
169 clazz = parser.parse();
170 } catch (Throwable e) {
171 e.printStackTrace();
172 return null;
173 }
174 // Adapt the class name to the passed value
175 ConstantPool cp = clazz.getConstantPool();
176 ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
177 Constants.CONSTANT_Class);
178 ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
179 Constants.CONSTANT_Utf8);
180 name.setBytes(class_name.replace('.', '/'));
181 return clazz;
182 }
183 }
+0
-121
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassLoaderRepository.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.apache.bcel.classfile.ClassParser;
23 import org.apache.bcel.classfile.JavaClass;
24
25 /**
26 * The repository maintains information about which classes have
27 * been loaded.
28 *
29 * It loads its data from the ClassLoader implementation
30 * passed into its constructor.
31 *
32 * @see org.apache.bcel.Repository
33 *
34 * @version $Id: ClassLoaderRepository.java 386056 2006-03-15 11:31:56Z tcurdt $
35 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36 * @author David Dixon-Peugh
37 */
38 public class ClassLoaderRepository implements Repository {
39
40 private java.lang.ClassLoader loader;
41 private Map loadedClasses = new HashMap(); // CLASSNAME X JAVACLASS
42
43
44 public ClassLoaderRepository(java.lang.ClassLoader loader) {
45 this.loader = loader;
46 }
47
48
49 /**
50 * Store a new JavaClass into this Repository.
51 */
52 public void storeClass( JavaClass clazz ) {
53 loadedClasses.put(clazz.getClassName(), clazz);
54 clazz.setRepository(this);
55 }
56
57
58 /**
59 * Remove class from repository
60 */
61 public void removeClass( JavaClass clazz ) {
62 loadedClasses.remove(clazz.getClassName());
63 }
64
65
66 /**
67 * Find an already defined JavaClass.
68 */
69 public JavaClass findClass( String className ) {
70 if (loadedClasses.containsKey(className)) {
71 return (JavaClass) loadedClasses.get(className);
72 } else {
73 return null;
74 }
75 }
76
77
78 /**
79 * Lookup a JavaClass object from the Class Name provided.
80 */
81 public JavaClass loadClass( String className ) throws ClassNotFoundException {
82 String classFile = className.replace('.', '/');
83 JavaClass RC = findClass(className);
84 if (RC != null) {
85 return RC;
86 }
87 try {
88 InputStream is = loader.getResourceAsStream(classFile + ".class");
89 if (is == null) {
90 throw new ClassNotFoundException(className + " not found.");
91 }
92 ClassParser parser = new ClassParser(is, className);
93 RC = parser.parse();
94 storeClass(RC);
95 return RC;
96 } catch (IOException e) {
97 throw new ClassNotFoundException(e.toString());
98 }
99 }
100
101
102 public JavaClass loadClass( Class clazz ) throws ClassNotFoundException {
103 return loadClass(clazz.getName());
104 }
105
106
107 /** Clear all entries from cache.
108 */
109 public void clear() {
110 loadedClasses.clear();
111 }
112
113
114 /*
115 * @return null
116 */
117 public ClassPath getClassPath() {
118 return null;
119 }
120 }
+0
-396
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassPath.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.DataInputStream;
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.FilenameFilter;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Locale;
29 import java.util.StringTokenizer;
30 import java.util.zip.ZipEntry;
31 import java.util.zip.ZipFile;
32
33 /**
34 * Responsible for loading (class) files from the CLASSPATH. Inspired by
35 * sun.tools.ClassPath.
36 *
37 * @version $Id: ClassPath.java 386056 2006-03-15 11:31:56Z tcurdt $
38 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
39 */
40 public class ClassPath implements Serializable {
41
42 public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
43 private PathEntry[] paths;
44 private String class_path;
45
46
47 /**
48 * Search for classes in given path.
49 */
50 public ClassPath(String class_path) {
51 this.class_path = class_path;
52 List vec = new ArrayList();
53 for (StringTokenizer tok = new StringTokenizer(class_path, System
54 .getProperty("path.separator")); tok.hasMoreTokens();) {
55 String path = tok.nextToken();
56 if (!path.equals("")) {
57 File file = new File(path);
58 try {
59 if (file.exists()) {
60 if (file.isDirectory()) {
61 vec.add(new Dir(path));
62 } else {
63 vec.add(new Zip(new ZipFile(file)));
64 }
65 }
66 } catch (IOException e) {
67 System.err.println("CLASSPATH component " + file + ": " + e);
68 }
69 }
70 }
71 paths = new PathEntry[vec.size()];
72 vec.toArray(paths);
73 }
74
75
76 /**
77 * Search for classes in CLASSPATH.
78 * @deprecated Use SYSTEM_CLASS_PATH constant
79 */
80 public ClassPath() {
81 this(getClassPath());
82 }
83
84
85 /** @return used class path string
86 */
87 public String toString() {
88 return class_path;
89 }
90
91
92 public int hashCode() {
93 return class_path.hashCode();
94 }
95
96
97 public boolean equals( Object o ) {
98 if (o instanceof ClassPath) {
99 return class_path.equals(((ClassPath) o).class_path);
100 }
101 return false;
102 }
103
104
105 private static final void getPathComponents( String path, List list ) {
106 if (path != null) {
107 StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
108 while (tok.hasMoreTokens()) {
109 String name = tok.nextToken();
110 File file = new File(name);
111 if (file.exists()) {
112 list.add(name);
113 }
114 }
115 }
116 }
117
118
119 /** Checks for class path components in the following properties:
120 * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
121 *
122 * @return class path as used by default by BCEL
123 */
124 public static final String getClassPath() {
125 String class_path = System.getProperty("java.class.path");
126 String boot_path = System.getProperty("sun.boot.class.path");
127 String ext_path = System.getProperty("java.ext.dirs");
128 List list = new ArrayList();
129 getPathComponents(class_path, list);
130 getPathComponents(boot_path, list);
131 List dirs = new ArrayList();
132 getPathComponents(ext_path, dirs);
133 for (Iterator e = dirs.iterator(); e.hasNext();) {
134 File ext_dir = new File((String) e.next());
135 String[] extensions = ext_dir.list(new FilenameFilter() {
136
137 public boolean accept( File dir, String name ) {
138 name = name.toLowerCase(Locale.ENGLISH);
139 return name.endsWith(".zip") || name.endsWith(".jar");
140 }
141 });
142 if (extensions != null) {
143 for (int i = 0; i < extensions.length; i++) {
144 list.add(ext_dir.getPath() + File.separatorChar + extensions[i]);
145 }
146 }
147 }
148 StringBuffer buf = new StringBuffer();
149 for (Iterator e = list.iterator(); e.hasNext();) {
150 buf.append((String) e.next());
151 if (e.hasNext()) {
152 buf.append(File.pathSeparatorChar);
153 }
154 }
155 return buf.toString().intern();
156 }
157
158
159 /**
160 * @param name fully qualified class name, e.g. java.lang.String
161 * @return input stream for class
162 */
163 public InputStream getInputStream( String name ) throws IOException {
164 return getInputStream(name.replace('.', '/'), ".class");
165 }
166
167
168 /**
169 * Return stream for class or resource on CLASSPATH.
170 *
171 * @param name fully qualified file name, e.g. java/lang/String
172 * @param suffix file name ends with suff, e.g. .java
173 * @return input stream for file on class path
174 */
175 public InputStream getInputStream( String name, String suffix ) throws IOException {
176 InputStream is = null;
177 try {
178 is = getClass().getClassLoader().getResourceAsStream(name + suffix);
179 } catch (Exception e) {
180 }
181 if (is != null) {
182 return is;
183 }
184 return getClassFile(name, suffix).getInputStream();
185 }
186
187
188 /**
189 * @param name fully qualified file name, e.g. java/lang/String
190 * @param suffix file name ends with suff, e.g. .java
191 * @return class file for the java class
192 */
193 public ClassFile getClassFile( String name, String suffix ) throws IOException {
194 for (int i = 0; i < paths.length; i++) {
195 ClassFile cf;
196 if ((cf = paths[i].getClassFile(name, suffix)) != null) {
197 return cf;
198 }
199 }
200 throw new IOException("Couldn't find: " + name + suffix);
201 }
202
203
204 /**
205 * @param name fully qualified class name, e.g. java.lang.String
206 * @return input stream for class
207 */
208 public ClassFile getClassFile( String name ) throws IOException {
209 return getClassFile(name, ".class");
210 }
211
212
213 /**
214 * @param name fully qualified file name, e.g. java/lang/String
215 * @param suffix file name ends with suffix, e.g. .java
216 * @return byte array for file on class path
217 */
218 public byte[] getBytes( String name, String suffix ) throws IOException {
219 DataInputStream dis = null;
220 try {
221 InputStream is = getInputStream(name, suffix);
222 if (is == null) {
223 throw new IOException("Couldn't find: " + name + suffix);
224 }
225 dis = new DataInputStream(is);
226 byte[] bytes = new byte[is.available()];
227 dis.readFully(bytes);
228 return bytes;
229 } finally {
230 if (dis != null) {
231 dis.close();
232 }
233 }
234 }
235
236
237 /**
238 * @return byte array for class
239 */
240 public byte[] getBytes( String name ) throws IOException {
241 return getBytes(name, ".class");
242 }
243
244
245 /**
246 * @param name name of file to search for, e.g. java/lang/String.java
247 * @return full (canonical) path for file
248 */
249 public String getPath( String name ) throws IOException {
250 int index = name.lastIndexOf('.');
251 String suffix = "";
252 if (index > 0) {
253 suffix = name.substring(index);
254 name = name.substring(0, index);
255 }
256 return getPath(name, suffix);
257 }
258
259
260 /**
261 * @param name name of file to search for, e.g. java/lang/String
262 * @param suffix file name suffix, e.g. .java
263 * @return full (canonical) path for file, if it exists
264 */
265 public String getPath( String name, String suffix ) throws IOException {
266 return getClassFile(name, suffix).getPath();
267 }
268
269 private static abstract class PathEntry implements Serializable {
270
271 abstract ClassFile getClassFile( String name, String suffix ) throws IOException;
272 }
273
274 /** Contains information about file/ZIP entry of the Java class.
275 */
276 public interface ClassFile {
277
278 /** @return input stream for class file.
279 */
280 public abstract InputStream getInputStream() throws IOException;
281
282
283 /** @return canonical path to class file.
284 */
285 public abstract String getPath();
286
287
288 /** @return base path of found class, i.e. class is contained relative
289 * to that path, which may either denote a directory, or zip file
290 */
291 public abstract String getBase();
292
293
294 /** @return modification time of class file.
295 */
296 public abstract long getTime();
297
298
299 /** @return size of class file.
300 */
301 public abstract long getSize();
302 }
303
304 private static class Dir extends PathEntry {
305
306 private String dir;
307
308
309 Dir(String d) {
310 dir = d;
311 }
312
313
314 ClassFile getClassFile( String name, String suffix ) throws IOException {
315 final File file = new File(dir + File.separatorChar
316 + name.replace('.', File.separatorChar) + suffix);
317 return file.exists() ? new ClassFile() {
318
319 public InputStream getInputStream() throws IOException {
320 return new FileInputStream(file);
321 }
322
323
324 public String getPath() {
325 try {
326 return file.getCanonicalPath();
327 } catch (IOException e) {
328 return null;
329 }
330 }
331
332
333 public long getTime() {
334 return file.lastModified();
335 }
336
337
338 public long getSize() {
339 return file.length();
340 }
341
342
343 public String getBase() {
344 return dir;
345 }
346 } : null;
347 }
348
349
350 public String toString() {
351 return dir;
352 }
353 }
354
355 private static class Zip extends PathEntry {
356
357 private ZipFile zip;
358
359
360 Zip(ZipFile z) {
361 zip = z;
362 }
363
364
365 ClassFile getClassFile( String name, String suffix ) throws IOException {
366 final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix);
367 return (entry != null) ? new ClassFile() {
368
369 public InputStream getInputStream() throws IOException {
370 return zip.getInputStream(entry);
371 }
372
373
374 public String getPath() {
375 return entry.toString();
376 }
377
378
379 public long getTime() {
380 return entry.getTime();
381 }
382
383
384 public long getSize() {
385 return entry.getSize();
386 }
387
388
389 public String getBase() {
390 return zip.getName();
391 }
392 } : null;
393 }
394 }
395 }
+0
-52
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassQueue.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.util.LinkedList;
19 import org.apache.bcel.classfile.JavaClass;
20
21 /**
22 * Utility class implementing a (typesafe) queue of JavaClass
23 * objects.
24 *
25 * @version $Id: ClassQueue.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public class ClassQueue implements java.io.Serializable {
29
30 protected LinkedList vec = new LinkedList();
31
32
33 public void enqueue( JavaClass clazz ) {
34 vec.addLast(clazz);
35 }
36
37
38 public JavaClass dequeue() {
39 return (JavaClass) vec.removeFirst();
40 }
41
42
43 public boolean empty() {
44 return vec.isEmpty();
45 }
46
47
48 public String toString() {
49 return vec.toString();
50 }
51 }
+0
-69
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassSet.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.Map;
21 import org.apache.bcel.classfile.JavaClass;
22
23 /**
24 * Utility class implementing a (typesafe) set of JavaClass objects.
25 * Since JavaClass has no equals() method, the name of the class is
26 * used for comparison.
27 *
28 * @version $Id: ClassSet.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 * @see ClassStack
31 */
32 public class ClassSet implements java.io.Serializable {
33
34 private Map _map = new HashMap();
35
36
37 public boolean add( JavaClass clazz ) {
38 boolean result = false;
39 if (!_map.containsKey(clazz.getClassName())) {
40 result = true;
41 _map.put(clazz.getClassName(), clazz);
42 }
43 return result;
44 }
45
46
47 public void remove( JavaClass clazz ) {
48 _map.remove(clazz.getClassName());
49 }
50
51
52 public boolean empty() {
53 return _map.isEmpty();
54 }
55
56
57 public JavaClass[] toArray() {
58 Collection values = _map.values();
59 JavaClass[] classes = new JavaClass[values.size()];
60 values.toArray(classes);
61 return classes;
62 }
63
64
65 public String[] getClassNames() {
66 return (String[]) _map.keySet().toArray(new String[_map.keySet().size()]);
67 }
68 }
+0
-52
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassStack.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.util.Stack;
19 import org.apache.bcel.classfile.JavaClass;
20
21 /**
22 * Utility class implementing a (typesafe) stack of JavaClass objects.
23 *
24 * @version $Id: ClassStack.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 * @see Stack
27 */
28 public class ClassStack implements java.io.Serializable {
29
30 private Stack stack = new Stack();
31
32
33 public void push( JavaClass clazz ) {
34 stack.push(clazz);
35 }
36
37
38 public JavaClass pop() {
39 return (JavaClass) stack.pop();
40 }
41
42
43 public JavaClass top() {
44 return (JavaClass) stack.peek();
45 }
46
47
48 public boolean empty() {
49 return stack.empty();
50 }
51 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ClassVector.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import org.apache.bcel.classfile.JavaClass;
21
22 /**
23 * Utility class implementing a (typesafe) collection of JavaClass
24 * objects. Contains the most important methods of a Vector.
25 *
26 * @version $Id: ClassVector.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 *
29 * @deprecated as of 5.1.1 - 7/17/2005
30 */
31 public class ClassVector implements java.io.Serializable {
32
33 protected List vec = new ArrayList();
34
35
36 public void addElement( JavaClass clazz ) {
37 vec.add(clazz);
38 }
39
40
41 public JavaClass elementAt( int index ) {
42 return (JavaClass) vec.get(index);
43 }
44
45
46 public void removeElementAt( int index ) {
47 vec.remove(index);
48 }
49
50
51 public JavaClass[] toArray() {
52 JavaClass[] classes = new JavaClass[vec.size()];
53 vec.toArray(classes);
54 return classes;
55 }
56 }
+0
-564
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/CodeHTML.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.FileOutputStream;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import java.util.BitSet;
22 import org.apache.bcel.classfile.Attribute;
23 import org.apache.bcel.classfile.Code;
24 import org.apache.bcel.classfile.CodeException;
25 import org.apache.bcel.classfile.ConstantFieldref;
26 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
27 import org.apache.bcel.classfile.ConstantMethodref;
28 import org.apache.bcel.classfile.ConstantNameAndType;
29 import org.apache.bcel.classfile.ConstantPool;
30 import org.apache.bcel.classfile.LocalVariable;
31 import org.apache.bcel.classfile.LocalVariableTable;
32 import org.apache.bcel.classfile.Method;
33 import org.apache.bcel.classfile.Utility;
34
35 /**
36 * Convert code into HTML file.
37 *
38 * @version $Id: CodeHTML.java 386056 2006-03-15 11:31:56Z tcurdt $
39 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
40 *
41 */
42 final class CodeHTML implements org.apache.bcel.Constants {
43
44 private String class_name; // name of current class
45 private Method[] methods; // Methods to print
46 private PrintWriter file; // file to write to
47 private BitSet goto_set;
48 private ConstantPool constant_pool;
49 private ConstantHTML constant_html;
50 private static boolean wide = false;
51
52
53 CodeHTML(String dir, String class_name, Method[] methods, ConstantPool constant_pool,
54 ConstantHTML constant_html) throws IOException {
55 this.class_name = class_name;
56 this.methods = methods;
57 this.constant_pool = constant_pool;
58 this.constant_html = constant_html;
59 file = new PrintWriter(new FileOutputStream(dir + class_name + "_code.html"));
60 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\">");
61 for (int i = 0; i < methods.length; i++) {
62 writeMethod(methods[i], i);
63 }
64 file.println("</BODY></HTML>");
65 file.close();
66 }
67
68
69 /**
70 * Disassemble a stream of byte codes and return the
71 * string representation.
72 *
73 * @param stream data input stream
74 * @return String representation of byte code
75 */
76 private final String codeToHTML( ByteSequence bytes, int method_number ) throws IOException {
77 short opcode = (short) bytes.readUnsignedByte();
78 StringBuffer buf;
79 String name, signature;
80 int default_offset = 0, low, high;
81 int index, class_index, vindex, constant;
82 int[] jump_table;
83 int no_pad_bytes = 0, offset;
84 buf = new StringBuffer(256);
85 buf.append("<TT>").append(OPCODE_NAMES[opcode]).append("</TT></TD><TD>");
86 /* Special case: Skip (0-3) padding bytes, i.e., the
87 * following bytes are 4-byte-aligned
88 */
89 if ((opcode == TABLESWITCH) || (opcode == LOOKUPSWITCH)) {
90 int remainder = bytes.getIndex() % 4;
91 no_pad_bytes = (remainder == 0) ? 0 : 4 - remainder;
92 for (int i = 0; i < no_pad_bytes; i++) {
93 bytes.readByte();
94 }
95 // Both cases have a field default_offset in common
96 default_offset = bytes.readInt();
97 }
98 switch (opcode) {
99 case TABLESWITCH:
100 low = bytes.readInt();
101 high = bytes.readInt();
102 offset = bytes.getIndex() - 12 - no_pad_bytes - 1;
103 default_offset += offset;
104 buf.append("<TABLE BORDER=1><TR>");
105 // Print switch indices in first row (and default)
106 jump_table = new int[high - low + 1];
107 for (int i = 0; i < jump_table.length; i++) {
108 jump_table[i] = offset + bytes.readInt();
109 buf.append("<TH>").append(low + i).append("</TH>");
110 }
111 buf.append("<TH>default</TH></TR>\n<TR>");
112 // Print target and default indices in second row
113 for (int i = 0; i < jump_table.length; i++) {
114 buf.append("<TD><A HREF=\"#code").append(method_number).append("@").append(
115 jump_table[i]).append("\">").append(jump_table[i]).append("</A></TD>");
116 }
117 buf.append("<TD><A HREF=\"#code").append(method_number).append("@").append(
118 default_offset).append("\">").append(default_offset).append(
119 "</A></TD></TR>\n</TABLE>\n");
120 break;
121 /* Lookup switch has variable length arguments.
122 */
123 case LOOKUPSWITCH:
124 int npairs = bytes.readInt();
125 offset = bytes.getIndex() - 8 - no_pad_bytes - 1;
126 jump_table = new int[npairs];
127 default_offset += offset;
128 buf.append("<TABLE BORDER=1><TR>");
129 // Print switch indices in first row (and default)
130 for (int i = 0; i < npairs; i++) {
131 int match = bytes.readInt();
132 jump_table[i] = offset + bytes.readInt();
133 buf.append("<TH>").append(match).append("</TH>");
134 }
135 buf.append("<TH>default</TH></TR>\n<TR>");
136 // Print target and default indices in second row
137 for (int i = 0; i < npairs; i++) {
138 buf.append("<TD><A HREF=\"#code").append(method_number).append("@").append(
139 jump_table[i]).append("\">").append(jump_table[i]).append("</A></TD>");
140 }
141 buf.append("<TD><A HREF=\"#code").append(method_number).append("@").append(
142 default_offset).append("\">").append(default_offset).append(
143 "</A></TD></TR>\n</TABLE>\n");
144 break;
145 /* Two address bytes + offset from start of byte stream form the
146 * jump target.
147 */
148 case GOTO:
149 case IFEQ:
150 case IFGE:
151 case IFGT:
152 case IFLE:
153 case IFLT:
154 case IFNE:
155 case IFNONNULL:
156 case IFNULL:
157 case IF_ACMPEQ:
158 case IF_ACMPNE:
159 case IF_ICMPEQ:
160 case IF_ICMPGE:
161 case IF_ICMPGT:
162 case IF_ICMPLE:
163 case IF_ICMPLT:
164 case IF_ICMPNE:
165 case JSR:
166 index = (int) (bytes.getIndex() + bytes.readShort() - 1);
167 buf.append("<A HREF=\"#code").append(method_number).append("@").append(index)
168 .append("\">").append(index).append("</A>");
169 break;
170 /* Same for 32-bit wide jumps
171 */
172 case GOTO_W:
173 case JSR_W:
174 int windex = bytes.getIndex() + bytes.readInt() - 1;
175 buf.append("<A HREF=\"#code").append(method_number).append("@").append(windex)
176 .append("\">").append(windex).append("</A>");
177 break;
178 /* Index byte references local variable (register)
179 */
180 case ALOAD:
181 case ASTORE:
182 case DLOAD:
183 case DSTORE:
184 case FLOAD:
185 case FSTORE:
186 case ILOAD:
187 case ISTORE:
188 case LLOAD:
189 case LSTORE:
190 case RET:
191 if (wide) {
192 vindex = bytes.readShort();
193 wide = false; // Clear flag
194 } else {
195 vindex = bytes.readUnsignedByte();
196 }
197 buf.append("%").append(vindex);
198 break;
199 /*
200 * Remember wide byte which is used to form a 16-bit address in the
201 * following instruction. Relies on that the method is called again with
202 * the following opcode.
203 */
204 case WIDE:
205 wide = true;
206 buf.append("(wide)");
207 break;
208 /* Array of basic type.
209 */
210 case NEWARRAY:
211 buf.append("<FONT COLOR=\"#00FF00\">").append(TYPE_NAMES[bytes.readByte()]).append(
212 "</FONT>");
213 break;
214 /* Access object/class fields.
215 */
216 case GETFIELD:
217 case GETSTATIC:
218 case PUTFIELD:
219 case PUTSTATIC:
220 index = bytes.readShort();
221 ConstantFieldref c1 = (ConstantFieldref) constant_pool.getConstant(index,
222 CONSTANT_Fieldref);
223 class_index = c1.getClassIndex();
224 name = constant_pool.getConstantString(class_index, CONSTANT_Class);
225 name = Utility.compactClassName(name, false);
226 index = c1.getNameAndTypeIndex();
227 String field_name = constant_pool.constantToString(index, CONSTANT_NameAndType);
228 if (name.equals(class_name)) { // Local field
229 buf.append("<A HREF=\"").append(class_name).append("_methods.html#field")
230 .append(field_name).append("\" TARGET=Methods>").append(field_name)
231 .append("</A>\n");
232 } else {
233 buf.append(constant_html.referenceConstant(class_index)).append(".").append(
234 field_name);
235 }
236 break;
237 /* Operands are references to classes in constant pool
238 */
239 case CHECKCAST:
240 case INSTANCEOF:
241 case NEW:
242 index = bytes.readShort();
243 buf.append(constant_html.referenceConstant(index));
244 break;
245 /* Operands are references to methods in constant pool
246 */
247 case INVOKESPECIAL:
248 case INVOKESTATIC:
249 case INVOKEVIRTUAL:
250 case INVOKEINTERFACE:
251 int m_index = bytes.readShort();
252 String str;
253 if (opcode == INVOKEINTERFACE) { // Special treatment needed
254 int nargs = bytes.readUnsignedByte(); // Redundant
255 int reserved = bytes.readUnsignedByte(); // Reserved
256 ConstantInterfaceMethodref c = (ConstantInterfaceMethodref) constant_pool
257 .getConstant(m_index, CONSTANT_InterfaceMethodref);
258 class_index = c.getClassIndex();
259 str = constant_pool.constantToString(c);
260 index = c.getNameAndTypeIndex();
261 } else {
262 ConstantMethodref c = (ConstantMethodref) constant_pool.getConstant(m_index,
263 CONSTANT_Methodref);
264 class_index = c.getClassIndex();
265 str = constant_pool.constantToString(c);
266 index = c.getNameAndTypeIndex();
267 }
268 name = Class2HTML.referenceClass(class_index);
269 str = Class2HTML.toHTML(constant_pool.constantToString(constant_pool.getConstant(
270 index, CONSTANT_NameAndType)));
271 // Get signature, i.e., types
272 ConstantNameAndType c2 = (ConstantNameAndType) constant_pool.getConstant(index,
273 CONSTANT_NameAndType);
274 signature = constant_pool.constantToString(c2.getSignatureIndex(), CONSTANT_Utf8);
275 String[] args = Utility.methodSignatureArgumentTypes(signature, false);
276 String type = Utility.methodSignatureReturnType(signature, false);
277 buf.append(name).append(".<A HREF=\"").append(class_name).append("_cp.html#cp")
278 .append(m_index).append("\" TARGET=ConstantPool>").append(str).append(
279 "</A>").append("(");
280 // List arguments
281 for (int i = 0; i < args.length; i++) {
282 buf.append(Class2HTML.referenceType(args[i]));
283 if (i < args.length - 1) {
284 buf.append(", ");
285 }
286 }
287 // Attach return type
288 buf.append("):").append(Class2HTML.referenceType(type));
289 break;
290 /* Operands are references to items in constant pool
291 */
292 case LDC_W:
293 case LDC2_W:
294 index = bytes.readShort();
295 buf.append("<A HREF=\"").append(class_name).append("_cp.html#cp").append(index)
296 .append("\" TARGET=\"ConstantPool\">").append(
297 Class2HTML.toHTML(constant_pool.constantToString(index,
298 constant_pool.getConstant(index).getTag()))).append("</a>");
299 break;
300 case LDC:
301 index = bytes.readUnsignedByte();
302 buf.append("<A HREF=\"").append(class_name).append("_cp.html#cp").append(index)
303 .append("\" TARGET=\"ConstantPool\">").append(
304 Class2HTML.toHTML(constant_pool.constantToString(index,
305 constant_pool.getConstant(index).getTag()))).append("</a>");
306 break;
307 /* Array of references.
308 */
309 case ANEWARRAY:
310 index = bytes.readShort();
311 buf.append(constant_html.referenceConstant(index));
312 break;
313 /* Multidimensional array of references.
314 */
315 case MULTIANEWARRAY:
316 index = bytes.readShort();
317 int dimensions = bytes.readByte();
318 buf.append(constant_html.referenceConstant(index)).append(":").append(dimensions)
319 .append("-dimensional");
320 break;
321 /* Increment local variable.
322 */
323 case IINC:
324 if (wide) {
325 vindex = bytes.readShort();
326 constant = bytes.readShort();
327 wide = false;
328 } else {
329 vindex = bytes.readUnsignedByte();
330 constant = bytes.readByte();
331 }
332 buf.append("%").append(vindex).append(" ").append(constant);
333 break;
334 default:
335 if (NO_OF_OPERANDS[opcode] > 0) {
336 for (int i = 0; i < TYPE_OF_OPERANDS[opcode].length; i++) {
337 switch (TYPE_OF_OPERANDS[opcode][i]) {
338 case T_BYTE:
339 buf.append(bytes.readUnsignedByte());
340 break;
341 case T_SHORT: // Either branch or index
342 buf.append(bytes.readShort());
343 break;
344 case T_INT:
345 buf.append(bytes.readInt());
346 break;
347 default: // Never reached
348 System.err.println("Unreachable default case reached!");
349 System.exit(-1);
350 }
351 buf.append("&nbsp;");
352 }
353 }
354 }
355 buf.append("</TD>");
356 return buf.toString();
357 }
358
359
360 /**
361 * Find all target addresses in code, so that they can be marked
362 * with &lt;A NAME = ...&gt;. Target addresses are kept in an BitSet object.
363 */
364 private final void findGotos( ByteSequence bytes, Method method, Code code ) throws IOException {
365 int index;
366 goto_set = new BitSet(bytes.available());
367 int opcode;
368 /* First get Code attribute from method and the exceptions handled
369 * (try .. catch) in this method. We only need the line number here.
370 */
371 if (code != null) {
372 CodeException[] ce = code.getExceptionTable();
373 int len = ce.length;
374 for (int i = 0; i < len; i++) {
375 goto_set.set(ce[i].getStartPC());
376 goto_set.set(ce[i].getEndPC());
377 goto_set.set(ce[i].getHandlerPC());
378 }
379 // Look for local variables and their range
380 Attribute[] attributes = code.getAttributes();
381 for (int i = 0; i < attributes.length; i++) {
382 if (attributes[i].getTag() == ATTR_LOCAL_VARIABLE_TABLE) {
383 LocalVariable[] vars = ((LocalVariableTable) attributes[i])
384 .getLocalVariableTable();
385 for (int j = 0; j < vars.length; j++) {
386 int start = vars[j].getStartPC();
387 int end = (int) (start + vars[j].getLength());
388 goto_set.set(start);
389 goto_set.set(end);
390 }
391 break;
392 }
393 }
394 }
395 // Get target addresses from GOTO, JSR, TABLESWITCH, etc.
396 for (int i = 0; bytes.available() > 0; i++) {
397 opcode = bytes.readUnsignedByte();
398 //System.out.println(OPCODE_NAMES[opcode]);
399 switch (opcode) {
400 case TABLESWITCH:
401 case LOOKUPSWITCH:
402 //bytes.readByte(); // Skip already read byte
403 int remainder = bytes.getIndex() % 4;
404 int no_pad_bytes = (remainder == 0) ? 0 : 4 - remainder;
405 int default_offset,
406 offset;
407 for (int j = 0; j < no_pad_bytes; j++) {
408 bytes.readByte();
409 }
410 // Both cases have a field default_offset in common
411 default_offset = bytes.readInt();
412 if (opcode == TABLESWITCH) {
413 int low = bytes.readInt();
414 int high = bytes.readInt();
415 offset = bytes.getIndex() - 12 - no_pad_bytes - 1;
416 default_offset += offset;
417 goto_set.set(default_offset);
418 for (int j = 0; j < (high - low + 1); j++) {
419 index = offset + bytes.readInt();
420 goto_set.set(index);
421 }
422 } else { // LOOKUPSWITCH
423 int npairs = bytes.readInt();
424 offset = bytes.getIndex() - 8 - no_pad_bytes - 1;
425 default_offset += offset;
426 goto_set.set(default_offset);
427 for (int j = 0; j < npairs; j++) {
428 int match = bytes.readInt();
429 index = offset + bytes.readInt();
430 goto_set.set(index);
431 }
432 }
433 break;
434 case GOTO:
435 case IFEQ:
436 case IFGE:
437 case IFGT:
438 case IFLE:
439 case IFLT:
440 case IFNE:
441 case IFNONNULL:
442 case IFNULL:
443 case IF_ACMPEQ:
444 case IF_ACMPNE:
445 case IF_ICMPEQ:
446 case IF_ICMPGE:
447 case IF_ICMPGT:
448 case IF_ICMPLE:
449 case IF_ICMPLT:
450 case IF_ICMPNE:
451 case JSR:
452 //bytes.readByte(); // Skip already read byte
453 index = bytes.getIndex() + bytes.readShort() - 1;
454 goto_set.set(index);
455 break;
456 case GOTO_W:
457 case JSR_W:
458 //bytes.readByte(); // Skip already read byte
459 index = bytes.getIndex() + bytes.readInt() - 1;
460 goto_set.set(index);
461 break;
462 default:
463 bytes.unreadByte();
464 codeToHTML(bytes, 0); // Ignore output
465 }
466 }
467 }
468
469
470 /**
471 * Write a single method with the byte code associated with it.
472 */
473 private void writeMethod( Method method, int method_number ) throws IOException {
474 // Get raw signature
475 String signature = method.getSignature();
476 // Get array of strings containing the argument types
477 String[] args = Utility.methodSignatureArgumentTypes(signature, false);
478 // Get return type string
479 String type = Utility.methodSignatureReturnType(signature, false);
480 // Get method name
481 String name = method.getName();
482 String html_name = Class2HTML.toHTML(name);
483 // Get method's access flags
484 String access = Utility.accessToString(method.getAccessFlags());
485 access = Utility.replace(access, " ", "&nbsp;");
486 // Get the method's attributes, the Code Attribute in particular
487 Attribute[] attributes = method.getAttributes();
488 file.print("<P><B><FONT COLOR=\"#FF0000\">" + access + "</FONT>&nbsp;" + "<A NAME=method"
489 + method_number + ">" + Class2HTML.referenceType(type) + "</A>&nbsp<A HREF=\""
490 + class_name + "_methods.html#method" + method_number + "\" TARGET=Methods>"
491 + html_name + "</A>(");
492 for (int i = 0; i < args.length; i++) {
493 file.print(Class2HTML.referenceType(args[i]));
494 if (i < args.length - 1) {
495 file.print(",&nbsp;");
496 }
497 }
498 file.println(")</B></P>");
499 Code c = null;
500 byte[] code = null;
501 if (attributes.length > 0) {
502 file.print("<H4>Attributes</H4><UL>\n");
503 for (int i = 0; i < attributes.length; i++) {
504 byte tag = attributes[i].getTag();
505 if (tag != ATTR_UNKNOWN) {
506 file.print("<LI><A HREF=\"" + class_name + "_attributes.html#method"
507 + method_number + "@" + i + "\" TARGET=Attributes>"
508 + ATTRIBUTE_NAMES[tag] + "</A></LI>\n");
509 } else {
510 file.print("<LI>" + attributes[i] + "</LI>");
511 }
512 if (tag == ATTR_CODE) {
513 c = (Code) attributes[i];
514 Attribute[] attributes2 = c.getAttributes();
515 code = c.getCode();
516 file.print("<UL>");
517 for (int j = 0; j < attributes2.length; j++) {
518 tag = attributes2[j].getTag();
519 file.print("<LI><A HREF=\"" + class_name + "_attributes.html#" + "method"
520 + method_number + "@" + i + "@" + j + "\" TARGET=Attributes>"
521 + ATTRIBUTE_NAMES[tag] + "</A></LI>\n");
522 }
523 file.print("</UL>");
524 }
525 }
526 file.println("</UL>");
527 }
528 if (code != null) { // No code, an abstract method, e.g.
529 //System.out.println(name + "\n" + Utility.codeToString(code, constant_pool, 0, -1));
530 // Print the byte code
531 ByteSequence stream = new ByteSequence(code);
532 stream.mark(stream.available());
533 findGotos(stream, method, c);
534 stream.reset();
535 file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Byte<BR>offset</TH>"
536 + "<TH ALIGN=LEFT>Instruction</TH><TH ALIGN=LEFT>Argument</TH>");
537 for (int i = 0; stream.available() > 0; i++) {
538 int offset = stream.getIndex();
539 String str = codeToHTML(stream, method_number);
540 String anchor = "";
541 /* Set an anchor mark if this line is targetted by a goto, jsr, etc.
542 * Defining an anchor for every line is very inefficient!
543 */
544 if (goto_set.get(offset)) {
545 anchor = "<A NAME=code" + method_number + "@" + offset + "></A>";
546 }
547 String anchor2;
548 if (stream.getIndex() == code.length) {
549 anchor2 = "<A NAME=code" + method_number + "@" + code.length + ">" + offset
550 + "</A>";
551 } else {
552 anchor2 = "" + offset;
553 }
554 file
555 .println("<TR VALIGN=TOP><TD>" + anchor2 + "</TD><TD>" + anchor + str
556 + "</TR>");
557 }
558 // Mark last line, may be targetted from Attributes window
559 file.println("<TR><TD> </A></TD></TR>");
560 file.println("</TABLE>");
561 }
562 }
563 }
+0
-234
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/ConstantHTML.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.FileOutputStream;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import org.apache.bcel.classfile.Constant;
22 import org.apache.bcel.classfile.ConstantClass;
23 import org.apache.bcel.classfile.ConstantFieldref;
24 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
25 import org.apache.bcel.classfile.ConstantMethodref;
26 import org.apache.bcel.classfile.ConstantNameAndType;
27 import org.apache.bcel.classfile.ConstantPool;
28 import org.apache.bcel.classfile.ConstantString;
29 import org.apache.bcel.classfile.Method;
30 import org.apache.bcel.classfile.Utility;
31
32 /**
33 * Convert constant pool into HTML file.
34 *
35 * @version $Id: ConstantHTML.java 386056 2006-03-15 11:31:56Z tcurdt $
36 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
37 *
38 */
39 final class ConstantHTML implements org.apache.bcel.Constants {
40
41 private String class_name; // name of current class
42 private String class_package; // name of package
43 private ConstantPool constant_pool; // reference to constant pool
44 private PrintWriter file; // file to write to
45 private String[] constant_ref; // String to return for cp[i]
46 private Constant[] constants; // The constants in the cp
47 private Method[] methods;
48
49
50 ConstantHTML(String dir, String class_name, String class_package, Method[] methods,
51 ConstantPool constant_pool) throws IOException {
52 this.class_name = class_name;
53 this.class_package = class_package;
54 this.constant_pool = constant_pool;
55 this.methods = methods;
56 constants = constant_pool.getConstantPool();
57 file = new PrintWriter(new FileOutputStream(dir + class_name + "_cp.html"));
58 constant_ref = new String[constants.length];
59 constant_ref[0] = "&lt;unknown&gt;";
60 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
61 // Loop through constants, constants[0] is reserved
62 for (int i = 1; i < constants.length; i++) {
63 if (i % 2 == 0) {
64 file.print("<TR BGCOLOR=\"#C0C0C0\"><TD>");
65 } else {
66 file.print("<TR BGCOLOR=\"#A0A0A0\"><TD>");
67 }
68 if (constants[i] != null) {
69 writeConstant(i);
70 }
71 file.print("</TD></TR>\n");
72 }
73 file.println("</TABLE></BODY></HTML>");
74 file.close();
75 }
76
77
78 String referenceConstant( int index ) {
79 return constant_ref[index];
80 }
81
82
83 private void writeConstant( int index ) {
84 byte tag = constants[index].getTag();
85 int class_index, name_index;
86 String ref;
87 // The header is always the same
88 file.println("<H4> <A NAME=cp" + index + ">" + index + "</A> " + CONSTANT_NAMES[tag]
89 + "</H4>");
90 /* For every constant type get the needed parameters and print them appropiately
91 */
92 switch (tag) {
93 case CONSTANT_InterfaceMethodref:
94 case CONSTANT_Methodref:
95 // Get class_index and name_and_type_index, depending on type
96 if (tag == CONSTANT_Methodref) {
97 ConstantMethodref c = (ConstantMethodref) constant_pool.getConstant(index,
98 CONSTANT_Methodref);
99 class_index = c.getClassIndex();
100 name_index = c.getNameAndTypeIndex();
101 } else {
102 ConstantInterfaceMethodref c1 = (ConstantInterfaceMethodref) constant_pool
103 .getConstant(index, CONSTANT_InterfaceMethodref);
104 class_index = c1.getClassIndex();
105 name_index = c1.getNameAndTypeIndex();
106 }
107 // Get method name and its class
108 String method_name = constant_pool.constantToString(name_index,
109 CONSTANT_NameAndType);
110 String html_method_name = Class2HTML.toHTML(method_name);
111 // Partially compacted class name, i.e., / -> .
112 String method_class = constant_pool.constantToString(class_index, CONSTANT_Class);
113 String short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang.
114 short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang.
115 short_method_class = Utility.compactClassName(short_method_class, class_package
116 + ".", true); // Remove class package prefix
117 // Get method signature
118 ConstantNameAndType c2 = (ConstantNameAndType) constant_pool.getConstant(
119 name_index, CONSTANT_NameAndType);
120 String signature = constant_pool.constantToString(c2.getSignatureIndex(),
121 CONSTANT_Utf8);
122 // Get array of strings containing the argument types
123 String[] args = Utility.methodSignatureArgumentTypes(signature, false);
124 // Get return type string
125 String type = Utility.methodSignatureReturnType(signature, false);
126 String ret_type = Class2HTML.referenceType(type);
127 StringBuffer buf = new StringBuffer("(");
128 for (int i = 0; i < args.length; i++) {
129 buf.append(Class2HTML.referenceType(args[i]));
130 if (i < args.length - 1) {
131 buf.append(",&nbsp;");
132 }
133 }
134 buf.append(")");
135 String arg_types = buf.toString();
136 if (method_class.equals(class_name)) {
137 ref = "<A HREF=\"" + class_name + "_code.html#method"
138 + getMethodNumber(method_name + signature) + "\" TARGET=Code>"
139 + html_method_name + "</A>";
140 } else {
141 ref = "<A HREF=\"" + method_class + ".html" + "\" TARGET=_top>"
142 + short_method_class + "</A>." + html_method_name;
143 }
144 constant_ref[index] = ret_type + "&nbsp;<A HREF=\"" + class_name + "_cp.html#cp"
145 + class_index + "\" TARGET=Constants>" + short_method_class
146 + "</A>.<A HREF=\"" + class_name + "_cp.html#cp" + index
147 + "\" TARGET=ConstantPool>" + html_method_name + "</A>&nbsp;" + arg_types;
148 file.println("<P><TT>" + ret_type + "&nbsp;" + ref + arg_types
149 + "&nbsp;</TT>\n<UL>" + "<LI><A HREF=\"#cp" + class_index
150 + "\">Class index(" + class_index + ")</A>\n" + "<LI><A HREF=\"#cp"
151 + name_index + "\">NameAndType index(" + name_index + ")</A></UL>");
152 break;
153 case CONSTANT_Fieldref:
154 // Get class_index and name_and_type_index
155 ConstantFieldref c3 = (ConstantFieldref) constant_pool.getConstant(index,
156 CONSTANT_Fieldref);
157 class_index = c3.getClassIndex();
158 name_index = c3.getNameAndTypeIndex();
159 // Get method name and its class (compacted)
160 String field_class = constant_pool.constantToString(class_index, CONSTANT_Class);
161 String short_field_class = Utility.compactClassName(field_class); // I.e., remove java.lang.
162 short_field_class = Utility.compactClassName(short_field_class,
163 class_package + ".", true); // Remove class package prefix
164 String field_name = constant_pool
165 .constantToString(name_index, CONSTANT_NameAndType);
166 if (field_class.equals(class_name)) {
167 ref = "<A HREF=\"" + field_class + "_methods.html#field" + field_name
168 + "\" TARGET=Methods>" + field_name + "</A>";
169 } else {
170 ref = "<A HREF=\"" + field_class + ".html\" TARGET=_top>" + short_field_class
171 + "</A>." + field_name + "\n";
172 }
173 constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + class_index
174 + "\" TARGET=Constants>" + short_field_class + "</A>.<A HREF=\""
175 + class_name + "_cp.html#cp" + index + "\" TARGET=ConstantPool>"
176 + field_name + "</A>";
177 file.println("<P><TT>" + ref + "</TT><BR>\n" + "<UL>" + "<LI><A HREF=\"#cp"
178 + class_index + "\">Class(" + class_index + ")</A><BR>\n"
179 + "<LI><A HREF=\"#cp" + name_index + "\">NameAndType(" + name_index
180 + ")</A></UL>");
181 break;
182 case CONSTANT_Class:
183 ConstantClass c4 = (ConstantClass) constant_pool.getConstant(index, CONSTANT_Class);
184 name_index = c4.getNameIndex();
185 String class_name2 = constant_pool.constantToString(index, tag); // / -> .
186 String short_class_name = Utility.compactClassName(class_name2); // I.e., remove java.lang.
187 short_class_name = Utility.compactClassName(short_class_name, class_package + ".",
188 true); // Remove class package prefix
189 ref = "<A HREF=\"" + class_name2 + ".html\" TARGET=_top>" + short_class_name
190 + "</A>";
191 constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + index
192 + "\" TARGET=ConstantPool>" + short_class_name + "</A>";
193 file.println("<P><TT>" + ref + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index
194 + "\">Name index(" + name_index + ")</A></UL>\n");
195 break;
196 case CONSTANT_String:
197 ConstantString c5 = (ConstantString) constant_pool.getConstant(index,
198 CONSTANT_String);
199 name_index = c5.getStringIndex();
200 String str = Class2HTML.toHTML(constant_pool.constantToString(index, tag));
201 file.println("<P><TT>" + str + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index
202 + "\">Name index(" + name_index + ")</A></UL>\n");
203 break;
204 case CONSTANT_NameAndType:
205 ConstantNameAndType c6 = (ConstantNameAndType) constant_pool.getConstant(index,
206 CONSTANT_NameAndType);
207 name_index = c6.getNameIndex();
208 int signature_index = c6.getSignatureIndex();
209 file.println("<P><TT>"
210 + Class2HTML.toHTML(constant_pool.constantToString(index, tag))
211 + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index + "\">Name index("
212 + name_index + ")</A>\n" + "<LI><A HREF=\"#cp" + signature_index
213 + "\">Signature index(" + signature_index + ")</A></UL>\n");
214 break;
215 default:
216 file
217 .println("<P><TT>"
218 + Class2HTML.toHTML(constant_pool.constantToString(index, tag))
219 + "</TT>\n");
220 } // switch
221 }
222
223
224 private final int getMethodNumber( String str ) {
225 for (int i = 0; i < methods.length; i++) {
226 String cmp = methods[i].getName() + methods[i].getSignature();
227 if (cmp.equals(str)) {
228 return i;
229 }
230 }
231 return -1;
232 }
233 }
+0
-472
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/InstructionFinder.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Locale;
23 import java.util.Map;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26 import org.apache.bcel.Constants;
27 import org.apache.bcel.generic.ClassGenException;
28 import org.apache.bcel.generic.Instruction;
29 import org.apache.bcel.generic.InstructionHandle;
30 import org.apache.bcel.generic.InstructionList;
31
32 /**
33 * InstructionFinder is a tool to search for given instructions patterns, i.e.,
34 * match sequences of instructions in an instruction list via regular
35 * expressions. This can be used, e.g., in order to implement a peep hole
36 * optimizer that looks for code patterns and replaces them with faster
37 * equivalents.
38 *
39 * <p>
40 * This class internally uses the <a href="http://jakarta.apache.org/regexp/">
41 * Regexp</a> package to search for regular expressions.
42 *
43 * A typical application would look like this:
44 *
45 * <pre>
46 *
47 *
48 * InstructionFinder f = new InstructionFinder(il);
49 * String pat = &quot;IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)&quot;;
50 *
51 * for(Iterator i = f.search(pat, constraint); i.hasNext(); ) {
52 * InstructionHandle[] match = (InstructionHandle[])i.next();
53 * ...
54 * il.delete(match[1], match[5]);
55 * ...
56 * }
57 *
58 *
59 * </pre>
60 *
61 * @version $Id: InstructionFinder.java 386056 2006-03-15 11:31:56Z tcurdt $
62 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
63 * @see Instruction
64 * @see InstructionList
65 */
66 public class InstructionFinder {
67
68 private static final int OFFSET = 32767; // char + OFFSET is
69 // outside of
70 // LATIN-1
71 private static final int NO_OPCODES = 256; // Potential number,
72 // some are not used
73 private static final Map map = new HashMap(); // Map<String,Pattern>
74 private InstructionList il;
75 private String il_string; // instruction list
76 // as string
77 private InstructionHandle[] handles; // map instruction
78
79
80 // list to array
81 /**
82 * @param il
83 * instruction list to search for given patterns
84 */
85 public InstructionFinder(InstructionList il) {
86 this.il = il;
87 reread();
88 }
89
90
91 /**
92 * Reread the instruction list, e.g., after you've altered the list upon a
93 * match.
94 */
95 public final void reread() {
96 int size = il.getLength();
97 char[] buf = new char[size]; // Create a string with length equal to il
98 // length
99 handles = il.getInstructionHandles();
100 // Map opcodes to characters
101 for (int i = 0; i < size; i++) {
102 buf[i] = makeChar(handles[i].getInstruction().getOpcode());
103 }
104 il_string = new String(buf);
105 }
106
107
108 /**
109 * Map symbolic instruction names like "getfield" to a single character.
110 *
111 * @param pattern
112 * instruction pattern in lower case
113 * @return encoded string for a pattern such as "BranchInstruction".
114 */
115 private static final String mapName( String pattern ) {
116 String result = (String) map.get(pattern);
117 if (result != null) {
118 return result;
119 }
120 for (short i = 0; i < NO_OPCODES; i++) {
121 if (pattern.equals(Constants.OPCODE_NAMES[i])) {
122 return "" + makeChar(i);
123 }
124 }
125 throw new RuntimeException("Instruction unknown: " + pattern);
126 }
127
128
129 /**
130 * Replace symbolic names of instructions with the appropiate character and
131 * remove all white space from string. Meta characters such as +, * are
132 * ignored.
133 *
134 * @param pattern
135 * The pattern to compile
136 * @return translated regular expression string
137 */
138 private static final String compilePattern( String pattern ) {
139 //Bug: 38787 - Instructions are assumed to be english, to avoid odd Locale issues
140 String lower = pattern.toLowerCase(Locale.ENGLISH);
141 StringBuffer buf = new StringBuffer();
142 int size = pattern.length();
143 for (int i = 0; i < size; i++) {
144 char ch = lower.charAt(i);
145 if (Character.isLetterOrDigit(ch)) {
146 StringBuffer name = new StringBuffer();
147 while ((Character.isLetterOrDigit(ch) || ch == '_') && i < size) {
148 name.append(ch);
149 if (++i < size) {
150 ch = lower.charAt(i);
151 } else {
152 break;
153 }
154 }
155 i--;
156 buf.append(mapName(name.toString()));
157 } else if (!Character.isWhitespace(ch)) {
158 buf.append(ch);
159 }
160 }
161 return buf.toString();
162 }
163
164
165 /**
166 * @return the matched piece of code as an array of instruction (handles)
167 */
168 private InstructionHandle[] getMatch( int matched_from, int match_length ) {
169 InstructionHandle[] match = new InstructionHandle[match_length];
170 System.arraycopy(handles, matched_from, match, 0, match_length);
171 return match;
172 }
173
174
175 /**
176 * Search for the given pattern in the instruction list. You can search for
177 * any valid opcode via its symbolic name, e.g. "istore". You can also use a
178 * super class or an interface name to match a whole set of instructions, e.g.
179 * "BranchInstruction" or "LoadInstruction". "istore" is also an alias for all
180 * "istore_x" instructions. Additional aliases are "if" for "ifxx", "if_icmp"
181 * for "if_icmpxx", "if_acmp" for "if_acmpxx".
182 *
183 * Consecutive instruction names must be separated by white space which will
184 * be removed during the compilation of the pattern.
185 *
186 * For the rest the usual pattern matching rules for regular expressions
187 * apply.
188 * <P>
189 * Example pattern:
190 *
191 * <pre>
192 * search(&quot;BranchInstruction NOP ((IfInstruction|GOTO)+ ISTORE Instruction)*&quot;);
193 * </pre>
194 *
195 * <p>
196 * If you alter the instruction list upon a match such that other matching
197 * areas are affected, you should call reread() to update the finder and call
198 * search() again, because the matches are cached.
199 *
200 * @param pattern
201 * the instruction pattern to search for, where case is ignored
202 * @param from
203 * where to start the search in the instruction list
204 * @param constraint
205 * optional CodeConstraint to check the found code pattern for
206 * user-defined constraints
207 * @return iterator of matches where e.nextElement() returns an array of
208 * instruction handles describing the matched area
209 */
210 public final Iterator search( String pattern, InstructionHandle from, CodeConstraint constraint ) {
211 String search = compilePattern(pattern);
212 int start = -1;
213 for (int i = 0; i < handles.length; i++) {
214 if (handles[i] == from) {
215 start = i; // Where to start search from (index)
216 break;
217 }
218 }
219 if (start == -1) {
220 throw new ClassGenException("Instruction handle " + from
221 + " not found in instruction list.");
222 }
223 Pattern regex = Pattern.compile(search);
224 List matches = new ArrayList();
225 Matcher matcher = regex.matcher(il_string);
226 while (start < il_string.length() && matcher.find(start)) {
227 int startExpr = matcher.start();
228 int endExpr = matcher.end();
229 int lenExpr = (endExpr - startExpr) + 1;
230 InstructionHandle[] match = getMatch(startExpr, lenExpr);
231 if ((constraint == null) || constraint.checkCode(match)) {
232 matches.add(match);
233 }
234 start = endExpr;
235 }
236 return matches.iterator();
237 }
238
239
240 /**
241 * Start search beginning from the start of the given instruction list.
242 *
243 * @param pattern
244 * the instruction pattern to search for, where case is ignored
245 * @return iterator of matches where e.nextElement() returns an array of
246 * instruction handles describing the matched area
247 */
248 public final Iterator search( String pattern ) {
249 return search(pattern, il.getStart(), null);
250 }
251
252
253 /**
254 * Start search beginning from `from'.
255 *
256 * @param pattern
257 * the instruction pattern to search for, where case is ignored
258 * @param from
259 * where to start the search in the instruction list
260 * @return iterator of matches where e.nextElement() returns an array of
261 * instruction handles describing the matched area
262 */
263 public final Iterator search( String pattern, InstructionHandle from ) {
264 return search(pattern, from, null);
265 }
266
267
268 /**
269 * Start search beginning from the start of the given instruction list. Check
270 * found matches with the constraint object.
271 *
272 * @param pattern
273 * the instruction pattern to search for, case is ignored
274 * @param constraint
275 * constraints to be checked on matching code
276 * @return instruction handle or `null' if the match failed
277 */
278 public final Iterator search( String pattern, CodeConstraint constraint ) {
279 return search(pattern, il.getStart(), constraint);
280 }
281
282
283 /**
284 * Convert opcode number to char.
285 */
286 private static final char makeChar( short opcode ) {
287 return (char) (opcode + OFFSET);
288 }
289
290
291 /**
292 * @return the inquired instruction list
293 */
294 public final InstructionList getInstructionList() {
295 return il;
296 }
297
298 /**
299 * Code patterns found may be checked using an additional user-defined
300 * constraint object whether they really match the needed criterion. I.e.,
301 * check constraints that can not expressed with regular expressions.
302 *
303 */
304 public static interface CodeConstraint {
305
306 /**
307 * @param match
308 * array of instructions matching the requested pattern
309 * @return true if the matched area is really useful
310 */
311 public boolean checkCode( InstructionHandle[] match );
312 }
313
314 // Initialize pattern map
315 static {
316 map
317 .put(
318 "arithmeticinstruction",
319 "(irem|lrem|iand|ior|ineg|isub|lneg|fneg|fmul|ldiv|fadd|lxor|frem|idiv|land|ixor|ishr|fsub|lshl|fdiv|iadd|lor|dmul|lsub|ishl|imul|lmul|lushr|dneg|iushr|lshr|ddiv|drem|dadd|ladd|dsub)");
320 map.put("invokeinstruction", "(invokevirtual|invokeinterface|invokestatic|invokespecial)");
321 map
322 .put(
323 "arrayinstruction",
324 "(baload|aastore|saload|caload|fastore|lastore|iaload|castore|iastore|aaload|bastore|sastore|faload|laload|daload|dastore)");
325 map.put("gotoinstruction", "(goto|goto_w)");
326 map.put("conversioninstruction",
327 "(d2l|l2d|i2s|d2i|l2i|i2b|l2f|d2f|f2i|i2d|i2l|f2d|i2c|f2l|i2f)");
328 map.put("localvariableinstruction",
329 "(fstore|iinc|lload|dstore|dload|iload|aload|astore|istore|fload|lstore)");
330 map.put("loadinstruction", "(fload|dload|lload|iload|aload)");
331 map.put("fieldinstruction", "(getfield|putstatic|getstatic|putfield)");
332 map
333 .put(
334 "cpinstruction",
335 "(ldc2_w|invokeinterface|multianewarray|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|ldc_w|invokestatic|invokevirtual|putfield|ldc|new|anewarray)");
336 map.put("stackinstruction", "(dup2|swap|dup2_x2|pop|pop2|dup|dup2_x1|dup_x2|dup_x1)");
337 map
338 .put(
339 "branchinstruction",
340 "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)");
341 map.put("returninstruction", "(lreturn|ireturn|freturn|dreturn|areturn|return)");
342 map.put("storeinstruction", "(istore|fstore|dstore|astore|lstore)");
343 map.put("select", "(tableswitch|lookupswitch)");
344 map
345 .put(
346 "ifinstruction",
347 "(ifeq|ifgt|if_icmpne|if_icmpeq|ifge|ifnull|ifne|if_icmple|if_icmpge|if_acmpeq|if_icmplt|if_acmpne|ifnonnull|iflt|if_icmpgt|ifle)");
348 map.put("jsrinstruction", "(jsr|jsr_w)");
349 map.put("variablelengthinstruction", "(tableswitch|jsr|goto|lookupswitch)");
350 map.put("unconditionalbranch", "(goto|jsr|jsr_w|athrow|goto_w)");
351 map.put("constantpushinstruction", "(dconst|bipush|sipush|fconst|iconst|lconst)");
352 map
353 .put(
354 "typedinstruction",
355 "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dastore|ret|f2d|f2i|drem|iinc|i2c|checkcast|frem|lreturn|astore|lushr|daload|dneg|fastore|istore|lshl|ldiv|lstore|areturn|ishr|ldc_w|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|faload|sipush|iushr|caload|instanceof|invokespecial|putfield|fmul|ireturn|laload|d2f|lneg|ixor|i2l|fdiv|lastore|multianewarray|i2b|getstatic|i2d|putstatic|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|freturn|ldc|aconst_null|castore|lmul|ldc2_w|dadd|iconst|f2l|ddiv|dstore|land|jsr|anewarray|dmul|bipush|dsub|sastore|d2i|i2s|lshr|iadd|l2i|lload|bastore|fstore|fneg|iload|fadd|baload|fconst|ior|ineg|dreturn|l2f|lconst|getfield|invokevirtual|invokestatic|iastore)");
356 map.put("popinstruction", "(fstore|dstore|pop|pop2|astore|putstatic|istore|lstore)");
357 map.put("allocationinstruction", "(multianewarray|new|anewarray|newarray)");
358 map
359 .put(
360 "indexedinstruction",
361 "(lload|lstore|fload|ldc2_w|invokeinterface|multianewarray|astore|dload|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|dstore|istore|iinc|ldc_w|ret|fstore|invokestatic|iload|putfield|invokevirtual|ldc|new|aload|anewarray)");
362 map
363 .put(
364 "pushinstruction",
365 "(dup|lload|dup2|bipush|fload|ldc2_w|sipush|lconst|fconst|dload|getstatic|ldc_w|aconst_null|dconst|iload|ldc|iconst|aload)");
366 map
367 .put(
368 "stackproducer",
369 "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dup|f2d|f2i|drem|i2c|checkcast|frem|lushr|daload|dneg|lshl|ldiv|ishr|ldc_w|invokeinterface|lxor|ishl|l2d|i2f|faload|sipush|iushr|caload|instanceof|invokespecial|fmul|laload|d2f|lneg|ixor|i2l|fdiv|getstatic|i2b|swap|i2d|dup2|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|ldc|arraylength|aconst_null|tableswitch|lmul|ldc2_w|iconst|dadd|f2l|ddiv|land|jsr|anewarray|dmul|bipush|dsub|d2i|newarray|i2s|lshr|iadd|lload|l2i|fneg|iload|fadd|baload|fconst|lookupswitch|ior|ineg|lconst|l2f|getfield|invokevirtual|invokestatic)");
370 map
371 .put(
372 "stackconsumer",
373 "(imul|lsub|lor|iflt|fcmpg|if_icmpgt|iand|ifeq|if_icmplt|lrem|ifnonnull|idiv|d2l|isub|dcmpg|dastore|if_icmpeq|f2d|f2i|drem|i2c|checkcast|frem|lreturn|astore|lushr|pop2|monitorexit|dneg|fastore|istore|lshl|ldiv|lstore|areturn|if_icmpge|ishr|monitorenter|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|iushr|instanceof|invokespecial|fmul|ireturn|d2f|lneg|ixor|pop|i2l|ifnull|fdiv|lastore|i2b|if_acmpeq|ifge|swap|i2d|putstatic|fcmpl|ladd|irem|dcmpl|fsub|freturn|ifgt|castore|lmul|dadd|f2l|ddiv|dstore|land|if_icmpne|if_acmpne|dmul|dsub|sastore|ifle|d2i|i2s|lshr|iadd|l2i|bastore|fstore|fneg|fadd|ior|ineg|ifne|dreturn|l2f|if_icmple|getfield|invokevirtual|invokestatic|iastore)");
374 map
375 .put(
376 "exceptionthrower",
377 "(irem|lrem|laload|putstatic|baload|dastore|areturn|getstatic|ldiv|anewarray|iastore|castore|idiv|saload|lastore|fastore|putfield|lreturn|caload|getfield|return|aastore|freturn|newarray|instanceof|multianewarray|athrow|faload|iaload|aaload|dreturn|monitorenter|checkcast|bastore|arraylength|new|invokevirtual|sastore|ldc_w|ireturn|invokespecial|monitorexit|invokeinterface|ldc|invokestatic|daload)");
378 map
379 .put(
380 "loadclass",
381 "(multianewarray|invokeinterface|instanceof|invokespecial|putfield|checkcast|putstatic|invokevirtual|new|getstatic|invokestatic|getfield|anewarray)");
382 map
383 .put(
384 "instructiontargeter",
385 "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)");
386 // Some aliases
387 map.put("if_icmp", "(if_icmpne|if_icmpeq|if_icmple|if_icmpge|if_icmplt|if_icmpgt)");
388 map.put("if_acmp", "(if_acmpeq|if_acmpne)");
389 map.put("if", "(ifeq|ifne|iflt|ifge|ifgt|ifle)");
390 // Precompile some aliases first
391 map.put("iconst", precompile(Constants.ICONST_0, Constants.ICONST_5, Constants.ICONST_M1));
392 map.put("lconst", new String(new char[] {
393 '(', makeChar(Constants.LCONST_0), '|', makeChar(Constants.LCONST_1), ')'
394 }));
395 map.put("dconst", new String(new char[] {
396 '(', makeChar(Constants.DCONST_0), '|', makeChar(Constants.DCONST_1), ')'
397 }));
398 map.put("fconst", new String(new char[] {
399 '(', makeChar(Constants.FCONST_0), '|', makeChar(Constants.FCONST_1), ')'
400 }));
401 map.put("iload", precompile(Constants.ILOAD_0, Constants.ILOAD_3, Constants.ILOAD));
402 map.put("dload", precompile(Constants.DLOAD_0, Constants.DLOAD_3, Constants.DLOAD));
403 map.put("fload", precompile(Constants.FLOAD_0, Constants.FLOAD_3, Constants.FLOAD));
404 map.put("aload", precompile(Constants.ALOAD_0, Constants.ALOAD_3, Constants.ALOAD));
405 map.put("istore", precompile(Constants.ISTORE_0, Constants.ISTORE_3, Constants.ISTORE));
406 map.put("dstore", precompile(Constants.DSTORE_0, Constants.DSTORE_3, Constants.DSTORE));
407 map.put("fstore", precompile(Constants.FSTORE_0, Constants.FSTORE_3, Constants.FSTORE));
408 map.put("astore", precompile(Constants.ASTORE_0, Constants.ASTORE_3, Constants.ASTORE));
409 // Compile strings
410 for (Iterator i = map.keySet().iterator(); i.hasNext();) {
411 String key = (String) i.next();
412 String value = (String) map.get(key);
413 char ch = value.charAt(1); // Omit already precompiled patterns
414 if (ch < OFFSET) {
415 map.put(key, compilePattern(value)); // precompile all patterns
416 }
417 }
418 // Add instruction alias to match anything
419 StringBuffer buf = new StringBuffer("(");
420 for (short i = 0; i < NO_OPCODES; i++) {
421 if (Constants.NO_OF_OPERANDS[i] != Constants.UNDEFINED) { // Not an
422 // invalid
423 // opcode
424 buf.append(makeChar(i));
425 if (i < NO_OPCODES - 1) {
426 buf.append('|');
427 }
428 }
429 }
430 buf.append(')');
431 map.put("instruction", buf.toString());
432 }
433
434
435 private static String precompile( short from, short to, short extra ) {
436 StringBuffer buf = new StringBuffer("(");
437 for (short i = from; i <= to; i++) {
438 buf.append(makeChar(i));
439 buf.append('|');
440 }
441 buf.append(makeChar(extra));
442 buf.append(")");
443 return buf.toString();
444 }
445
446
447 /*
448 * Internal debugging routines.
449 */
450 private static final String pattern2string( String pattern ) {
451 return pattern2string(pattern, true);
452 }
453
454
455 private static final String pattern2string( String pattern, boolean make_string ) {
456 StringBuffer buf = new StringBuffer();
457 for (int i = 0; i < pattern.length(); i++) {
458 char ch = pattern.charAt(i);
459 if (ch >= OFFSET) {
460 if (make_string) {
461 buf.append(Constants.OPCODE_NAMES[ch - OFFSET]);
462 } else {
463 buf.append((ch - OFFSET));
464 }
465 } else {
466 buf.append(ch);
467 }
468 }
469 return buf.toString();
470 }
471 }
+0
-117
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/JavaWrapper.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.lang.reflect.Method;
19 import java.lang.reflect.Modifier;
20
21 /**
22 * Java interpreter replacement, i.e., wrapper that uses its own ClassLoader
23 * to modify/generate classes as they're requested. You can take this as a template
24 * for your own applications.<br>
25 * Call this wrapper with
26 * <pre>java org.apache.bcel.util.JavaWrapper &lt;real.class.name&gt; [arguments]</pre>
27 * <p>
28 * To use your own class loader you can set the "bcel.classloader" system property
29 * which defaults to "org.apache.bcel.util.ClassLoader", e.g., with
30 * <pre>java org.apache.bcel.util.JavaWrapper -Dbcel.classloader=foo.MyLoader &lt;real.class.name&gt; [arguments]</pre>
31 * </p>
32 *
33 * @version $Id: JavaWrapper.java 386056 2006-03-15 11:31:56Z tcurdt $
34 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35 * @see ClassLoader
36 */
37 public class JavaWrapper {
38
39 private java.lang.ClassLoader loader;
40
41
42 private static java.lang.ClassLoader getClassLoader() {
43 String s = System.getProperty("bcel.classloader");
44 if ((s == null) || "".equals(s)) {
45 s = "org.apache.bcel.util.ClassLoader";
46 }
47 try {
48 return (java.lang.ClassLoader) Class.forName(s).newInstance();
49 } catch (Exception e) {
50 throw new RuntimeException(e.toString());
51 }
52 }
53
54
55 public JavaWrapper(java.lang.ClassLoader loader) {
56 this.loader = loader;
57 }
58
59
60 public JavaWrapper() {
61 this(getClassLoader());
62 }
63
64
65 /** Runs the main method of the given class with the arguments passed in argv
66 *
67 * @param class_name the fully qualified class name
68 * @param argv the arguments just as you would pass them directly
69 */
70 public void runMain( String class_name, String[] argv ) throws ClassNotFoundException {
71 Class cl = loader.loadClass(class_name);
72 Method method = null;
73 try {
74 method = cl.getMethod("main", new Class[] {
75 argv.getClass()
76 });
77 /* Method main is sane ?
78 */
79 int m = method.getModifiers();
80 Class r = method.getReturnType();
81 if (!(Modifier.isPublic(m) && Modifier.isStatic(m)) || Modifier.isAbstract(m)
82 || (r != Void.TYPE)) {
83 throw new NoSuchMethodException();
84 }
85 } catch (NoSuchMethodException no) {
86 System.out.println("In class " + class_name
87 + ": public static void main(String[] argv) is not defined");
88 return;
89 }
90 try {
91 method.invoke(null, new Object[] {
92 argv
93 });
94 } catch (Exception ex) {
95 ex.printStackTrace();
96 }
97 }
98
99
100 /** Default main method used as wrapper, expects the fully qualified class name
101 * of the real class as the first argument.
102 */
103 public static void main( String[] argv ) throws Exception {
104 /* Expects class name as first argument, other arguments are by-passed.
105 */
106 if (argv.length == 0) {
107 System.out.println("Missing class name.");
108 return;
109 }
110 String class_name = argv[0];
111 String[] new_argv = new String[argv.length - 1];
112 System.arraycopy(argv, 1, new_argv, 0, new_argv.length);
113 JavaWrapper wrapper = new JavaWrapper();
114 wrapper.runMain(class_name, new_argv);
115 }
116 }
+0
-156
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/MethodHTML.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.FileOutputStream;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import org.apache.bcel.classfile.Attribute;
22 import org.apache.bcel.classfile.Code;
23 import org.apache.bcel.classfile.ConstantValue;
24 import org.apache.bcel.classfile.ExceptionTable;
25 import org.apache.bcel.classfile.Field;
26 import org.apache.bcel.classfile.Method;
27 import org.apache.bcel.classfile.Utility;
28
29 /**
30 * Convert methods and fields into HTML file.
31 *
32 * @version $Id: MethodHTML.java 386056 2006-03-15 11:31:56Z tcurdt $
33 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34 *
35 */
36 final class MethodHTML implements org.apache.bcel.Constants {
37
38 private String class_name; // name of current class
39 private PrintWriter file; // file to write to
40 private ConstantHTML constant_html;
41 private AttributeHTML attribute_html;
42
43
44 MethodHTML(String dir, String class_name, Method[] methods, Field[] fields,
45 ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException {
46 this.class_name = class_name;
47 this.attribute_html = attribute_html;
48 this.constant_html = constant_html;
49 file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"));
50 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
51 file.println("<TR><TH ALIGN=LEFT>Access&nbsp;flags</TH><TH ALIGN=LEFT>Type</TH>"
52 + "<TH ALIGN=LEFT>Field&nbsp;name</TH></TR>");
53 for (int i = 0; i < fields.length; i++) {
54 writeField(fields[i]);
55 }
56 file.println("</TABLE>");
57 file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access&nbsp;flags</TH>"
58 + "<TH ALIGN=LEFT>Return&nbsp;type</TH><TH ALIGN=LEFT>Method&nbsp;name</TH>"
59 + "<TH ALIGN=LEFT>Arguments</TH></TR>");
60 for (int i = 0; i < methods.length; i++) {
61 writeMethod(methods[i], i);
62 }
63 file.println("</TABLE></BODY></HTML>");
64 file.close();
65 }
66
67
68 /**
69 * Print field of class.
70 *
71 * @param field field to print
72 * @exception java.io.IOException
73 */
74 private void writeField( Field field ) throws IOException {
75 String type = Utility.signatureToString(field.getSignature());
76 String name = field.getName();
77 String access = Utility.accessToString(field.getAccessFlags());
78 Attribute[] attributes;
79 access = Utility.replace(access, " ", "&nbsp;");
80 file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>"
81 + Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + name
82 + "</A></TD>");
83 attributes = field.getAttributes();
84 // Write them to the Attributes.html file with anchor "<name>[<i>]"
85 for (int i = 0; i < attributes.length; i++) {
86 attribute_html.writeAttribute(attributes[i], name + "@" + i);
87 }
88 for (int i = 0; i < attributes.length; i++) {
89 if (attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
90 String str = ((ConstantValue) attributes[i]).toString();
91 // Reference attribute in _attributes.html
92 file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + name + "@" + i
93 + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
94 break;
95 }
96 }
97 file.println("</TR>");
98 }
99
100
101 private final void writeMethod( Method method, int method_number ) throws IOException {
102 // Get raw signature
103 String signature = method.getSignature();
104 // Get array of strings containing the argument types
105 String[] args = Utility.methodSignatureArgumentTypes(signature, false);
106 // Get return type string
107 String type = Utility.methodSignatureReturnType(signature, false);
108 // Get method name
109 String name = method.getName(), html_name;
110 // Get method's access flags
111 String access = Utility.accessToString(method.getAccessFlags());
112 // Get the method's attributes, the Code Attribute in particular
113 Attribute[] attributes = method.getAttributes();
114 /* HTML doesn't like names like <clinit> and spaces are places to break
115 * lines. Both we don't want...
116 */
117 access = Utility.replace(access, " ", "&nbsp;");
118 html_name = Class2HTML.toHTML(name);
119 file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number
120 + ">" + access + "</A></FONT></TD>");
121 file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" + "<A HREF=" + class_name
122 + "_code.html#method" + method_number + " TARGET=Code>" + html_name
123 + "</A></TD>\n<TD>(");
124 for (int i = 0; i < args.length; i++) {
125 file.print(Class2HTML.referenceType(args[i]));
126 if (i < args.length - 1) {
127 file.print(", ");
128 }
129 }
130 file.print(")</TD></TR>");
131 // Check for thrown exceptions
132 for (int i = 0; i < attributes.length; i++) {
133 attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i,
134 method_number);
135 byte tag = attributes[i].getTag();
136 if (tag == ATTR_EXCEPTIONS) {
137 file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>");
138 int[] exceptions = ((ExceptionTable) attributes[i]).getExceptionIndexTable();
139 for (int j = 0; j < exceptions.length; j++) {
140 file.print(constant_html.referenceConstant(exceptions[j]));
141 if (j < exceptions.length - 1) {
142 file.print(", ");
143 }
144 }
145 file.println("</TD></TR>");
146 } else if (tag == ATTR_CODE) {
147 Attribute[] c_a = ((Code) attributes[i]).getAttributes();
148 for (int j = 0; j < c_a.length; j++) {
149 attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@"
150 + j, method_number);
151 }
152 }
153 }
154 }
155 }
+0
-73
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/Repository.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import org.apache.bcel.classfile.JavaClass;
19
20 /**
21 * Abstract definition of a class repository. Instances may be used
22 * to load classes from different sources and may be used in the
23 * Repository.setRepository method.
24 *
25 * @see org.apache.bcel.Repository
26 * @version $Id: Repository.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 * @author David Dixon-Peugh
29 */
30 public interface Repository extends java.io.Serializable {
31
32 /**
33 * Store the provided class under "clazz.getClassName()"
34 */
35 public void storeClass( JavaClass clazz );
36
37
38 /**
39 * Remove class from repository
40 */
41 public void removeClass( JavaClass clazz );
42
43
44 /**
45 * Find the class with the name provided, if the class
46 * isn't there, return NULL.
47 */
48 public JavaClass findClass( String className );
49
50
51 /**
52 * Find the class with the name provided, if the class
53 * isn't there, make an attempt to load it.
54 */
55 public JavaClass loadClass( String className ) throws java.lang.ClassNotFoundException;
56
57
58 /**
59 * Find the JavaClass instance for the given run-time class object
60 */
61 public JavaClass loadClass( Class clazz ) throws java.lang.ClassNotFoundException;
62
63
64 /** Clear all entries from cache.
65 */
66 public void clear();
67
68
69 /** Get the ClassPath associated with this Repository
70 */
71 public ClassPath getClassPath();
72 }
+0
-190
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/SyntheticRepository.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.util;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.lang.ref.SoftReference;
21 import java.util.HashMap;
22 import java.util.Map;
23 import org.apache.bcel.classfile.ClassParser;
24 import org.apache.bcel.classfile.JavaClass;
25
26 /**
27 * This repository is used in situations where a Class is created
28 * outside the realm of a ClassLoader. Classes are loaded from
29 * the file systems using the paths specified in the given
30 * class path. By default, this is the value returned by
31 * ClassPath.getClassPath().
32 * <br>
33 * It is designed to be used as a singleton, however it
34 * can also be used with custom classpaths.
35 *
36 /**
37 * Abstract definition of a class repository. Instances may be used
38 * to load classes from different sources and may be used in the
39 * Repository.setRepository method.
40 *
41 * @see org.apache.bcel.Repository
42 *
43 * @version $Id: SyntheticRepository.java 386056 2006-03-15 11:31:56Z tcurdt $
44 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
45 * @author David Dixon-Peugh
46 */
47 public class SyntheticRepository implements Repository {
48
49 private static final String DEFAULT_PATH = ClassPath.getClassPath();
50 private static Map _instances = new HashMap(); // CLASSPATH X REPOSITORY
51 private ClassPath _path = null;
52 private Map _loadedClasses = new HashMap(); // CLASSNAME X JAVACLASS
53
54
55 private SyntheticRepository(ClassPath path) {
56 _path = path;
57 }
58
59
60 public static SyntheticRepository getInstance() {
61 return getInstance(ClassPath.SYSTEM_CLASS_PATH);
62 }
63
64
65 public static SyntheticRepository getInstance( ClassPath classPath ) {
66 SyntheticRepository rep = (SyntheticRepository) _instances.get(classPath);
67 if (rep == null) {
68 rep = new SyntheticRepository(classPath);
69 _instances.put(classPath, rep);
70 }
71 return rep;
72 }
73
74
75 /**
76 * Store a new JavaClass instance into this Repository.
77 */
78 public void storeClass( JavaClass clazz ) {
79 _loadedClasses.put(clazz.getClassName(), new SoftReference(clazz));
80 clazz.setRepository(this);
81 }
82
83
84 /**
85 * Remove class from repository
86 */
87 public void removeClass( JavaClass clazz ) {
88 _loadedClasses.remove(clazz.getClassName());
89 }
90
91
92 /**
93 * Find an already defined (cached) JavaClass object by name.
94 */
95 public JavaClass findClass( String className ) {
96 SoftReference ref = (SoftReference) _loadedClasses.get(className);
97 if (ref == null) {
98 return null;
99 }
100 return (JavaClass) ref.get();
101 }
102
103
104 /**
105 * Find a JavaClass object by name.
106 * If it is already in this Repository, the Repository version
107 * is returned. Otherwise, the Repository's classpath is searched for
108 * the class (and it is added to the Repository if found).
109 *
110 * @param className the name of the class
111 * @return the JavaClass object
112 * @throws ClassNotFoundException if the class is not in the
113 * Repository, and could not be found on the classpath
114 */
115 public JavaClass loadClass( String className ) throws ClassNotFoundException {
116 if (className == null || className.equals("")) {
117 throw new IllegalArgumentException("Invalid class name " + className);
118 }
119 className = className.replace('/', '.'); // Just in case, canonical form
120 JavaClass clazz = findClass(className);
121 if (clazz != null) {
122 return clazz;
123 }
124 try {
125 return loadClass(_path.getInputStream(className), className);
126 } catch (IOException e) {
127 throw new ClassNotFoundException("Exception while looking for class " + className
128 + ": " + e.toString());
129 }
130 }
131
132
133 /**
134 * Find the JavaClass object for a runtime Class object.
135 * If a class with the same name is already in this Repository,
136 * the Repository version is returned. Otherwise, getResourceAsStream()
137 * is called on the Class object to find the class's representation.
138 * If the representation is found, it is added to the Repository.
139 *
140 * @see Class
141 * @param clazz the runtime Class object
142 * @return JavaClass object for given runtime class
143 * @throws ClassNotFoundException if the class is not in the
144 * Repository, and its representation could not be found
145 */
146 public JavaClass loadClass( Class clazz ) throws ClassNotFoundException {
147 String className = clazz.getName();
148 JavaClass repositoryClass = findClass(className);
149 if (repositoryClass != null) {
150 return repositoryClass;
151 }
152 String name = className;
153 int i = name.lastIndexOf('.');
154 if (i > 0) {
155 name = name.substring(i + 1);
156 }
157 return loadClass(clazz.getResourceAsStream(name + ".class"), className);
158 }
159
160
161 private JavaClass loadClass( InputStream is, String className ) throws ClassNotFoundException {
162 try {
163 if (is != null) {
164 ClassParser parser = new ClassParser(is, className);
165 JavaClass clazz = parser.parse();
166 storeClass(clazz);
167 return clazz;
168 }
169 } catch (IOException e) {
170 throw new ClassNotFoundException("Exception while looking for class " + className
171 + ": " + e.toString());
172 }
173 throw new ClassNotFoundException("SyntheticRepository could not load " + className);
174 }
175
176
177 /** ClassPath associated with the Repository.
178 */
179 public ClassPath getClassPath() {
180 return _path;
181 }
182
183
184 /** Clear all entries from cache.
185 */
186 public void clear() {
187 _loadedClasses.clear();
188 }
189 }
+0
-25
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/util/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 152878 2003-12-16 23:24:10Z enver $
5 -->
6 </head>
7 <body bgcolor="white">
8 <p>
9 This package contains utility classes for the
10 <a href="http://jakarta.apache.org/bcel/">Byte Code Engineering
11 Library</a>, namely:
12 </p>
13 <p>
14 <ul>
15 <li>Collection classes for JavaClass objects</li>
16 <li>A converter for class files to HTML</li>
17 <li>A tool to find instructions patterns via regular expressions</li>
18 <li>A class to find classes as defined in the CLASSPATH</li>
19 <li>A class loader that allows to create classes at run time</li>
20 </ul>
21
22 </p>
23 </body>
24 </html>
+0
-72
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/GraphicalVerifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.awt.Dimension;
19 import java.awt.Toolkit;
20 import javax.swing.UIManager;
21 import org.apache.bcel.generic.Type;
22
23 /**
24 * A graphical user interface application demonstrating JustIce.
25 *
26 * @version $Id: GraphicalVerifier.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author Enver Haase
28 */
29 public class GraphicalVerifier {
30
31 boolean packFrame = false;
32
33
34 /** Constructor. */
35 public GraphicalVerifier() {
36 VerifierAppFrame frame = new VerifierAppFrame();
37 //Frames überprüfen, die voreingestellte Größe haben
38 //Frames packen, die nutzbare bevorzugte Größeninformationen enthalten, z.B. aus ihrem Layout
39 if (packFrame) {
40 frame.pack();
41 } else {
42 frame.validate();
43 }
44 //Das Fenster zentrieren
45 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
46 Dimension frameSize = frame.getSize();
47 if (frameSize.height > screenSize.height) {
48 frameSize.height = screenSize.height;
49 }
50 if (frameSize.width > screenSize.width) {
51 frameSize.width = screenSize.width;
52 }
53 frame.setLocation((screenSize.width - frameSize.width) / 2,
54 (screenSize.height - frameSize.height) / 2);
55 frame.setVisible(true);
56 frame.classNamesJList.setModel(new VerifierFactoryListModel());
57 VerifierFactory.getVerifier(Type.OBJECT.getClassName()); // Fill list with java.lang.Object
58 frame.classNamesJList.setSelectedIndex(0); // default, will verify java.lang.Object
59 }
60
61
62 /** Main method. */
63 public static void main( String[] args ) {
64 try {
65 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
66 } catch (Exception e) {
67 e.printStackTrace();
68 }
69 new GraphicalVerifier();
70 }
71 }
+0
-74
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/NativeVerifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 /**
19 * The NativeVerifier class implements a main(String[] args) method that's
20 * roughly compatible to the one in the Verifier class, but that uses the
21 * JVM's internal verifier for its class file verification.
22 * This can be used for comparison runs between the JVM-internal verifier
23 * and JustIce.
24 *
25 * @version $Id: NativeVerifier.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author Enver Haase
27 */
28 public abstract class NativeVerifier {
29
30 /**
31 * This class must not be instantiated.
32 */
33 private NativeVerifier() {
34 }
35
36
37 /**
38 * Works only on the first argument.
39 */
40 public static void main( String[] args ) {
41 if (args.length != 1) {
42 System.out.println("Verifier front-end: need exactly one argument.");
43 System.exit(1);
44 }
45 int dotclasspos = args[0].lastIndexOf(".class");
46 if (dotclasspos != -1) {
47 args[0] = args[0].substring(0, dotclasspos);
48 }
49 args[0] = args[0].replace('/', '.');
50 //System.out.println(args[0]);
51 try {
52 Class.forName(args[0]);
53 } catch (ExceptionInInitializerError eiie) { //subclass of LinkageError!
54 System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '"
55 + args[0] + "'.");
56 System.out.println(eiie);
57 System.exit(1);
58 } catch (LinkageError le) {
59 System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'.");
60 System.out.println(le);
61 System.exit(1);
62 } catch (ClassNotFoundException cnfe) {
63 System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'.");
64 System.exit(1);
65 } catch (Throwable t) {
66 System.out.println("NativeVerifier: Unspecified verification error on'" + args[0]
67 + "'.");
68 System.exit(1);
69 }
70 System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay.");
71 System.exit(0);
72 }
73 }
+0
-105
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/PassVerifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 /**
22 * A PassVerifier actually verifies a class file; it is instantiated
23 * by a Verifier.
24 * The verification should conform with a certain pass as described
25 * in The Java Virtual Machine Specification, 2nd edition.
26 * This book describes four passes. Pass one means loading the
27 * class and verifying a few static constraints. Pass two actually
28 * verifies some other constraints that could enforce loading in
29 * referenced class files. Pass three is the first pass that actually
30 * checks constraints in the code array of a method in the class file;
31 * it has two parts with the first verifying static constraints and
32 * the second part verifying structural constraints (where a data flow
33 * analysis is used for). The fourth pass, finally, performs checks
34 * that can only be done at run-time.
35 * JustIce does not have a run-time pass, but certain constraints that
36 * are usually delayed until run-time for performance reasons are also
37 * checked during the second part of pass three.
38 * PassVerifier instances perform caching.
39 * That means, if you really want a new verification run of a certain
40 * pass you must use a new instance of a given PassVerifier.
41 *
42 * @version $Id: PassVerifier.java 386056 2006-03-15 11:31:56Z tcurdt $
43 * @author Enver Haase
44 * @see org.apache.bcel.verifier.Verifier
45 * @see #verify()
46 */
47 public abstract class PassVerifier {
48
49 /** The (warning) messages. */
50 private List messages = new ArrayList(); //Type of elements: String
51 /** The VerificationResult cache. */
52 private VerificationResult verificationResult = null;
53
54
55 /**
56 * This method runs a verification pass conforming to the
57 * Java Virtual Machine Specification, 2nd edition, on a
58 * class file.
59 * PassVerifier instances perform caching;
60 * i.e. if the verify() method once determined a VerificationResult,
61 * then this result may be returned after every invocation of this
62 * method instead of running the verification pass anew; likewise with
63 * the result of getMessages().
64 *
65 * @see #getMessages()
66 * @see #addMessage(String)
67 */
68 public VerificationResult verify() {
69 if (verificationResult == null) {
70 verificationResult = do_verify();
71 }
72 return verificationResult;
73 }
74
75
76 /** Does the real verification work, uncached. */
77 public abstract VerificationResult do_verify();
78
79
80 /**
81 * This method adds a (warning) message to the message pool of this
82 * PassVerifier. This method is normally only internally used by
83 * BCEL's class file verifier "JustIce" and should not be used from
84 * the outside.
85 *
86 * @see #getMessages()
87 */
88 public void addMessage( String message ) {
89 messages.add(message);
90 }
91
92
93 /**
94 * Returns the (warning) messages that this PassVerifier accumulated
95 * during its do_verify()ing work.
96 *
97 * @see #addMessage(String)
98 * @see #do_verify()
99 */
100 public String[] getMessages() {
101 verify(); // create messages if not already done (cached!)
102 return (String[]) messages.toArray(new String[messages.size()]);
103 }
104 }
+0
-104
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/TransitiveHull.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import org.apache.bcel.Repository;
19 import org.apache.bcel.classfile.JavaClass;
20
21 /**
22 * This class has a main method implementing a demonstration program
23 * of how to use the VerifierFactoryObserver. It transitively verifies
24 * all class files encountered; this may take up a lot of time and,
25 * more notably, memory.
26 *
27 * @version $Id: TransitiveHull.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author Enver Haase
29 */
30 public class TransitiveHull implements VerifierFactoryObserver {
31
32 /** Used for indentation. */
33 private int indent = 0;
34
35
36 /** Not publicly instantiable. */
37 private TransitiveHull() {
38 }
39
40
41 /* Implementing VerifierFactoryObserver. */
42 public void update( String classname ) {
43 System.gc(); // avoid swapping if possible.
44 for (int i = 0; i < indent; i++) {
45 System.out.print(" ");
46 }
47 System.out.println(classname);
48 indent += 1;
49 Verifier v = VerifierFactory.getVerifier(classname);
50 VerificationResult vr;
51 vr = v.doPass1();
52 if (vr != VerificationResult.VR_OK) {
53 System.out.println("Pass 1:\n" + vr);
54 }
55 vr = v.doPass2();
56 if (vr != VerificationResult.VR_OK) {
57 System.out.println("Pass 2:\n" + vr);
58 }
59 if (vr == VerificationResult.VR_OK) {
60 try {
61 JavaClass jc = Repository.lookupClass(v.getClassName());
62 for (int i = 0; i < jc.getMethods().length; i++) {
63 vr = v.doPass3a(i);
64 if (vr != VerificationResult.VR_OK) {
65 System.out.println(v.getClassName() + ", Pass 3a, method " + i + " ['"
66 + jc.getMethods()[i] + "']:\n" + vr);
67 }
68 vr = v.doPass3b(i);
69 if (vr != VerificationResult.VR_OK) {
70 System.out.println(v.getClassName() + ", Pass 3b, method " + i + " ['"
71 + jc.getMethods()[i] + "']:\n" + vr);
72 }
73 }
74 } catch (ClassNotFoundException e) {
75 System.err.println("Could not find class " + v.getClassName() + " in Repository");
76 }
77 }
78 indent -= 1;
79 }
80
81
82 /**
83 * This method implements a demonstration program
84 * of how to use the VerifierFactoryObserver. It transitively verifies
85 * all class files encountered; this may take up a lot of time and,
86 * more notably, memory.
87 */
88 public static void main( String[] args ) {
89 if (args.length != 1) {
90 System.out.println("Need exactly one argument: The root class to verify.");
91 System.exit(1);
92 }
93 int dotclasspos = args[0].lastIndexOf(".class");
94 if (dotclasspos != -1) {
95 args[0] = args[0].substring(0, dotclasspos);
96 }
97 args[0] = args[0].replace('/', '.');
98 TransitiveHull th = new TransitiveHull();
99 VerifierFactory.attach(th);
100 VerifierFactory.getVerifier(args[0]); // the observer is called back and does the actual trick.
101 VerifierFactory.detach(th);
102 }
103 }
+0
-115
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerificationResult.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 /**
19 * A VerificationResult is what a PassVerifier returns
20 * after verifying.
21 *
22 * @version $Id: VerificationResult.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author Enver Haase
24 *
25 */
26 public class VerificationResult {
27
28 /**
29 * Constant to indicate verification has not been tried yet.
30 * This happens if some earlier verification pass did not return VERIFIED_OK.
31 */
32 public static final int VERIFIED_NOTYET = 0;
33 /** Constant to indicate verification was passed. */
34 public static final int VERIFIED_OK = 1;
35 /** Constant to indicate verfication failed. */
36 public static final int VERIFIED_REJECTED = 2;
37 /**
38 * This string is the canonical message for verifications that have not been tried yet.
39 * This happens if some earlier verification pass did not return VERIFIED_OK.
40 */
41 private static final String VERIFIED_NOTYET_MSG = "Not yet verified.";
42 /** This string is the canonical message for passed verification passes. */
43 private static final String VERIFIED_OK_MSG = "Passed verification.";
44 /**
45 * Canonical VerificationResult for not-yet-tried verifications.
46 * This happens if some earlier verification pass did not return VERIFIED_OK.
47 */
48 public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET,
49 VERIFIED_NOTYET_MSG);
50 /** Canonical VerificationResult for passed verifications. */
51 public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK,
52 VERIFIED_OK_MSG);
53 /** The numeric status. */
54 private int numeric;
55 /** The detailed message. */
56 private String detailMessage;
57
58
59 /** The usual constructor. */
60 public VerificationResult(int status, String message) {
61 numeric = status;
62 detailMessage = message;
63 }
64
65
66 /** Returns one one the VERIFIED_OK, VERIFIED_NOTYET, VERIFIED_REJECTED constants. */
67 public int getStatus() {
68 return numeric;
69 }
70
71
72 /** Returns a detailed message. */
73 public String getMessage() {
74 return detailMessage;
75 }
76
77
78 /** @return a hash code value for the object.
79 */
80 public int hashCode() {
81 return numeric ^ detailMessage.hashCode();
82 }
83
84
85 /**
86 * Returns if two VerificationResult instances are equal.
87 */
88 public boolean equals( Object o ) {
89 if (!(o instanceof VerificationResult)) {
90 return false;
91 }
92 VerificationResult other = (VerificationResult) o;
93 return ((other.numeric == this.numeric) && (other.detailMessage.equals(this.detailMessage)));
94 }
95
96
97 /**
98 * Returns a String representation of the VerificationResult.
99 */
100 public String toString() {
101 String ret = "";
102 if (numeric == VERIFIED_NOTYET) {
103 ret = "VERIFIED_NOTYET";
104 }
105 if (numeric == VERIFIED_OK) {
106 ret = "VERIFIED_OK";
107 }
108 if (numeric == VERIFIED_REJECTED) {
109 ret = "VERIFIED_REJECTED";
110 }
111 ret += "\n" + detailMessage + "\n";
112 return ret;
113 }
114 }
+0
-248
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/Verifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22 import org.apache.bcel.classfile.JavaClass;
23 import org.apache.bcel.verifier.statics.Pass1Verifier;
24 import org.apache.bcel.verifier.statics.Pass2Verifier;
25 import org.apache.bcel.verifier.statics.Pass3aVerifier;
26 import org.apache.bcel.verifier.structurals.Pass3bVerifier;
27
28 /**
29 * A Verifier instance is there to verify a class file according to The Java Virtual
30 * Machine Specification, 2nd Edition.
31 *
32 * Pass-3b-verification includes pass-3a-verification;
33 * pass-3a-verification includes pass-2-verification;
34 * pass-2-verification includes pass-1-verification.
35 *
36 * A Verifier creates PassVerifier instances to perform the actual verification.
37 * Verifier instances are usually generated by the VerifierFactory.
38 *
39 * @version $Id: Verifier.java 386056 2006-03-15 11:31:56Z tcurdt $
40 * @author Enver Haase
41 * @see org.apache.bcel.verifier.VerifierFactory
42 * @see org.apache.bcel.verifier.PassVerifier
43 */
44 public class Verifier {
45
46 /**
47 * The name of the class this verifier operates on.
48 */
49 private final String classname;
50 /** A Pass1Verifier for this Verifier instance. */
51 private Pass1Verifier p1v;
52 /** A Pass2Verifier for this Verifier instance. */
53 private Pass2Verifier p2v;
54 /** The Pass3aVerifiers for this Verifier instance. Key: Interned string specifying the method number. */
55 private Map p3avs = new HashMap();
56 /** The Pass3bVerifiers for this Verifier instance. Key: Interned string specifying the method number. */
57 private Map p3bvs = new HashMap();
58
59
60 /** Returns the VerificationResult for the given pass. */
61 public VerificationResult doPass1() {
62 if (p1v == null) {
63 p1v = new Pass1Verifier(this);
64 }
65 return p1v.verify();
66 }
67
68
69 /** Returns the VerificationResult for the given pass. */
70 public VerificationResult doPass2() {
71 if (p2v == null) {
72 p2v = new Pass2Verifier(this);
73 }
74 return p2v.verify();
75 }
76
77
78 /** Returns the VerificationResult for the given pass. */
79 public VerificationResult doPass3a( int method_no ) {
80 String key = Integer.toString(method_no);
81 Pass3aVerifier p3av;
82 p3av = (Pass3aVerifier) (p3avs.get(key));
83 if (p3avs.get(key) == null) {
84 p3av = new Pass3aVerifier(this, method_no);
85 p3avs.put(key, p3av);
86 }
87 return p3av.verify();
88 }
89
90
91 /** Returns the VerificationResult for the given pass. */
92 public VerificationResult doPass3b( int method_no ) {
93 String key = Integer.toString(method_no);
94 Pass3bVerifier p3bv;
95 p3bv = (Pass3bVerifier) (p3bvs.get(key));
96 if (p3bvs.get(key) == null) {
97 p3bv = new Pass3bVerifier(this, method_no);
98 p3bvs.put(key, p3bv);
99 }
100 return p3bv.verify();
101 }
102
103
104 /**
105 * Instantiation is done by the VerifierFactory.
106 *
107 * @see VerifierFactory
108 */
109 Verifier(String fully_qualified_classname) {
110 classname = fully_qualified_classname;
111 flush();
112 }
113
114
115 /**
116 * Returns the name of the class this verifier operates on.
117 * This is particularly interesting when this verifier was created
118 * recursively by another Verifier and you got a reference to this
119 * Verifier by the getVerifiers() method of the VerifierFactory.
120 * @see VerifierFactory
121 */
122 public final String getClassName() {
123 return classname;
124 }
125
126
127 /**
128 * Forget everything known about the class file; that means, really
129 * start a new verification of a possibly different class file from
130 * BCEL's repository.
131 *
132 */
133 public void flush() {
134 p1v = null;
135 p2v = null;
136 p3avs.clear();
137 p3bvs.clear();
138 }
139
140
141 /**
142 * This returns all the (warning) messages collected during verification.
143 * A prefix shows from which verifying pass a message originates.
144 */
145 public String[] getMessages() throws ClassNotFoundException {
146 ArrayList messages = new ArrayList();
147 if (p1v != null) {
148 String[] p1m = p1v.getMessages();
149 for (int i = 0; i < p1m.length; i++) {
150 messages.add("Pass 1: " + p1m[i]);
151 }
152 }
153 if (p2v != null) {
154 String[] p2m = p2v.getMessages();
155 for (int i = 0; i < p2m.length; i++) {
156 messages.add("Pass 2: " + p2m[i]);
157 }
158 }
159 Iterator p3as = p3avs.values().iterator();
160 while (p3as.hasNext()) {
161 Pass3aVerifier pv = (Pass3aVerifier) p3as.next();
162 String[] p3am = pv.getMessages();
163 int meth = pv.getMethodNo();
164 for (int i = 0; i < p3am.length; i++) {
165 messages.add("Pass 3a, method " + meth + " ('"
166 + org.apache.bcel.Repository.lookupClass(classname).getMethods()[meth]
167 + "'): " + p3am[i]);
168 }
169 }
170 Iterator p3bs = p3bvs.values().iterator();
171 while (p3bs.hasNext()) {
172 Pass3bVerifier pv = (Pass3bVerifier) p3bs.next();
173 String[] p3bm = pv.getMessages();
174 int meth = pv.getMethodNo();
175 for (int i = 0; i < p3bm.length; i++) {
176 messages.add("Pass 3b, method " + meth + " ('"
177 + org.apache.bcel.Repository.lookupClass(classname).getMethods()[meth]
178 + "'): " + p3bm[i]);
179 }
180 }
181 String[] ret = new String[messages.size()];
182 for (int i = 0; i < messages.size(); i++) {
183 ret[i] = (String) messages.get(i);
184 }
185 return ret;
186 }
187
188
189 /**
190 * Verifies class files.
191 * This is a simple demonstration of how the API of BCEL's
192 * class file verifier "JustIce" may be used.
193 * You should supply command-line arguments which are
194 * fully qualified namea of the classes to verify. These class files
195 * must be somewhere in your CLASSPATH (refer to Sun's
196 * documentation for questions about this) or you must have put the classes
197 * into the BCEL Repository yourself (via 'addClass(JavaClass)').
198 */
199 public static void main( String[] args ) {
200 System.out
201 .println("JustIce by Enver Haase, (C) 2001-2002.\n<http://bcel.sourceforge.net>\n<http://jakarta.apache.org/bcel>\n");
202 for (int k = 0; k < args.length; k++) {
203 try {
204 if (args[k].endsWith(".class")) {
205 int dotclasspos = args[k].lastIndexOf(".class");
206 if (dotclasspos != -1) {
207 args[k] = args[k].substring(0, dotclasspos);
208 }
209 }
210 args[k] = args[k].replace('/', '.');
211 System.out.println("Now verifying: " + args[k] + "\n");
212 Verifier v = VerifierFactory.getVerifier(args[k]);
213 VerificationResult vr;
214 vr = v.doPass1();
215 System.out.println("Pass 1:\n" + vr);
216 vr = v.doPass2();
217 System.out.println("Pass 2:\n" + vr);
218 if (vr == VerificationResult.VR_OK) {
219 JavaClass jc = org.apache.bcel.Repository.lookupClass(args[k]);
220 for (int i = 0; i < jc.getMethods().length; i++) {
221 vr = v.doPass3a(i);
222 System.out.println("Pass 3a, method number " + i + " ['"
223 + jc.getMethods()[i] + "']:\n" + vr);
224 vr = v.doPass3b(i);
225 System.out.println("Pass 3b, method number " + i + " ['"
226 + jc.getMethods()[i] + "']:\n" + vr);
227 }
228 }
229 System.out.println("Warnings:");
230 String[] warnings = v.getMessages();
231 if (warnings.length == 0) {
232 System.out.println("<none>");
233 }
234 for (int j = 0; j < warnings.length; j++) {
235 System.out.println(warnings[j]);
236 }
237 System.out.println("\n");
238 // avoid swapping.
239 v.flush();
240 org.apache.bcel.Repository.clearCache();
241 System.gc();
242 } catch (ClassNotFoundException e) {
243 e.printStackTrace();
244 }
245 }
246 }
247 }
+0
-396
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerifierAppFrame.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.awt.AWTEvent;
19 import java.awt.CardLayout;
20 import java.awt.Color;
21 import java.awt.Dimension;
22 import java.awt.GridLayout;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.WindowEvent;
25 import javax.swing.BorderFactory;
26 import javax.swing.JFrame;
27 import javax.swing.JList;
28 import javax.swing.JMenu;
29 import javax.swing.JMenuBar;
30 import javax.swing.JMenuItem;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JSplitPane;
35 import javax.swing.JTextPane;
36 import javax.swing.ListSelectionModel;
37 import javax.swing.event.ListSelectionEvent;
38 import org.apache.bcel.Repository;
39 import org.apache.bcel.classfile.JavaClass;
40
41 /**
42 * This class implements a machine-generated frame for use with
43 * the GraphicalVerfifier.
44 *
45 * @version $Id: VerifierAppFrame.java 386056 2006-03-15 11:31:56Z tcurdt $
46 * @author Enver Haase
47 * @see GraphicalVerifier
48 */
49 public class VerifierAppFrame extends JFrame {
50
51 JPanel contentPane;
52 JSplitPane jSplitPane1 = new JSplitPane();
53 JPanel jPanel1 = new JPanel();
54 JPanel jPanel2 = new JPanel();
55 JSplitPane jSplitPane2 = new JSplitPane();
56 JPanel jPanel3 = new JPanel();
57 JList classNamesJList = new JList();
58 GridLayout gridLayout1 = new GridLayout();
59 JPanel messagesPanel = new JPanel();
60 GridLayout gridLayout2 = new GridLayout();
61 JMenuBar jMenuBar1 = new JMenuBar();
62 JMenu jMenu1 = new JMenu();
63 JScrollPane jScrollPane1 = new JScrollPane();
64 JScrollPane messagesScrollPane = new JScrollPane();
65 JScrollPane jScrollPane3 = new JScrollPane();
66 GridLayout gridLayout4 = new GridLayout();
67 JScrollPane jScrollPane4 = new JScrollPane();
68 CardLayout cardLayout1 = new CardLayout();
69 private String JUSTICE_VERSION = "JustIce by Enver Haase";
70 private String current_class;
71 GridLayout gridLayout3 = new GridLayout();
72 JTextPane pass1TextPane = new JTextPane();
73 JTextPane pass2TextPane = new JTextPane();
74 JTextPane messagesTextPane = new JTextPane();
75 JMenuItem newFileMenuItem = new JMenuItem();
76 JSplitPane jSplitPane3 = new JSplitPane();
77 JSplitPane jSplitPane4 = new JSplitPane();
78 JScrollPane jScrollPane2 = new JScrollPane();
79 JScrollPane jScrollPane5 = new JScrollPane();
80 JScrollPane jScrollPane6 = new JScrollPane();
81 JScrollPane jScrollPane7 = new JScrollPane();
82 JList pass3aJList = new JList();
83 JList pass3bJList = new JList();
84 JTextPane pass3aTextPane = new JTextPane();
85 JTextPane pass3bTextPane = new JTextPane();
86 JMenu jMenu2 = new JMenu();
87 JMenuItem whatisMenuItem = new JMenuItem();
88 JMenuItem aboutMenuItem = new JMenuItem();
89
90
91 /** Constructor. */
92 public VerifierAppFrame() {
93 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
94 try {
95 jbInit();
96 } catch (Exception e) {
97 e.printStackTrace();
98 }
99 }
100
101
102 /** Initizalization of the components. */
103 private void jbInit() throws Exception {
104 //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]")));
105 contentPane = (JPanel) this.getContentPane();
106 contentPane.setLayout(cardLayout1);
107 this.setJMenuBar(jMenuBar1);
108 this.setSize(new Dimension(708, 451));
109 this.setTitle("JustIce");
110 jPanel1.setMinimumSize(new Dimension(100, 100));
111 jPanel1.setPreferredSize(new Dimension(100, 100));
112 jPanel1.setLayout(gridLayout1);
113 jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
114 jPanel2.setLayout(gridLayout2);
115 jPanel3.setMinimumSize(new Dimension(200, 100));
116 jPanel3.setPreferredSize(new Dimension(400, 400));
117 jPanel3.setLayout(gridLayout4);
118 messagesPanel.setMinimumSize(new Dimension(100, 100));
119 messagesPanel.setLayout(gridLayout3);
120 jPanel2.setMinimumSize(new Dimension(200, 100));
121 jMenu1.setText("File");
122 jScrollPane1.getViewport().setBackground(Color.red);
123 messagesScrollPane.getViewport().setBackground(Color.red);
124 messagesScrollPane.setPreferredSize(new Dimension(10, 10));
125 classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
126
127 public void valueChanged( ListSelectionEvent e ) {
128 classNamesJList_valueChanged(e);
129 }
130 });
131 classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
132 jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black));
133 jScrollPane3.setPreferredSize(new Dimension(100, 100));
134 gridLayout4.setRows(4);
135 gridLayout4.setColumns(1);
136 gridLayout4.setHgap(1);
137 jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black));
138 jScrollPane4.setPreferredSize(new Dimension(100, 100));
139 pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
140 pass1TextPane.setToolTipText("");
141 pass1TextPane.setEditable(false);
142 pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
143 pass2TextPane.setEditable(false);
144 messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder());
145 messagesTextPane.setEditable(false);
146 newFileMenuItem.setText("New...");
147 newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78,
148 java.awt.event.KeyEvent.CTRL_MASK, true));
149 newFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
150
151 public void actionPerformed( ActionEvent e ) {
152 newFileMenuItem_actionPerformed(e);
153 }
154 });
155 pass3aTextPane.setEditable(false);
156 pass3bTextPane.setEditable(false);
157 pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
158
159 public void valueChanged( ListSelectionEvent e ) {
160 pass3aJList_valueChanged(e);
161 }
162 });
163 pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
164
165 public void valueChanged( ListSelectionEvent e ) {
166 pass3bJList_valueChanged(e);
167 }
168 });
169 jMenu2.setText("Help");
170 whatisMenuItem.setText("What is...");
171 whatisMenuItem.addActionListener(new java.awt.event.ActionListener() {
172
173 public void actionPerformed( ActionEvent e ) {
174 whatisMenuItem_actionPerformed(e);
175 }
176 });
177 aboutMenuItem.setText("About");
178 aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
179
180 public void actionPerformed( ActionEvent e ) {
181 aboutMenuItem_actionPerformed(e);
182 }
183 });
184 jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM);
185 messagesPanel.add(messagesScrollPane, null);
186 messagesScrollPane.getViewport().add(messagesTextPane, null);
187 jSplitPane2.add(jPanel3, JSplitPane.TOP);
188 jPanel3.add(jScrollPane3, null);
189 jScrollPane3.getViewport().add(pass1TextPane, null);
190 jPanel3.add(jScrollPane4, null);
191 jPanel3.add(jSplitPane3, null);
192 jSplitPane3.add(jScrollPane2, JSplitPane.LEFT);
193 jScrollPane2.getViewport().add(pass3aJList, null);
194 jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT);
195 jScrollPane5.getViewport().add(pass3aTextPane, null);
196 jPanel3.add(jSplitPane4, null);
197 jSplitPane4.add(jScrollPane6, JSplitPane.LEFT);
198 jScrollPane6.getViewport().add(pass3bJList, null);
199 jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT);
200 jScrollPane7.getViewport().add(pass3bTextPane, null);
201 jScrollPane4.getViewport().add(pass2TextPane, null);
202 jSplitPane1.add(jPanel2, JSplitPane.TOP);
203 jPanel2.add(jScrollPane1, null);
204 jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
205 jPanel1.add(jSplitPane2, null);
206 jScrollPane1.getViewport().add(classNamesJList, null);
207 jMenuBar1.add(jMenu1);
208 jMenuBar1.add(jMenu2);
209 contentPane.add(jSplitPane1, "jSplitPane1");
210 jMenu1.add(newFileMenuItem);
211 jMenu2.add(whatisMenuItem);
212 jMenu2.add(aboutMenuItem);
213 jSplitPane2.setDividerLocation(300);
214 jSplitPane3.setDividerLocation(150);
215 jSplitPane4.setDividerLocation(150);
216 }
217
218
219 /** Overridden to stop the application on a closing window. */
220 protected void processWindowEvent( WindowEvent e ) {
221 super.processWindowEvent(e);
222 if (e.getID() == WindowEvent.WINDOW_CLOSING) {
223 System.exit(0);
224 }
225 }
226
227
228 synchronized void classNamesJList_valueChanged( ListSelectionEvent e ) {
229 if (e.getValueIsAdjusting()) {
230 return;
231 }
232 current_class = classNamesJList.getSelectedValue().toString();
233 try {
234 verify();
235 } catch (ClassNotFoundException ex) {
236 // FIXME: report the error using the GUI
237 ex.printStackTrace();
238 }
239 classNamesJList.setSelectedValue(current_class, true);
240 }
241
242
243 private void verify() throws ClassNotFoundException {
244 setTitle("PLEASE WAIT");
245 Verifier v = VerifierFactory.getVerifier(current_class);
246 v.flush(); // Don't cache the verification result for this class.
247 VerificationResult vr;
248 vr = v.doPass1();
249 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
250 pass1TextPane.setText(vr.getMessage());
251 pass1TextPane.setBackground(Color.red);
252 pass2TextPane.setText("");
253 pass2TextPane.setBackground(Color.yellow);
254 pass3aTextPane.setText("");
255 pass3aJList.setListData(new Object[0]);
256 pass3aTextPane.setBackground(Color.yellow);
257 pass3bTextPane.setText("");
258 pass3bJList.setListData(new Object[0]);
259 pass3bTextPane.setBackground(Color.yellow);
260 } else { // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
261 pass1TextPane.setBackground(Color.green);
262 pass1TextPane.setText(vr.getMessage());
263 vr = v.doPass2();
264 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
265 pass2TextPane.setText(vr.getMessage());
266 pass2TextPane.setBackground(Color.red);
267 pass3aTextPane.setText("");
268 pass3aTextPane.setBackground(Color.yellow);
269 pass3aJList.setListData(new Object[0]);
270 pass3bTextPane.setText("");
271 pass3bTextPane.setBackground(Color.yellow);
272 pass3bJList.setListData(new Object[0]);
273 } else { // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
274 pass2TextPane.setText(vr.getMessage());
275 pass2TextPane.setBackground(Color.green);
276 JavaClass jc = Repository.lookupClass(current_class);
277 /*
278 boolean all3aok = true;
279 boolean all3bok = true;
280 String all3amsg = "";
281 String all3bmsg = "";
282 */
283 String[] methodnames = new String[jc.getMethods().length];
284 for (int i = 0; i < jc.getMethods().length; i++) {
285 methodnames[i] = jc.getMethods()[i].toString().replace('\n', ' ').replace('\t',
286 ' ');
287 }
288 pass3aJList.setListData(methodnames);
289 pass3aJList.setSelectionInterval(0, jc.getMethods().length - 1);
290 pass3bJList.setListData(methodnames);
291 pass3bJList.setSelectionInterval(0, jc.getMethods().length - 1);
292 }
293 }
294 String[] msgs = v.getMessages();
295 messagesTextPane.setBackground(msgs.length == 0 ? Color.green : Color.yellow);
296 String allmsgs = "";
297 for (int i = 0; i < msgs.length; i++) {
298 msgs[i] = msgs[i].replace('\n', ' ');
299 allmsgs += msgs[i] + "\n\n";
300 }
301 messagesTextPane.setText(allmsgs);
302 setTitle(current_class + " - " + JUSTICE_VERSION);
303 }
304
305
306 void newFileMenuItem_actionPerformed( ActionEvent e ) {
307 String classname = JOptionPane
308 .showInputDialog("Please enter the fully qualified name of a class or interface to verify:");
309 if ((classname == null) || (classname.equals(""))) {
310 return;
311 }
312 VerifierFactory.getVerifier(classname); // let observers do the rest.
313 classNamesJList.setSelectedValue(classname, true);
314 }
315
316
317 synchronized void pass3aJList_valueChanged( ListSelectionEvent e ) {
318 if (e.getValueIsAdjusting()) {
319 return;
320 }
321 Verifier v = VerifierFactory.getVerifier(current_class);
322 String all3amsg = "";
323 boolean all3aok = true;
324 boolean rejected = false;
325 for (int i = 0; i < pass3aJList.getModel().getSize(); i++) {
326 if (pass3aJList.isSelectedIndex(i)) {
327 VerificationResult vr = v.doPass3a(i);
328 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
329 all3aok = false;
330 rejected = true;
331 }
332 JavaClass jc = null;
333 try {
334 jc = Repository.lookupClass(v.getClassName());
335 all3amsg += "Method '" + jc.getMethods()[i] + "': "
336 + vr.getMessage().replace('\n', ' ') + "\n\n";
337 } catch (ClassNotFoundException ex) {
338 // FIXME: handle the error
339 ex.printStackTrace();
340 }
341 }
342 }
343 pass3aTextPane.setText(all3amsg);
344 pass3aTextPane.setBackground(all3aok ? Color.green : (rejected ? Color.red : Color.yellow));
345 }
346
347
348 synchronized void pass3bJList_valueChanged( ListSelectionEvent e ) {
349 if (e.getValueIsAdjusting()) {
350 return;
351 }
352 Verifier v = VerifierFactory.getVerifier(current_class);
353 String all3bmsg = "";
354 boolean all3bok = true;
355 boolean rejected = false;
356 for (int i = 0; i < pass3bJList.getModel().getSize(); i++) {
357 if (pass3bJList.isSelectedIndex(i)) {
358 VerificationResult vr = v.doPass3b(i);
359 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
360 all3bok = false;
361 rejected = true;
362 }
363 JavaClass jc = null;
364 try {
365 jc = Repository.lookupClass(v.getClassName());
366 all3bmsg += "Method '" + jc.getMethods()[i] + "': "
367 + vr.getMessage().replace('\n', ' ') + "\n\n";
368 } catch (ClassNotFoundException ex) {
369 // FIXME: handle the error
370 ex.printStackTrace();
371 }
372 }
373 }
374 pass3bTextPane.setText(all3bmsg);
375 pass3bTextPane.setBackground(all3bok ? Color.green : (rejected ? Color.red : Color.yellow));
376 }
377
378
379 void aboutMenuItem_actionPerformed( ActionEvent e ) {
380 JOptionPane
381 .showMessageDialog(
382 this,
383 "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001, 2002.\n<http://jakarta.apache.org/bcel/index.html>",
384 JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
385 }
386
387
388 void whatisMenuItem_actionPerformed( ActionEvent e ) {
389 JOptionPane
390 .showMessageDialog(
391 this,
392 "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.",
393 JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
394 }
395 }
+0
-110
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerifierFactory.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Vector;
23
24 /**
25 * This class produces instances of the Verifier class. Its purpose is to make
26 * sure that they are singleton instances with respect to the class name they
27 * operate on. That means, for every class (represented by a unique fully qualified
28 * class name) there is exactly one Verifier.
29 *
30 * @version $Id: VerifierFactory.java 386056 2006-03-15 11:31:56Z tcurdt $
31 * @author Enver Haase
32 * @see org.apache.bcel.verifier.Verifier
33 */
34 public class VerifierFactory {
35
36 /**
37 * The HashMap that holds the data about the already-constructed Verifier instances.
38 */
39 private static Map hashMap = new HashMap();
40 /**
41 * The VerifierFactoryObserver instances that observe the VerifierFactory.
42 */
43 private static List observers = new Vector();
44
45
46 /**
47 * The VerifierFactory is not instantiable.
48 */
49 private VerifierFactory() {
50 }
51
52
53 /**
54 * Returns the (only) verifier responsible for the class with the given name.
55 * Possibly a new Verifier object is transparently created.
56 * @return the (only) verifier responsible for the class with the given name.
57 */
58 public static Verifier getVerifier( String fully_qualified_classname ) {
59 Verifier v = (Verifier) (hashMap.get(fully_qualified_classname));
60 if (v == null) {
61 v = new Verifier(fully_qualified_classname);
62 hashMap.put(fully_qualified_classname, v);
63 notify(fully_qualified_classname);
64 }
65 return v;
66 }
67
68
69 /**
70 * Notifies the observers of a newly generated Verifier.
71 */
72 private static void notify( String fully_qualified_classname ) {
73 // notify the observers
74 Iterator i = observers.iterator();
75 while (i.hasNext()) {
76 VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next();
77 vfo.update(fully_qualified_classname);
78 }
79 }
80
81
82 /**
83 * Returns all Verifier instances created so far.
84 * This is useful when a Verifier recursively lets
85 * the VerifierFactory create other Verifier instances
86 * and if you want to verify the transitive hull of
87 * referenced class files.
88 */
89 public static Verifier[] getVerifiers() {
90 Verifier[] vs = new Verifier[hashMap.values().size()];
91 return (Verifier[]) (hashMap.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned!
92 }
93
94
95 /**
96 * Adds the VerifierFactoryObserver o to the list of observers.
97 */
98 public static void attach( VerifierFactoryObserver o ) {
99 observers.add(o);
100 }
101
102
103 /**
104 * Removes the VerifierFactoryObserver o from the list of observers.
105 */
106 public static void detach( VerifierFactoryObserver o ) {
107 observers.remove(o);
108 }
109 }
+0
-75
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerifierFactoryListModel.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import javax.swing.event.ListDataEvent;
19
20 /**
21 * This class implements an adapter; it implements both a Swing ListModel and
22 * a VerifierFactoryObserver.
23 *
24 * @version $Id: VerifierFactoryListModel.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author Enver Haase
26 */
27 public class VerifierFactoryListModel implements org.apache.bcel.verifier.VerifierFactoryObserver,
28 javax.swing.ListModel {
29
30 private java.util.ArrayList listeners = new java.util.ArrayList();
31 private java.util.TreeSet cache = new java.util.TreeSet();
32
33
34 public VerifierFactoryListModel() {
35 VerifierFactory.attach(this);
36 update(null); // fill cache.
37 }
38
39
40 public synchronized void update( String s ) {
41 int size = listeners.size();
42 Verifier[] verifiers = VerifierFactory.getVerifiers();
43 int num_of_verifiers = verifiers.length;
44 cache.clear();
45 for (int i = 0; i < num_of_verifiers; i++) {
46 cache.add(verifiers[i].getClassName());
47 }
48 for (int i = 0; i < size; i++) {
49 ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0,
50 num_of_verifiers - 1);
51 ((javax.swing.event.ListDataListener) (listeners.get(i))).contentsChanged(e);
52 }
53 }
54
55
56 public synchronized void addListDataListener( javax.swing.event.ListDataListener l ) {
57 listeners.add(l);
58 }
59
60
61 public synchronized void removeListDataListener( javax.swing.event.ListDataListener l ) {
62 listeners.remove(l);
63 }
64
65
66 public synchronized int getSize() {
67 return cache.size();
68 }
69
70
71 public synchronized Object getElementAt( int index ) {
72 return (cache.toArray())[index];
73 }
74 }
+0
-39
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerifierFactoryObserver.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 /**
19 * VerifierFactoryObserver instances are notified when new Verifier
20 * instances are created.
21 *
22 * @version $Id: VerifierFactoryObserver.java 386056 2006-03-15 11:31:56Z tcurdt $
23 * @author Enver Haase
24 *
25 * @see VerifierFactory#getVerifier(String)
26 * @see VerifierFactory#getVerifiers()
27 * @see VerifierFactory#attach(VerifierFactoryObserver)
28 * @see VerifierFactory#detach(VerifierFactoryObserver)
29 */
30 public interface VerifierFactoryObserver {
31
32 /**
33 * VerifierFactoryObserver instances are notified invoking this method.
34 * The String argument is the fully qualified class name of a class a
35 * new Verifier instance created by the VerifierFactory operates on.
36 */
37 public void update( String s );
38 }
+0
-553
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/VerifyDialog.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier;
17
18 import java.awt.Color;
19 import org.apache.bcel.Repository;
20 import org.apache.bcel.classfile.JavaClass;
21
22 /**
23 * A class for simple graphical class file verification.
24 * Use the main(String []) method with fully qualified
25 * class names as arguments to use it as a stand-alone
26 * application.
27 * Use the VerifyDialog(String) constructor to use this
28 * class in your application.
29 * [This class was created using VisualAge for Java,
30 * but it does not work under VAJ itself (Version 3.02 JDK 1.2)]
31 * @version $Id: VerifyDialog.java 386056 2006-03-15 11:31:56Z tcurdt $
32 * @author Enver Haase
33 * @see #main(String[])
34 * @see #VerifyDialog(String)
35 */
36 public class VerifyDialog extends javax.swing.JDialog {
37
38 /** Machine-generated. */
39 private javax.swing.JPanel ivjJDialogContentPane = null;
40 /** Machine-generated. */
41 private javax.swing.JPanel ivjPass1Panel = null;
42 /** Machine-generated. */
43 private javax.swing.JPanel ivjPass2Panel = null;
44 /** Machine-generated. */
45 private javax.swing.JPanel ivjPass3Panel = null;
46 /** Machine-generated. */
47 private javax.swing.JButton ivjPass1Button = null;
48 /** Machine-generated. */
49 private javax.swing.JButton ivjPass2Button = null;
50 /** Machine-generated. */
51 private javax.swing.JButton ivjPass3Button = null;
52 /** Machine-generated. */
53 IvjEventHandler ivjEventHandler = new IvjEventHandler();
54 /**
55 * The class to verify. Default set to 'java.lang.Object'
56 * in case this class is instantiated via one of the many
57 * machine-generated constructors.
58 */
59 private String class_name = "java.lang.Object";
60 /**
61 * This field is here to count the number of open VerifyDialog
62 * instances so the JVM can be exited afer every Dialog had been
63 * closed.
64 */
65 private static int classes_to_verify;
66
67 /** Machine-generated. */
68 class IvjEventHandler implements java.awt.event.ActionListener {
69
70 public void actionPerformed( java.awt.event.ActionEvent e ) {
71 if (e.getSource() == VerifyDialog.this.getPass1Button()) {
72 connEtoC1(e);
73 }
74 if (e.getSource() == VerifyDialog.this.getPass2Button()) {
75 connEtoC2(e);
76 }
77 if (e.getSource() == VerifyDialog.this.getPass3Button()) {
78 connEtoC3(e);
79 }
80 if (e.getSource() == VerifyDialog.this.getFlushButton()) {
81 connEtoC4(e);
82 }
83 };
84 };
85
86 /** Machine-generated. */
87 private javax.swing.JButton ivjFlushButton = null;
88
89
90 /** Machine-generated. */
91 public VerifyDialog() {
92 super();
93 initialize();
94 }
95
96
97 /** Machine-generated. */
98 public VerifyDialog(java.awt.Dialog owner) {
99 super(owner);
100 }
101
102
103 /** Machine-generated. */
104 public VerifyDialog(java.awt.Dialog owner, String title) {
105 super(owner, title);
106 }
107
108
109 /** Machine-generated. */
110 public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) {
111 super(owner, title, modal);
112 }
113
114
115 /** Machine-generated. */
116 public VerifyDialog(java.awt.Dialog owner, boolean modal) {
117 super(owner, modal);
118 }
119
120
121 /** Machine-generated. */
122 public VerifyDialog(java.awt.Frame owner) {
123 super(owner);
124 }
125
126
127 /** Machine-generated. */
128 public VerifyDialog(java.awt.Frame owner, String title) {
129 super(owner, title);
130 }
131
132
133 /** Machine-generated. */
134 public VerifyDialog(java.awt.Frame owner, String title, boolean modal) {
135 super(owner, title, modal);
136 }
137
138
139 /** Machine-generated. */
140 public VerifyDialog(java.awt.Frame owner, boolean modal) {
141 super(owner, modal);
142 }
143
144
145 /**
146 * Use this constructor if you want a possibility to verify other
147 * class files than java.lang.Object.
148 * @param fully_qualified_class_name java.lang.String
149 */
150 public VerifyDialog(String fully_qualified_class_name) {
151 super();
152 int dotclasspos = fully_qualified_class_name.lastIndexOf(".class");
153 if (dotclasspos != -1) {
154 fully_qualified_class_name = fully_qualified_class_name.substring(0, dotclasspos);
155 }
156 fully_qualified_class_name = fully_qualified_class_name.replace('/', '.');
157 class_name = fully_qualified_class_name;
158 initialize();
159 }
160
161
162 /** Machine-generated. */
163 private void connEtoC1( java.awt.event.ActionEvent arg1 ) {
164 try {
165 // user code begin {1}
166 // user code end
167 this.pass1Button_ActionPerformed(arg1);
168 // user code begin {2}
169 // user code end
170 } catch (java.lang.Throwable ivjExc) {
171 // user code begin {3}
172 // user code end
173 handleException(ivjExc);
174 }
175 }
176
177
178 /** Machine-generated. */
179 private void connEtoC2( java.awt.event.ActionEvent arg1 ) {
180 try {
181 // user code begin {1}
182 // user code end
183 this.pass2Button_ActionPerformed(arg1);
184 // user code begin {2}
185 // user code end
186 } catch (java.lang.Throwable ivjExc) {
187 // user code begin {3}
188 // user code end
189 handleException(ivjExc);
190 }
191 }
192
193
194 /** Machine-generated. */
195 private void connEtoC3( java.awt.event.ActionEvent arg1 ) {
196 try {
197 // user code begin {1}
198 // user code end
199 this.pass4Button_ActionPerformed(arg1);
200 // user code begin {2}
201 // user code end
202 } catch (java.lang.Throwable ivjExc) {
203 // user code begin {3}
204 // user code end
205 handleException(ivjExc);
206 }
207 }
208
209
210 /** Machine-generated. */
211 private void connEtoC4( java.awt.event.ActionEvent arg1 ) {
212 try {
213 // user code begin {1}
214 // user code end
215 this.flushButton_ActionPerformed(arg1);
216 // user code begin {2}
217 // user code end
218 } catch (java.lang.Throwable ivjExc) {
219 // user code begin {3}
220 // user code end
221 handleException(ivjExc);
222 }
223 }
224
225
226 /** Machine-generated. */
227 public void flushButton_ActionPerformed( java.awt.event.ActionEvent actionEvent ) {
228 VerifierFactory.getVerifier(class_name).flush();
229 Repository.removeClass(class_name); // Make sure it will be reloaded.
230 getPass1Panel().setBackground(Color.gray);
231 getPass1Panel().repaint();
232 getPass2Panel().setBackground(Color.gray);
233 getPass2Panel().repaint();
234 getPass3Panel().setBackground(Color.gray);
235 getPass3Panel().repaint();
236 }
237
238
239 /** Machine-generated. */
240 private javax.swing.JButton getFlushButton() {
241 if (ivjFlushButton == null) {
242 try {
243 ivjFlushButton = new javax.swing.JButton();
244 ivjFlushButton.setName("FlushButton");
245 ivjFlushButton.setText("Flush: Forget old verification results");
246 ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight);
247 ivjFlushButton.setBounds(60, 215, 300, 30);
248 ivjFlushButton.setForeground(java.awt.Color.red);
249 ivjFlushButton.setActionCommand("FlushButton");
250 // user code begin {1}
251 // user code end
252 } catch (java.lang.Throwable ivjExc) {
253 // user code begin {2}
254 // user code end
255 handleException(ivjExc);
256 }
257 }
258 return ivjFlushButton;
259 }
260
261
262 /** Machine-generated. */
263 private javax.swing.JPanel getJDialogContentPane() {
264 if (ivjJDialogContentPane == null) {
265 try {
266 ivjJDialogContentPane = new javax.swing.JPanel();
267 ivjJDialogContentPane.setName("JDialogContentPane");
268 ivjJDialogContentPane.setLayout(null);
269 getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName());
270 getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName());
271 getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName());
272 getJDialogContentPane().add(getPass1Button(), getPass1Button().getName());
273 getJDialogContentPane().add(getPass2Button(), getPass2Button().getName());
274 getJDialogContentPane().add(getPass3Button(), getPass3Button().getName());
275 getJDialogContentPane().add(getFlushButton(), getFlushButton().getName());
276 // user code begin {1}
277 // user code end
278 } catch (java.lang.Throwable ivjExc) {
279 // user code begin {2}
280 // user code end
281 handleException(ivjExc);
282 }
283 }
284 return ivjJDialogContentPane;
285 }
286
287
288 /** Machine-generated. */
289 private javax.swing.JButton getPass1Button() {
290 if (ivjPass1Button == null) {
291 try {
292 ivjPass1Button = new javax.swing.JButton();
293 ivjPass1Button.setName("Pass1Button");
294 ivjPass1Button.setText("Pass1: Verify binary layout of .class file");
295 ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight);
296 ivjPass1Button.setBounds(100, 40, 300, 30);
297 ivjPass1Button.setActionCommand("Button1");
298 // user code begin {1}
299 // user code end
300 } catch (java.lang.Throwable ivjExc) {
301 // user code begin {2}
302 // user code end
303 handleException(ivjExc);
304 }
305 }
306 return ivjPass1Button;
307 }
308
309
310 /** Machine-generated. */
311 private javax.swing.JPanel getPass1Panel() {
312 if (ivjPass1Panel == null) {
313 try {
314 ivjPass1Panel = new javax.swing.JPanel();
315 ivjPass1Panel.setName("Pass1Panel");
316 ivjPass1Panel.setLayout(null);
317 ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow);
318 ivjPass1Panel.setBounds(30, 30, 50, 50);
319 // user code begin {1}
320 // user code end
321 } catch (java.lang.Throwable ivjExc) {
322 // user code begin {2}
323 // user code end
324 handleException(ivjExc);
325 }
326 }
327 return ivjPass1Panel;
328 }
329
330
331 /** Machine-generated. */
332 private javax.swing.JButton getPass2Button() {
333 if (ivjPass2Button == null) {
334 try {
335 ivjPass2Button = new javax.swing.JButton();
336 ivjPass2Button.setName("Pass2Button");
337 ivjPass2Button.setText("Pass 2: Verify static .class file constraints");
338 ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight);
339 ivjPass2Button.setBounds(100, 100, 300, 30);
340 ivjPass2Button.setActionCommand("Button2");
341 // user code begin {1}
342 // user code end
343 } catch (java.lang.Throwable ivjExc) {
344 // user code begin {2}
345 // user code end
346 handleException(ivjExc);
347 }
348 }
349 return ivjPass2Button;
350 }
351
352
353 /** Machine-generated. */
354 private javax.swing.JPanel getPass2Panel() {
355 if (ivjPass2Panel == null) {
356 try {
357 ivjPass2Panel = new javax.swing.JPanel();
358 ivjPass2Panel.setName("Pass2Panel");
359 ivjPass2Panel.setLayout(null);
360 ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow);
361 ivjPass2Panel.setBounds(30, 90, 50, 50);
362 // user code begin {1}
363 // user code end
364 } catch (java.lang.Throwable ivjExc) {
365 // user code begin {2}
366 // user code end
367 handleException(ivjExc);
368 }
369 }
370 return ivjPass2Panel;
371 }
372
373
374 /** Machine-generated. */
375 private javax.swing.JButton getPass3Button() {
376 if (ivjPass3Button == null) {
377 try {
378 ivjPass3Button = new javax.swing.JButton();
379 ivjPass3Button.setName("Pass3Button");
380 ivjPass3Button.setText("Passes 3a+3b: Verify code arrays");
381 ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight);
382 ivjPass3Button.setBounds(100, 160, 300, 30);
383 ivjPass3Button.setActionCommand("Button2");
384 // user code begin {1}
385 // user code end
386 } catch (java.lang.Throwable ivjExc) {
387 // user code begin {2}
388 // user code end
389 handleException(ivjExc);
390 }
391 }
392 return ivjPass3Button;
393 }
394
395
396 /** Machine-generated. */
397 private javax.swing.JPanel getPass3Panel() {
398 if (ivjPass3Panel == null) {
399 try {
400 ivjPass3Panel = new javax.swing.JPanel();
401 ivjPass3Panel.setName("Pass3Panel");
402 ivjPass3Panel.setLayout(null);
403 ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow);
404 ivjPass3Panel.setBounds(30, 150, 50, 50);
405 // user code begin {1}
406 // user code end
407 } catch (java.lang.Throwable ivjExc) {
408 // user code begin {2}
409 // user code end
410 handleException(ivjExc);
411 }
412 }
413 return ivjPass3Panel;
414 }
415
416
417 /** Machine-generated. */
418 private void handleException( java.lang.Throwable exception ) {
419 /* Uncomment the following lines to print uncaught exceptions to stdout */
420 System.out.println("--------- UNCAUGHT EXCEPTION ---------");
421 exception.printStackTrace(System.out);
422 }
423
424
425 /** Machine-generated. */
426 private void initConnections() throws java.lang.Exception {
427 // user code begin {1}
428 // user code end
429 getPass1Button().addActionListener(ivjEventHandler);
430 getPass2Button().addActionListener(ivjEventHandler);
431 getPass3Button().addActionListener(ivjEventHandler);
432 getFlushButton().addActionListener(ivjEventHandler);
433 }
434
435
436 /** Machine-generated. */
437 private void initialize() {
438 try {
439 // user code begin {1}
440 // user code end
441 setName("VerifyDialog");
442 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
443 setSize(430, 280);
444 setVisible(true);
445 setModal(true);
446 setResizable(false);
447 setContentPane(getJDialogContentPane());
448 initConnections();
449 } catch (java.lang.Throwable ivjExc) {
450 handleException(ivjExc);
451 }
452 // user code begin {2}
453 setTitle("'" + class_name + "' verification - JustIce / BCEL");
454 // user code end
455 }
456
457
458 /**
459 * Verifies one or more class files.
460 * Verification results are presented graphically: Red means 'rejected',
461 * green means 'passed' while yellow means 'could not be verified yet'.
462 * @param args java.lang.String[] fully qualified names of classes to verify.
463 */
464 public static void main( java.lang.String[] args ) {
465 classes_to_verify = args.length;
466 for (int i = 0; i < args.length; i++) {
467 try {
468 VerifyDialog aVerifyDialog;
469 aVerifyDialog = new VerifyDialog(args[i]);
470 aVerifyDialog.setModal(true);
471 aVerifyDialog.addWindowListener(new java.awt.event.WindowAdapter() {
472
473 public void windowClosing( java.awt.event.WindowEvent e ) {
474 classes_to_verify--;
475 if (classes_to_verify == 0) {
476 System.exit(0);
477 }
478 };
479 });
480 aVerifyDialog.setVisible(true);
481 } catch (Throwable exception) {
482 System.err.println("Exception occurred in main() of javax.swing.JDialog");
483 exception.printStackTrace(System.out);
484 }
485 }
486 }
487
488
489 /** Machine-generated. */
490 public void pass1Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) {
491 Verifier v = VerifierFactory.getVerifier(class_name);
492 VerificationResult vr = v.doPass1();
493 if (vr.getStatus() == VerificationResult.VERIFIED_OK) {
494 getPass1Panel().setBackground(Color.green);
495 getPass1Panel().repaint();
496 }
497 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
498 getPass1Panel().setBackground(Color.red);
499 getPass1Panel().repaint();
500 }
501 }
502
503
504 /** Machine-generated. */
505 public void pass2Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) {
506 pass1Button_ActionPerformed(actionEvent);
507 Verifier v = VerifierFactory.getVerifier(class_name);
508 VerificationResult vr = v.doPass2();
509 if (vr.getStatus() == VerificationResult.VERIFIED_OK) {
510 getPass2Panel().setBackground(Color.green);
511 getPass2Panel().repaint();
512 }
513 if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET) {
514 getPass2Panel().setBackground(Color.yellow);
515 getPass2Panel().repaint();
516 }
517 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
518 getPass2Panel().setBackground(Color.red);
519 getPass2Panel().repaint();
520 }
521 }
522
523
524 /** Machine-generated. */
525 public void pass4Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) {
526 pass2Button_ActionPerformed(actionEvent);
527 Color color = Color.green;
528 Verifier v = VerifierFactory.getVerifier(class_name);
529 VerificationResult vr = v.doPass2();
530 if (vr.getStatus() == VerificationResult.VERIFIED_OK) {
531 JavaClass jc = null;
532 try {
533 jc = Repository.lookupClass(class_name);
534 int nr = jc.getMethods().length;
535 for (int i = 0; i < nr; i++) {
536 vr = v.doPass3b(i);
537 if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
538 color = Color.red;
539 break;
540 }
541 }
542 } catch (ClassNotFoundException ex) {
543 // FIXME: report the error
544 ex.printStackTrace();
545 }
546 } else {
547 color = Color.yellow;
548 }
549 getPass3Panel().setBackground(color);
550 getPass3Panel().repaint();
551 }
552 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/AssertionViolatedException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class should never be thrown. When such an instance is thrown,
21 * this is due to an INTERNAL ERROR of BCEL's class file verifier &quot;JustIce&quot;.
22 *
23 * @version $Id: AssertionViolatedException.java 386056 2006-03-15 11:31:56Z tcurdt $
24 * @author Enver Haase
25 */
26 public final class AssertionViolatedException extends RuntimeException{
27 /** The error message. */
28 private String detailMessage;
29 /** Constructs a new AssertionViolatedException with null as its error message string. */
30 public AssertionViolatedException(){
31 super();
32 }
33 /**
34 * Constructs a new AssertionViolatedException with the specified error message preceded
35 * by &quot;INTERNAL ERROR: &quot;.
36 */
37 public AssertionViolatedException(String message){
38 super(message = "INTERNAL ERROR: "+message); // Thanks to Java, the constructor call here must be first.
39 detailMessage=message;
40 }
41 /** Extends the error message with a string before ("pre") and after ("post") the
42 'old' error message. All of these three strings are allowed to be null, and null
43 is always replaced by the empty string (""). In particular, after invoking this
44 method, the error message of this object can no longer be null.
45 */
46 public void extendMessage(String pre, String post){
47 if (pre == null) {
48 pre="";
49 }
50 if (detailMessage == null) {
51 detailMessage="";
52 }
53 if (post == null) {
54 post="";
55 }
56 detailMessage = pre+detailMessage+post;
57 }
58 /**
59 * Returns the error message string of this AssertionViolatedException object.
60 * @return the error message string of this AssertionViolatedException.
61 */
62 public String getMessage(){
63 return detailMessage;
64 }
65
66 /**
67 * DO NOT USE. It's for experimental testing during development only.
68 */
69 public static void main(String[] args){
70 AssertionViolatedException ave = new AssertionViolatedException("Oops!");
71 ave.extendMessage("\nFOUND:\n\t","\nExiting!!\n");
72 throw ave;
73 }
74
75 }
+0
-42
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/ClassConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce"
21 * when a class file to verify does not pass the verification pass 2 as described
22 * in the Java Virtual Machine specification, 2nd edition.
23 *
24 * @version $Id: ClassConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
25 * @author Enver Haase
26 */
27 public class ClassConstraintException extends VerificationException{
28 /**
29 * Constructs a new ClassConstraintException with null as its error message string.
30 */
31 public ClassConstraintException(){
32 super();
33 }
34
35 /**
36 * Constructs a new ClassConstraintException with the specified error message.
37 */
38 public ClassConstraintException(String message){
39 super (message);
40 }
41 }
+0
-40
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/CodeConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18 /**
19 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
20 * a class file does not pass the verification pass 3. Note that the pass 3 used by
21 * "JustIce" involves verification that is usually delayed to pass 4.
22 *
23 * @version $Id: CodeConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
24 * @author Enver Haase
25 */
26 public abstract class CodeConstraintException extends VerificationException{
27 /**
28 * Constructs a new CodeConstraintException with null as its error message string.
29 */
30 CodeConstraintException(){
31 super();
32 }
33 /**
34 * Constructs a new CodeConstraintException with the specified error message.
35 */
36 CodeConstraintException(String message){
37 super(message);
38 }
39 }
+0
-32
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/InvalidMethodException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18 /**
19 * Instances of this class are thrown by BCEL's class file verifier "JustIce"
20 * when the verification of a method is requested that does not exist.
21 *
22 * @version $Id: InvalidMethodException.java 371539 2006-01-23 14:08:00Z tcurdt $
23 * @author Enver Haase
24 */
25 public class InvalidMethodException extends RuntimeException{
26
27 /** Constructs an InvalidMethodException with the specified detail message. */
28 public InvalidMethodException(String message){
29 super(message);
30 }
31 }
+0
-37
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/LinkingConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18 /**
19 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
20 * a class file to verify does not pass the verification pass 3 because of a violation
21 * of a constraint that is usually only verified at run-time (pass 4).
22 * The Java Virtual Machine Specification, 2nd edition, states that certain constraints
23 * are usually verified at run-time for performance reasons (the verification of those
24 * constraints requires loading in and recursively verifying referenced classes) that
25 * conceptually belong to pass 3; to be precise, that conceptually belong to the
26 * data flow analysis of pass 3 (called pass 3b in JustIce).
27 * These are the checks necessary for resolution: Compare pages 142-143 ("4.9.1 The
28 * Verification Process") and pages 50-51 ("2.17.3 Linking: Verification, Preparation,
29 * and Resolution") of the above mentioned book.
30 * <B>TODO: At this time, this class is not used in JustIce.</B>
31 *
32 * @version $Id: LinkingConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
33 * @author Enver Haase
34 */
35 public class LinkingConstraintException extends StructuralCodeConstraintException{
36 }
+0
-42
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/LoadingException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * When loading a class file, BCEL will throw an instance of LoadingException if
21 * the class file is malformed; so it is not conforming to the "Pass 1" verification
22 * process as described in the Java Virtual Machine specification, 2nd. edition.
23 * @version $Id: LoadingException.java 371539 2006-01-23 14:08:00Z tcurdt $
24 * @author Enver Haase
25 */
26 public class LoadingException extends VerifierConstraintViolatedException{
27
28 /**
29 * Constructs a new LoadingException with null as its error message string.
30 */
31 public LoadingException(){
32 super();
33 }
34
35 /**
36 * Constructs a new LoadingException with the specified error message.
37 */
38 public LoadingException(String message){
39 super (message);
40 }
41 }
+0
-44
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/LocalVariableInfoInconsistentException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * A LocalVariableInfoInconsistentException instance is thrown by
21 * the LocalVariableInfo class when it detects that the information
22 * it holds is inconsistent; this is normally due to inconsistent
23 * LocalVariableTable entries in the Code attribute of a certain
24 * Method object.
25 *
26 * @version $Id: LocalVariableInfoInconsistentException.java 371539 2006-01-23 14:08:00Z tcurdt $
27 * @author Enver Haase
28 */
29 public class LocalVariableInfoInconsistentException extends ClassConstraintException{
30 /**
31 * Constructs a new LocalVariableInfoInconsistentException with null as its error message string.
32 */
33 public LocalVariableInfoInconsistentException(){
34 super();
35 }
36
37 /**
38 * Constructs a new LocalVariableInfoInconsistentException with the specified error message.
39 */
40 public LocalVariableInfoInconsistentException(String message){
41 super (message);
42 }
43 }
+0
-34
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/StaticCodeConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
21 * a class file to verify does not pass the verification pass 3 because of a violation
22 * of a static constraint as described in the Java Virtual Machine Specification,
23 * 2nd edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3
24 * is called pass 3a in JustIce.
25 *
26 * @version $Id: StaticCodeConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
27 * @author Enver Haase
28 */
29 public abstract class StaticCodeConstraintException extends CodeConstraintException{
30 public StaticCodeConstraintException(String message){
31 super(message);
32 }
33 }
+0
-37
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/StaticCodeInstructionConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
21 * a class file to verify does not pass the verification pass 3 because of a violation
22 * of a static constraint as described in the Java Virtual Machine Specification,
23 * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3
24 * is called pass 3a in JustIce.
25 * Static constraints on the instructions in the code array are checked early in
26 * pass 3a and are described on page 134 in the Java Virtual Machine Specification,
27 * Second Edition.
28 *
29 * @version $Id: StaticCodeInstructionConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
30 * @author Enver Haase
31 */
32 public class StaticCodeInstructionConstraintException extends StaticCodeConstraintException{
33 public StaticCodeInstructionConstraintException(String message){
34 super(message);
35 }
36 }
+0
-37
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/StaticCodeInstructionOperandConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
21 * a class file to verify does not pass the verification pass 3 because of a violation
22 * of a static constraint as described in the Java Virtual Machine Specification,
23 * Second edition, 4.8.1, pages 133-137. The static constraints checking part of pass 3
24 * is called pass 3a in JustIce.
25 * Static constraints on the operands of instructions in the code array are checked late in
26 * pass 3a and are described on page 134-137 in the Java Virtual Machine Specification,
27 * Second Edition.
28 *
29 * @version $Id: StaticCodeInstructionOperandConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
30 * @author Enver Haase
31 */
32 public class StaticCodeInstructionOperandConstraintException extends StaticCodeConstraintException{
33 public StaticCodeInstructionOperandConstraintException(String message){
34 super(message);
35 }
36 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/StructuralCodeConstraintException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18 /**
19 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when
20 * a class file to verify does not pass the verification pass 3 because of a violation
21 * of a structural constraint as described in the Java Virtual Machine Specification,
22 * 2nd edition, 4.8.2, pages 137-139.
23 * Note that the notion of a "structural" constraint is somewhat misleading. Structural
24 * constraints are constraints on relationships between Java virtual machine instructions.
25 * These are the constraints where data-flow analysis is needed to verify if they hold.
26 * The data flow analysis of pass 3 is called pass 3b in JustIce.
27 *
28 * @version $Id: StructuralCodeConstraintException.java 371539 2006-01-23 14:08:00Z tcurdt $
29 * @author Enver Haase
30 */
31 public class StructuralCodeConstraintException extends CodeConstraintException{
32 /**
33 * Constructs a new StructuralCodeConstraintException with the specified error message.
34 */
35 public StructuralCodeConstraintException(String message){
36 super(message);
37 }
38 /**
39 * Constructs a new StructuralCodeConstraintException with null as its error message string.
40 */
41 public StructuralCodeConstraintException(){
42 super();
43 }
44 }
+0
-40
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/Utility.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21
22 /**
23 * A utility class providing convenience methods concerning Throwable instances.
24 * @version $Id: Utility.java 371539 2006-01-23 14:08:00Z tcurdt $
25 * @author Enver Haase
26 * @see java.lang.Throwable
27 */
28 public final class Utility{
29 /** This class is not instantiable. */
30 private Utility(){}
31
32 /** This method returns the stack trace of a Throwable instance as a String. */
33 public static String getStackTrace(Throwable t){
34 StringWriter sw = new StringWriter();
35 PrintWriter pw = new PrintWriter(sw);
36 t.printStackTrace(pw);
37 return sw.toString();
38 }
39 }
+0
-45
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/VerificationException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce" when a
21 * class file to verify does not pass one of the verification passes 2 or 3.
22 * Note that the pass 3 used by "JustIce" involves verification that is usually
23 * delayed to pass 4.
24 * The name of this class is justified by the Java Virtual Machine Specification, 2nd
25 * edition, page 164, 5.4.1 where verification as a part of the linking process is
26 * defined to be the verification happening in passes 2 and 3.
27 *
28 * @version $Id: VerificationException.java 371539 2006-01-23 14:08:00Z tcurdt $
29 * @author Enver Haase
30 */
31 public abstract class VerificationException extends VerifierConstraintViolatedException{
32 /**
33 * Constructs a new VerificationException with null as its error message string.
34 */
35 VerificationException(){
36 super();
37 }
38 /**
39 * Constructs a new VerificationException with the specified error message.
40 */
41 VerificationException(String message){
42 super(message);
43 }
44 }
+0
-76
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/VerifierConstraintViolatedException.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.exc;
17
18
19 /**
20 * Instances of this class are thrown by BCEL's class file verifier "JustIce"
21 * whenever
22 * verification proves that some constraint of a class file (as stated in the
23 * Java Virtual Machine Specification, Edition 2) is violated.
24 * This is roughly equivalent to the VerifyError the JVM-internal verifiers
25 * throw.
26 *
27 * @version $Id: VerifierConstraintViolatedException.java 386056 2006-03-15 11:31:56Z tcurdt $
28 * @author Enver Haase
29 */
30 public abstract class VerifierConstraintViolatedException extends RuntimeException{
31 // /** The name of the offending class that did not pass the verifier. */
32 // String name_of_offending_class;
33
34 /** The specified error message. */
35 private String detailMessage;
36 /**
37 * Constructs a new VerifierConstraintViolatedException with null as its error message string.
38 */
39 VerifierConstraintViolatedException(){
40 super();
41 }
42 /**
43 * Constructs a new VerifierConstraintViolatedException with the specified error message.
44 */
45 VerifierConstraintViolatedException(String message){
46 super(message); // Not that important
47 detailMessage = message;
48 }
49
50
51 /** Extends the error message with a string before ("pre") and after ("post") the
52 'old' error message. All of these three strings are allowed to be null, and null
53 is always replaced by the empty string (""). In particular, after invoking this
54 method, the error message of this object can no longer be null.
55 */
56 public void extendMessage(String pre, String post){
57 if (pre == null) {
58 pre="";
59 }
60 if (detailMessage == null) {
61 detailMessage="";
62 }
63 if (post == null) {
64 post="";
65 }
66 detailMessage = pre+detailMessage+post;
67 }
68 /**
69 * Returns the error message string of this VerifierConstraintViolatedException object.
70 * @return the error message string of this VerifierConstraintViolatedException.
71 */
72 public String getMessage(){
73 return detailMessage;
74 }
75 }
+0
-17
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/exc/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 371539 2006-01-23 14:08:00Z tcurdt $
5 -->
6 </head>
7 <body bgcolor="white">
8
9 Exception classes used by JustIce, mostly used internally. You don't need to bother with them.
10
11 <h2>Package Specification</h2>
12
13 Contained in this package are Exception classes for use with the JustIce verifier.
14
15 </body>
16 </html>
+0
-18
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 371539 2006-01-23 14:08:00Z tcurdt $
5 -->
6 </head>
7 <body bgcolor="white">
8
9 BCEL's verifier JustIce is there to help you dump correct Java class files created or modified with BCEL.
10
11 <h2>Package Specification</h2>
12
13 This is the top-level package of the JustIce verifier. To actually use it, have a look at the VerifierFactory and
14 Verifier classes.
15
16 </body>
17 </html>
+0
-42
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/DOUBLE_Upper.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.generic.Type;
21
22 /**
23 * This class represents the upper half of a DOUBLE variable.
24 * @version $Id: DOUBLE_Upper.java 371539 2006-01-23 14:08:00Z tcurdt $
25 * @author Enver Haase
26 */
27 public final class DOUBLE_Upper extends Type{
28
29 /** The one and only instance of this class. */
30 private static DOUBLE_Upper singleInstance = new DOUBLE_Upper();
31
32 /** The constructor; this class must not be instantiated from the outside. */
33 private DOUBLE_Upper(){
34 super(Constants.T_UNKNOWN, "Long_Upper");
35 }
36
37 /** Use this method to get the single instance of this class. */
38 public static DOUBLE_Upper theInstance(){
39 return singleInstance;
40 }
41 }
+0
-51
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/IntList.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 /**
23 * A small utility class representing a set of basic int values.
24 *
25 * @version $Id: IntList.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author Enver Haase
27 */
28 public class IntList{
29 /** The int are stored as Integer objects here. */
30 private List theList;
31 /** This constructor creates an empty list. */
32 IntList(){
33 theList = new ArrayList();
34 }
35 /** Adds an element to the list. */
36 void add(int i){
37 theList.add(new Integer(i));
38 }
39 /** Checks if the specified int is already in the list. */
40 boolean contains(int i){
41 Integer[] ints = new Integer[theList.size()];
42 theList.toArray(ints);
43 for (int j=0; j<ints.length; j++){
44 if (i == ints[j].intValue()) {
45 return true;
46 }
47 }
48 return false;
49 }
50 }
+0
-42
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/LONG_Upper.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.generic.Type;
21
22 /**
23 * This class represents the upper half of a LONG variable.
24 * @version $Id: LONG_Upper.java 371539 2006-01-23 14:08:00Z tcurdt $
25 * @author Enver Haase
26 */
27 public final class LONG_Upper extends Type{
28
29 /** The one and only instance of this class. */
30 private static LONG_Upper singleInstance = new LONG_Upper();
31
32 /** The constructor; this class must not be instantiated from the outside. */
33 private LONG_Upper(){
34 super(Constants.T_UNKNOWN, "Long_Upper");
35 }
36
37 /** Use this method to get the single instance of this class. */
38 public static LONG_Upper theInstance(){
39 return singleInstance;
40 }
41 }
+0
-107
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/LocalVariableInfo.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import java.util.Hashtable;
20 import org.apache.bcel.generic.Type;
21 import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;
22
23 /**
24 * A utility class holding the information about
25 * the name and the type of a local variable in
26 * a given slot (== index). This information
27 * often changes in course of byte code offsets.
28 *
29 * @version $Id: LocalVariableInfo.java 371539 2006-01-23 14:08:00Z tcurdt $
30 * @author Enver Haase
31 */
32 public class LocalVariableInfo{
33
34 /** The types database. KEY: String representing the offset integer. */
35 private Hashtable types = new Hashtable();
36 /** The names database. KEY: String representing the offset integer. */
37 private Hashtable names = new Hashtable();
38
39 /**
40 * Adds a name of a local variable and a certain slot to our 'names'
41 * (Hashtable) database.
42 */
43 private void setName(int offset, String name){
44 names.put( ((Integer.toString(offset))), name);
45 }
46 /**
47 * Adds a type of a local variable and a certain slot to our 'types'
48 * (Hashtable) database.
49 */
50 private void setType(int offset, Type t){
51 types.put( ((Integer.toString(offset))), t);
52 }
53
54 /**
55 * Returns the type of the local variable that uses this local
56 * variable slot at the given bytecode offset.
57 * Care for legal bytecode offsets yourself, otherwise the return value
58 * might be wrong.
59 * May return 'null' if nothing is known about the type of this local
60 * variable slot at the given bytecode offset.
61 */
62 public Type getType(int offset){
63 return (Type) types.get(Integer.toString(offset));
64 }
65 /**
66 * Returns the name of the local variable that uses this local
67 * variable slot at the given bytecode offset.
68 * Care for legal bytecode offsets yourself, otherwise the return value
69 * might be wrong.
70 * May return 'null' if nothing is known about the type of this local
71 * variable slot at the given bytecode offset.
72 */
73 public String getName(int offset){
74 return (String) (names.get(Integer.toString(offset)));
75 }
76 /**
77 * Adds some information about this local variable (slot).
78 * @throws LocalVariableInfoInconsistentException if the new information conflicts
79 * with already gathered information.
80 */
81 public void add(String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{
82 for (int i=startpc; i<=startpc+length; i++){ // incl/incl-notation!
83 add(i,name,t);
84 }
85 }
86
87 /**
88 * Adds information about name and type for a given offset.
89 * @throws LocalVariableInfoInconsistentException if the new information conflicts
90 * with already gathered information.
91 */
92 private void add(int offset, String name, Type t) throws LocalVariableInfoInconsistentException{
93 if (getName(offset) != null){
94 if (! getName(offset).equals(name)){
95 throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different names: '"+getName(offset)+"' and '"+name+"'.");
96 }
97 }
98 if (getType(offset) != null){
99 if (! getType(offset).equals(t)){
100 throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different types: '"+getType(offset)+"' and '"+t+"'.");
101 }
102 }
103 setName(offset, name);
104 setType(offset, t);
105 }
106 }
+0
-74
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/LocalVariablesInfo.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.generic.Type;
20 import org.apache.bcel.verifier.exc.AssertionViolatedException;
21 import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;
22
23 /**
24 * A utility class holding the information about
25 * the names and the types of the local variables in
26 * a given method.
27 *
28 * @version $Id: LocalVariablesInfo.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author Enver Haase
30 */
31 public class LocalVariablesInfo{
32
33 /** The information about the local variables is stored here. */
34 private LocalVariableInfo[] localVariableInfos;
35
36 /** The constructor. */
37 LocalVariablesInfo(int max_locals){
38 localVariableInfos = new LocalVariableInfo[max_locals];
39 for (int i=0; i<max_locals; i++){
40 localVariableInfos[i] = new LocalVariableInfo();
41 }
42 }
43
44 /** Returns the LocalVariableInfo for the given slot. */
45 public LocalVariableInfo getLocalVariableInfo(int slot){
46 if (slot < 0 || slot >= localVariableInfos.length){
47 throw new AssertionViolatedException("Slot number for local variable information out of range.");
48 }
49 return localVariableInfos[slot];
50 }
51
52 /**
53 * Adds information about the local variable in slot 'slot'. Automatically
54 * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE.
55 * @throws LocalVariableInfoInconsistentException if the new information conflicts
56 * with already gathered information.
57 */
58 public void add(int slot, String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{
59 // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here.
60
61 if (slot < 0 || slot >= localVariableInfos.length){
62 throw new AssertionViolatedException("Slot number for local variable information out of range.");
63 }
64
65 localVariableInfos[slot].add(name, startpc, length, t);
66 if (t == Type.LONG) {
67 localVariableInfos[slot+1].add(name, startpc, length, LONG_Upper.theInstance());
68 }
69 if (t == Type.DOUBLE) {
70 localVariableInfos[slot+1].add(name, startpc, length, DOUBLE_Upper.theInstance());
71 }
72 }
73 }
+0
-185
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/Pass1Verifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.Repository;
20 import org.apache.bcel.classfile.ClassFormatException;
21 import org.apache.bcel.classfile.JavaClass;
22 import org.apache.bcel.verifier.PassVerifier;
23 import org.apache.bcel.verifier.VerificationResult;
24 import org.apache.bcel.verifier.Verifier;
25 import org.apache.bcel.verifier.exc.LoadingException;
26 import org.apache.bcel.verifier.exc.Utility;
27
28 /**
29 * This PassVerifier verifies a class file according to pass 1 as
30 * described in The Java Virtual Machine Specification, 2nd edition.
31 * More detailed information is to be found at the do_verify() method's
32 * documentation.
33 *
34 * @version $Id: Pass1Verifier.java 371539 2006-01-23 14:08:00Z tcurdt $
35 * @author Enver Haase
36 * @see #do_verify()
37 */
38 public final class Pass1Verifier extends PassVerifier{
39 /**
40 * DON'T USE THIS EVEN PRIVATELY! USE getJavaClass() INSTEAD.
41 * @see #getJavaClass()
42 */
43 private JavaClass jc;
44
45 /**
46 * The Verifier that created this.
47 */
48 private Verifier myOwner;
49
50 /** Used to load in and return the myOwner-matching JavaClass object when needed. Avoids loading in a class file when it's not really needed! */
51 private JavaClass getJavaClass(){
52 if (jc == null){
53 try {
54 jc = Repository.lookupClass(myOwner.getClassName());
55 } catch (ClassNotFoundException e) {
56 // FIXME: currently, Pass1Verifier treats jc == null as a special
57 // case, so we don't need to do anything here. A better solution
58 // would be to simply throw the ClassNotFoundException
59 // out of this method.
60 }
61 }
62 return jc;
63 }
64
65 /**
66 * Should only be instantiated by a Verifier.
67 *
68 * @see org.apache.bcel.verifier.Verifier
69 */
70 public Pass1Verifier(Verifier owner){
71 myOwner = owner;
72 }
73
74 /**
75 * Pass-one verification basically means loading in a class file.
76 * The Java Virtual Machine Specification is not too precise about
77 * what makes the difference between passes one and two.
78 * The answer is that only pass one is performed on a class file as
79 * long as its resolution is not requested; whereas pass two and
80 * pass three are performed during the resolution process.
81 * Only four constraints to be checked are explicitely stated by
82 * The Java Virtual Machine Specification, 2nd edition:
83 * <UL>
84 * <LI>The first four bytes must contain the right magic number (0xCAFEBABE).
85 * <LI>All recognized attributes must be of the proper length.
86 * <LI>The class file must not be truncated or have extra bytes at the end.
87 * <LI>The constant pool must not contain any superficially unrecognizable information.
88 * </UL>
89 * A more in-depth documentation of what pass one should do was written by
90 * <A HREF=mailto:pwfong@cs.sfu.ca>Philip W. L. Fong</A>:
91 * <UL>
92 * <LI> the file should not be truncated.
93 * <LI> the file should not have extra bytes at the end.
94 * <LI> all variable-length structures should be well-formatted:
95 * <UL>
96 * <LI> there should only be constant_pool_count-1 many entries in the constant pool.
97 * <LI> all constant pool entries should have size the same as indicated by their type tag.
98 * <LI> there are exactly interfaces_count many entries in the interfaces array of the class file.
99 * <LI> there are exactly fields_count many entries in the fields array of the class file.
100 * <LI> there are exactly methods_count many entries in the methods array of the class file.
101 * <LI> there are exactly attributes_count many entries in the attributes array of the class file, fields, methods, and code attribute.
102 * <LI> there should be exactly attribute_length many bytes in each attribute. Inconsistency between attribute_length and the actually size of the attribute content should be uncovered. For example, in an Exceptions attribute, the actual number of exceptions as required by the number_of_exceptions field might yeild an attribute size that doesn't match the attribute_length. Such an anomaly should be detected.
103 * <LI> all attributes should have proper length. In particular, under certain context (e.g. while parsing method_info), recognizable attributes (e.g. "Code" attribute) should have correct format (e.g. attribute_length is 2).
104 * </UL>
105 * <LI> Also, certain constant values are checked for validity:
106 * <UL>
107 * <LI> The magic number should be 0xCAFEBABE.
108 * <LI> The major and minor version numbers are valid.
109 * <LI> All the constant pool type tags are recognizable.
110 * <LI> All undocumented access flags are masked off before use. Strictly speaking, this is not really a check.
111 * <LI> The field this_class should point to a string that represents a legal non-array class name, and this name should be the same as the class file being loaded.
112 * <LI> the field super_class should point to a string that represents a legal non-array class name.
113 * <LI> Because some of the above checks require cross referencing the constant pool entries, guards are set up to make sure that the referenced entries are of the right type and the indices are within the legal range (0 < index < constant_pool_count).
114 * </UL>
115 * <LI> Extra checks done in pass 1:
116 * <UL>
117 * <LI> the constant values of static fields should have the same type as the fields.
118 * <LI> the number of words in a parameter list does not exceed 255 and locals_max.
119 * <LI> the name and signature of fields and methods are verified to be of legal format.
120 * </UL>
121 * </UL>
122 * (From the Paper <A HREF=http://www.cs.sfu.ca/people/GradStudents/pwfong/personal/JVM/pass1/>The Mysterious Pass One, first draft, September 2, 1997</A>.)
123 * </BR>
124 * However, most of this is done by parsing a class file or generating a class file into BCEL's internal data structure.
125 * <B>Therefore, all that is really done here is look up the class file from BCEL's repository.</B>
126 * This is also motivated by the fact that some omitted things
127 * (like the check for extra bytes at the end of the class file) are handy when actually using BCEL to repair a class file (otherwise you would not be
128 * able to load it into BCEL).
129 *
130 * @see org.apache.bcel.Repository
131 */
132 public VerificationResult do_verify(){
133 JavaClass jc;
134 try{
135 jc = getJavaClass(); //loads in the class file if not already done.
136
137 if (jc != null){
138 /* If we find more constraints to check, we should do this in an own method. */
139 if (! myOwner.getClassName().equals(jc.getClassName())){
140 // This should maybe caught by BCEL: In case of renamed .class files we get wrong
141 // JavaClass objects here.
142 throw new LoadingException("Wrong name: the internal name of the .class file '"+jc.getClassName()+"' does not match the file's name '"+myOwner.getClassName()+"'.");
143 }
144 }
145
146 }
147 catch(LoadingException e){
148 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage());
149 }
150 catch(ClassFormatException e){
151 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage());
152 }
153 catch(RuntimeException e){
154 // BCEL does not catch every possible RuntimeException; e.g. if
155 // a constant pool index is referenced that does not exist.
156 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Parsing via BCEL did not succeed. "+e.getClass().getName()+" occured:\n"+Utility.getStackTrace(e));
157 }
158
159 if (jc != null){
160 return VerificationResult.VR_OK;
161 }
162 else{
163 //TODO: Maybe change Repository's behaviour to throw a LoadingException instead of just returning "null"
164 // if a class file cannot be found or in another way be looked up.
165 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Repository.lookup() failed. FILE NOT FOUND?");
166 }
167 }
168
169 /**
170 * Currently this returns an empty array of String.
171 * One could parse the error messages of BCEL
172 * (written to java.lang.System.err) when loading
173 * a class file such as detecting unknown attributes
174 * or trailing garbage at the end of a class file.
175 * However, Markus Dahm does not like the idea so this
176 * method is currently useless and therefore marked as
177 * <B>TODO</B>.
178 */
179 public String[] getMessages(){
180 // This method is only here to override the javadoc-comment.
181 return super.getMessages();
182 }
183
184 }
+0
-1444
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/Pass2Verifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Locale;
22 import java.util.Map;
23 import java.util.Set;
24 import org.apache.bcel.Constants;
25 import org.apache.bcel.Repository;
26 import org.apache.bcel.classfile.Attribute;
27 import org.apache.bcel.classfile.ClassFormatException;
28 import org.apache.bcel.classfile.Code;
29 import org.apache.bcel.classfile.CodeException;
30 import org.apache.bcel.classfile.Constant;
31 import org.apache.bcel.classfile.ConstantClass;
32 import org.apache.bcel.classfile.ConstantDouble;
33 import org.apache.bcel.classfile.ConstantFieldref;
34 import org.apache.bcel.classfile.ConstantFloat;
35 import org.apache.bcel.classfile.ConstantInteger;
36 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
37 import org.apache.bcel.classfile.ConstantLong;
38 import org.apache.bcel.classfile.ConstantMethodref;
39 import org.apache.bcel.classfile.ConstantNameAndType;
40 import org.apache.bcel.classfile.ConstantPool;
41 import org.apache.bcel.classfile.ConstantString;
42 import org.apache.bcel.classfile.ConstantUtf8;
43 import org.apache.bcel.classfile.ConstantValue;
44 import org.apache.bcel.classfile.Deprecated;
45 import org.apache.bcel.classfile.DescendingVisitor;
46 import org.apache.bcel.classfile.EmptyVisitor;
47 import org.apache.bcel.classfile.ExceptionTable;
48 import org.apache.bcel.classfile.Field;
49 import org.apache.bcel.classfile.InnerClass;
50 import org.apache.bcel.classfile.InnerClasses;
51 import org.apache.bcel.classfile.JavaClass;
52 import org.apache.bcel.classfile.LineNumber;
53 import org.apache.bcel.classfile.LineNumberTable;
54 import org.apache.bcel.classfile.LocalVariable;
55 import org.apache.bcel.classfile.LocalVariableTable;
56 import org.apache.bcel.classfile.Method;
57 import org.apache.bcel.classfile.Node;
58 import org.apache.bcel.classfile.SourceFile;
59 import org.apache.bcel.classfile.Synthetic;
60 import org.apache.bcel.classfile.Unknown;
61 import org.apache.bcel.classfile.Visitor;
62 import org.apache.bcel.generic.ArrayType;
63 import org.apache.bcel.generic.ObjectType;
64 import org.apache.bcel.generic.Type;
65 import org.apache.bcel.verifier.PassVerifier;
66 import org.apache.bcel.verifier.VerificationResult;
67 import org.apache.bcel.verifier.Verifier;
68 import org.apache.bcel.verifier.VerifierFactory;
69 import org.apache.bcel.verifier.exc.AssertionViolatedException;
70 import org.apache.bcel.verifier.exc.ClassConstraintException;
71 import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;
72
73 /**
74 * This PassVerifier verifies a class file according to
75 * pass 2 as described in The Java Virtual Machine
76 * Specification, 2nd edition.
77 * More detailed information is to be found at the do_verify()
78 * method's documentation.
79 *
80 * @version $Id: Pass2Verifier.java 386056 2006-03-15 11:31:56Z tcurdt $
81 * @author Enver Haase
82 * @see #do_verify()
83 */
84 public final class Pass2Verifier extends PassVerifier implements Constants{
85
86 /**
87 * The LocalVariableInfo instances used by Pass3bVerifier.
88 * localVariablesInfos[i] denotes the information for the
89 * local variables of method number i in the
90 * JavaClass this verifier operates on.
91 */
92 private LocalVariablesInfo[] localVariablesInfos;
93
94 /** The Verifier that created this. */
95 private Verifier myOwner;
96
97 /**
98 * Should only be instantiated by a Verifier.
99 *
100 * @see Verifier
101 */
102 public Pass2Verifier(Verifier owner){
103 myOwner = owner;
104 }
105
106 /**
107 * Returns a LocalVariablesInfo object containing information
108 * about the usage of the local variables in the Code attribute
109 * of the said method or <B>null</B> if the class file this
110 * Pass2Verifier operates on could not be pass-2-verified correctly.
111 * The method number method_nr is the method you get using
112 * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>.
113 * You should not add own information. Leave that to JustIce.
114 */
115 public LocalVariablesInfo getLocalVariablesInfo(int method_nr){
116 if (this.verify() != VerificationResult.VR_OK) {
117 return null; // It's cached, don't worry.
118 }
119 if (method_nr < 0 || method_nr >= localVariablesInfos.length){
120 throw new AssertionViolatedException("Method number out of range.");
121 }
122 return localVariablesInfos[method_nr];
123 }
124
125 /**
126 * Pass 2 is the pass where static properties of the
127 * class file are checked without looking into "Code"
128 * arrays of methods.
129 * This verification pass is usually invoked when
130 * a class is resolved; and it may be possible that
131 * this verification pass has to load in other classes
132 * such as superclasses or implemented interfaces.
133 * Therefore, Pass 1 is run on them.<BR>
134 * Note that most referenced classes are <B>not</B> loaded
135 * in for verification or for an existance check by this
136 * pass; only the syntactical correctness of their names
137 * and descriptors (a.k.a. signatures) is checked.<BR>
138 * Very few checks that conceptually belong here
139 * are delayed until pass 3a in JustIce. JustIce does
140 * not only check for syntactical correctness but also
141 * for semantical sanity - therefore it needs access to
142 * the "Code" array of methods in a few cases. Please
143 * see the pass 3a documentation, too.
144 *
145 * @see org.apache.bcel.verifier.statics.Pass3aVerifier
146 */
147 public VerificationResult do_verify(){
148 try {
149 VerificationResult vr1 = myOwner.doPass1();
150 if (vr1.equals(VerificationResult.VR_OK)){
151
152 // For every method, we could have information about the local variables out of LocalVariableTable attributes of
153 // the Code attributes.
154 localVariablesInfos = new LocalVariablesInfo[Repository.lookupClass(myOwner.getClassName()).getMethods().length];
155
156 VerificationResult vr = VerificationResult.VR_OK; // default.
157 try{
158 constant_pool_entries_satisfy_static_constraints();
159 field_and_method_refs_are_valid();
160 every_class_has_an_accessible_superclass();
161 final_methods_are_not_overridden();
162 }
163 catch (ClassConstraintException cce){
164 vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
165 }
166 return vr;
167 } else {
168 return VerificationResult.VR_NOTYET;
169 }
170
171 } catch (ClassNotFoundException e) {
172 // FIXME: this might not be the best way to handle missing classes.
173 throw new AssertionViolatedException("Missing class: " + e.toString());
174 }
175 }
176
177 /**
178 * Ensures that every class has a super class and that
179 * <B>final</B> classes are not subclassed.
180 * This means, the class this Pass2Verifier operates
181 * on has proper super classes (transitively) up to
182 * java.lang.Object.
183 * The reason for really loading (and Pass1-verifying)
184 * all of those classes here is that we need them in
185 * Pass2 anyway to verify no final methods are overridden
186 * (that could be declared anywhere in the ancestor hierarchy).
187 *
188 * @throws ClassConstraintException otherwise.
189 */
190 private void every_class_has_an_accessible_superclass(){
191 try {
192 Set hs = new HashSet(); // save class names to detect circular inheritance
193 JavaClass jc = Repository.lookupClass(myOwner.getClassName());
194 int supidx = -1;
195
196 while (supidx != 0){
197 supidx = jc.getSuperclassNameIndex();
198
199 if (supidx == 0){
200 if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){
201 throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!");
202 }
203 }
204 else{
205 String supername = jc.getSuperclassName();
206 if (! hs.add(supername)){ // If supername already is in the list
207 throw new ClassConstraintException("Circular superclass hierarchy detected.");
208 }
209 Verifier v = VerifierFactory.getVerifier(supername);
210 VerificationResult vr = v.doPass1();
211
212 if (vr != VerificationResult.VR_OK){
213 throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'.");
214 }
215 jc = Repository.lookupClass(supername);
216
217 if (jc.isFinal()){
218 throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed.");
219 }
220 }
221 }
222
223 } catch (ClassNotFoundException e) {
224 // FIXME: this might not be the best way to handle missing classes.
225 throw new AssertionViolatedException("Missing class: " + e.toString());
226 }
227 }
228
229 /**
230 * Ensures that <B>final</B> methods are not overridden.
231 * <B>Precondition to run this method:
232 * constant_pool_entries_satisfy_static_constraints() and
233 * every_class_has_an_accessible_superclass() have to be invoked before
234 * (in that order).</B>
235 *
236 * @throws ClassConstraintException otherwise.
237 * @see #constant_pool_entries_satisfy_static_constraints()
238 * @see #every_class_has_an_accessible_superclass()
239 */
240 private void final_methods_are_not_overridden(){
241 try {
242 Map hashmap = new HashMap();
243 JavaClass jc = Repository.lookupClass(myOwner.getClassName());
244
245 int supidx = -1;
246 while (supidx != 0){
247 supidx = jc.getSuperclassNameIndex();
248
249 Method[] methods = jc.getMethods();
250 for (int i=0; i<methods.length; i++){
251 String name_and_sig = (methods[i].getName()+methods[i].getSignature());
252
253 if (hashmap.containsKey(name_and_sig)){
254 if ( methods[i].isFinal() ){
255 if (!(methods[i].isPrivate())) {
256 throw new ClassConstraintException("Method '"+name_and_sig+"' in class '"+hashmap.get(name_and_sig)+"' overrides the final (not-overridable) definition in class '"+jc.getClassName()+"'.");
257 }
258 else{
259 addMessage("Method '"+name_and_sig+"' in class '"+hashmap.get(name_and_sig)+"' overrides the final (not-overridable) definition in class '"+jc.getClassName()+"'. This is okay, as the original definition was private; however this constraint leverage was introduced by JLS 8.4.6 (not vmspec2) and the behaviour of the Sun verifiers.");
260 }
261 }
262 else{
263 if (!methods[i].isStatic()){ // static methods don't inherit
264 hashmap.put(name_and_sig, jc.getClassName());
265 }
266 }
267 }
268 else{
269 if (!methods[i].isStatic()){ // static methods don't inherit
270 hashmap.put(name_and_sig, jc.getClassName());
271 }
272 }
273 }
274
275 jc = Repository.lookupClass(jc.getSuperclassName()); // Well, for OBJECT this returns OBJECT so it works (could return anything but must not throw an Exception).
276 }
277
278 } catch (ClassNotFoundException e) {
279 // FIXME: this might not be the best way to handle missing classes.
280 throw new AssertionViolatedException("Missing class: " + e.toString());
281 }
282
283 }
284
285 /**
286 * Ensures that the constant pool entries satisfy the static constraints
287 * as described in The Java Virtual Machine Specification, 2nd Edition.
288 *
289 * @throws ClassConstraintException otherwise.
290 */
291 private void constant_pool_entries_satisfy_static_constraints(){
292 try {
293 // Most of the consistency is handled internally by BCEL; here
294 // we only have to verify if the indices of the constants point
295 // to constants of the appropriate type and such.
296 JavaClass jc = Repository.lookupClass(myOwner.getClassName());
297 new CPESSC_Visitor(jc); // constructor implicitely traverses jc
298
299 } catch (ClassNotFoundException e) {
300 // FIXME: this might not be the best way to handle missing classes.
301 throw new AssertionViolatedException("Missing class: " + e.toString());
302 }
303 }
304
305 /**
306 * A Visitor class that ensures the constant pool satisfies the static
307 * constraints.
308 * The visitXXX() methods throw ClassConstraintException instances otherwise.
309 *
310 * @see #constant_pool_entries_satisfy_static_constraints()
311 */
312 private class CPESSC_Visitor extends org.apache.bcel.classfile.EmptyVisitor implements Visitor{
313 private Class CONST_Class;
314 /*
315 private Class CONST_Fieldref;
316 private Class CONST_Methodref;
317 private Class CONST_InterfaceMethodref;
318 */
319 private Class CONST_String;
320 private Class CONST_Integer;
321 private Class CONST_Float;
322 private Class CONST_Long;
323 private Class CONST_Double;
324 private Class CONST_NameAndType;
325 private Class CONST_Utf8;
326
327 private final JavaClass jc;
328 private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work and computing power.
329 private final int cplen; // == cp.getLength() -- to save computing power.
330 private DescendingVisitor carrier;
331
332 private Set field_names = new HashSet();
333 private Set field_names_and_desc = new HashSet();
334 private Set method_names_and_desc = new HashSet();
335
336 private CPESSC_Visitor(JavaClass _jc){
337 jc = _jc;
338 cp = _jc.getConstantPool();
339 cplen = cp.getLength();
340
341 CONST_Class = org.apache.bcel.classfile.ConstantClass.class;
342 /*
343 CONST_Fieldref = org.apache.bcel.classfile.ConstantFieldref.class;
344 CONST_Methodref = org.apache.bcel.classfile.ConstantMethodref.class;
345 CONST_InterfaceMethodref = org.apache.bcel.classfile.ConstantInterfaceMethodref.class;
346 */
347 CONST_String = org.apache.bcel.classfile.ConstantString.class;
348 CONST_Integer = org.apache.bcel.classfile.ConstantInteger.class;
349 CONST_Float = org.apache.bcel.classfile.ConstantFloat.class;
350 CONST_Long = org.apache.bcel.classfile.ConstantLong.class;
351 CONST_Double = org.apache.bcel.classfile.ConstantDouble.class;
352 CONST_NameAndType = org.apache.bcel.classfile.ConstantNameAndType.class;
353 CONST_Utf8 = org.apache.bcel.classfile.ConstantUtf8.class;
354
355 carrier = new DescendingVisitor(_jc, this);
356 carrier.visit();
357 }
358
359 private void checkIndex(Node referrer, int index, Class shouldbe){
360 if ((index < 0) || (index >= cplen)){
361 throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(referrer)+"'.");
362 }
363 Constant c = cp.getConstant(index);
364 if (! shouldbe.isInstance(c)){
365 /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */
366 throw new ClassCastException("Illegal constant '"+tostring(c)+"' at index '"+index+"'. '"+tostring(referrer)+"' expects a '"+shouldbe+"'.");
367 }
368 }
369 ///////////////////////////////////////
370 // ClassFile structure (vmspec2 4.1) //
371 ///////////////////////////////////////
372 public void visitJavaClass(JavaClass obj){
373 Attribute[] atts = obj.getAttributes();
374 boolean foundSourceFile = false;
375 boolean foundInnerClasses = false;
376
377 // Is there an InnerClass referenced?
378 // This is a costly check; existing verifiers don't do it!
379 boolean hasInnerClass = new InnerClassDetector(jc).innerClassReferenced();
380
381 for (int i=0; i<atts.length; i++){
382 if ((! (atts[i] instanceof SourceFile)) &&
383 (! (atts[i] instanceof Deprecated)) &&
384 (! (atts[i] instanceof InnerClasses)) &&
385 (! (atts[i] instanceof Synthetic))){
386 addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of the ClassFile structure '"+tostring(obj)+"' is unknown and will therefore be ignored.");
387 }
388
389 if (atts[i] instanceof SourceFile){
390 if (foundSourceFile == false) {
391 foundSourceFile = true;
392 } else {
393 throw new ClassConstraintException("A ClassFile structure (like '"+tostring(obj)+"') may have no more than one SourceFile attribute."); //vmspec2 4.7.7
394 }
395 }
396
397 if (atts[i] instanceof InnerClasses){
398 if (foundInnerClasses == false) {
399 foundInnerClasses = true;
400 } else{
401 if (hasInnerClass){
402 throw new ClassConstraintException("A Classfile structure (like '"+tostring(obj)+"') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case). More than one InnerClasses attribute was found.");
403 }
404 }
405 if (!hasInnerClass){
406 addMessage("No referenced Inner Class found, but InnerClasses attribute '"+tostring(atts[i])+"' found. Strongly suggest removal of that attribute.");
407 }
408 }
409
410 }
411 if (hasInnerClass && !foundInnerClasses){
412 //throw new ClassConstraintException("A Classfile structure (like '"+tostring(obj)+"') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case). No InnerClasses attribute was found.");
413 //vmspec2, page 125 says it would be a constraint: but existing verifiers
414 //don't check it and javac doesn't satisfy it when it comes to anonymous
415 //inner classes
416 addMessage("A Classfile structure (like '"+tostring(obj)+"') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case). No InnerClasses attribute was found.");
417 }
418 }
419 /////////////////////////////
420 // CONSTANTS (vmspec2 4.4) //
421 /////////////////////////////
422 public void visitConstantClass(ConstantClass obj){
423 if (obj.getTag() != Constants.CONSTANT_Class){
424 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
425 }
426 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
427
428 }
429 public void visitConstantFieldref(ConstantFieldref obj){
430 if (obj.getTag() != Constants.CONSTANT_Fieldref){
431 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
432 }
433 checkIndex(obj, obj.getClassIndex(), CONST_Class);
434 checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
435 }
436 public void visitConstantMethodref(ConstantMethodref obj){
437 if (obj.getTag() != Constants.CONSTANT_Methodref){
438 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
439 }
440 checkIndex(obj, obj.getClassIndex(), CONST_Class);
441 checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
442 }
443 public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
444 if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
445 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
446 }
447 checkIndex(obj, obj.getClassIndex(), CONST_Class);
448 checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
449 }
450 public void visitConstantString(ConstantString obj){
451 if (obj.getTag() != Constants.CONSTANT_String){
452 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
453 }
454 checkIndex(obj, obj.getStringIndex(), CONST_Utf8);
455 }
456 public void visitConstantInteger(ConstantInteger obj){
457 if (obj.getTag() != Constants.CONSTANT_Integer){
458 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
459 }
460 // no indices to check
461 }
462 public void visitConstantFloat(ConstantFloat obj){
463 if (obj.getTag() != Constants.CONSTANT_Float){
464 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
465 }
466 //no indices to check
467 }
468 public void visitConstantLong(ConstantLong obj){
469 if (obj.getTag() != Constants.CONSTANT_Long){
470 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
471 }
472 //no indices to check
473 }
474 public void visitConstantDouble(ConstantDouble obj){
475 if (obj.getTag() != Constants.CONSTANT_Double){
476 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
477 }
478 //no indices to check
479 }
480 public void visitConstantNameAndType(ConstantNameAndType obj){
481 if (obj.getTag() != Constants.CONSTANT_NameAndType){
482 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
483 }
484 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
485 //checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below.
486 checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
487 }
488 public void visitConstantUtf8(ConstantUtf8 obj){
489 if (obj.getTag() != Constants.CONSTANT_Utf8){
490 throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
491 }
492 //no indices to check
493 }
494 //////////////////////////
495 // FIELDS (vmspec2 4.5) //
496 //////////////////////////
497 public void visitField(Field obj){
498
499 if (jc.isClass()){
500 int maxone=0;
501 if (obj.isPrivate()) {
502 maxone++;
503 }
504 if (obj.isProtected()) {
505 maxone++;
506 }
507 if (obj.isPublic()) {
508 maxone++;
509 }
510 if (maxone > 1){
511 throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
512 }
513
514 if (obj.isFinal() && obj.isVolatile()){
515 throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
516 }
517 }
518 else{ // isInterface!
519 if (!obj.isPublic()){
520 throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
521 }
522 if (!obj.isStatic()){
523 throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
524 }
525 if (!obj.isFinal()){
526 throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
527 }
528 }
529
530 if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
531 addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
532 }
533
534 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
535
536 String name = obj.getName();
537 if (! validFieldName(name)){
538 throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
539 }
540
541 // A descriptor is often named signature in BCEL
542 checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
543
544 String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
545
546 try{
547 Type.getType(sig); /* Don't need the return value */
548 }
549 catch (ClassFormatException cfe){
550 throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
551 }
552
553 String nameanddesc = (name+sig);
554 if (field_names_and_desc.contains(nameanddesc)){
555 throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
556 }
557 if (field_names.contains(name)){
558 addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
559 }
560 field_names_and_desc.add(nameanddesc);
561 field_names.add(name);
562
563 Attribute[] atts = obj.getAttributes();
564 for (int i=0; i<atts.length; i++){
565 if ((! (atts[i] instanceof ConstantValue)) &&
566 (! (atts[i] instanceof Synthetic)) &&
567 (! (atts[i] instanceof Deprecated))){
568 addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is unknown and will therefore be ignored.");
569 }
570 if (! (atts[i] instanceof ConstantValue)){
571 addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is not a ConstantValue and is therefore only of use for debuggers and such.");
572 }
573 }
574 }
575 ///////////////////////////
576 // METHODS (vmspec2 4.6) //
577 ///////////////////////////
578 public void visitMethod(Method obj){
579
580 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
581
582 String name = obj.getName();
583 if (! validMethodName(name, true)){
584 throw new ClassConstraintException("Method '"+tostring(obj)+"' has illegal name '"+name+"'.");
585 }
586
587 // A descriptor is often named signature in BCEL
588 checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
589
590 String sig = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Method's signature(=descriptor)
591
592 Type t;
593 Type[] ts; // needed below the try block.
594 try{
595 t = Type.getReturnType(sig);
596 ts = Type.getArgumentTypes(sig);
597 }
598 catch (ClassFormatException cfe){
599 throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by Method '"+tostring(obj)+"'.");
600 }
601
602 // Check if referenced objects exist.
603 Type act = t;
604 if (act instanceof ArrayType) {
605 act = ((ArrayType) act).getBasicType();
606 }
607 if (act instanceof ObjectType){
608 Verifier v = VerifierFactory.getVerifier( ((ObjectType) act).getClassName() );
609 VerificationResult vr = v.doPass1();
610 if (vr != VerificationResult.VR_OK) {
611 throw new ClassConstraintException("Method '"+tostring(obj)+"' has a return type that does not pass verification pass 1: '"+vr+"'.");
612 }
613 }
614
615 for (int i=0; i<ts.length; i++){
616 act = ts[i];
617 if (act instanceof ArrayType) {
618 act = ((ArrayType) act).getBasicType();
619 }
620 if (act instanceof ObjectType){
621 Verifier v = VerifierFactory.getVerifier( ((ObjectType) act).getClassName() );
622 VerificationResult vr = v.doPass1();
623 if (vr != VerificationResult.VR_OK) {
624 throw new ClassConstraintException("Method '"+tostring(obj)+"' has an argument type that does not pass verification pass 1: '"+vr+"'.");
625 }
626 }
627 }
628
629 // Nearly forgot this! Funny return values are allowed, but a non-empty arguments list makes a different method out of it!
630 if (name.equals(STATIC_INITIALIZER_NAME) && (ts.length != 0)){
631 throw new ClassConstraintException("Method '"+tostring(obj)+"' has illegal name '"+name+"'. It's name resembles the class or interface initialization method which it isn't because of its arguments (==descriptor).");
632 }
633
634 if (jc.isClass()){
635 int maxone=0;
636 if (obj.isPrivate()) {
637 maxone++;
638 }
639 if (obj.isProtected()) {
640 maxone++;
641 }
642 if (obj.isPublic()) {
643 maxone++;
644 }
645 if (maxone > 1){
646 throw new ClassConstraintException("Method '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
647 }
648
649 if (obj.isAbstract()){
650 if (obj.isFinal()) {
651 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_FINAL modifier set.");
652 }
653 if (obj.isNative()) {
654 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_NATIVE modifier set.");
655 }
656 if (obj.isPrivate()) {
657 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_PRIVATE modifier set.");
658 }
659 if (obj.isStatic()) {
660 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STATIC modifier set.");
661 }
662 if (obj.isStrictfp()) {
663 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_STRICT modifier set.");
664 }
665 if (obj.isSynchronized()) {
666 throw new ClassConstraintException("Abstract method '"+tostring(obj)+"' must not have the ACC_SYNCHRONIZED modifier set.");
667 }
668 }
669 }
670 else{ // isInterface!
671 if (!name.equals(STATIC_INITIALIZER_NAME)){//vmspec2, p.116, 2nd paragraph
672 if (!obj.isPublic()){
673 throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
674 }
675 if (!obj.isAbstract()){
676 throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
677 }
678 if ( obj.isPrivate() ||
679 obj.isProtected() ||
680 obj.isStatic() ||
681 obj.isFinal() ||
682 obj.isSynchronized() ||
683 obj.isNative() ||
684 obj.isStrictfp() ){
685 throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must not have any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT modifiers set.");
686 }
687 }
688 }
689
690 // A specific instance initialization method... (vmspec2,Page 116).
691 if (name.equals(CONSTRUCTOR_NAME)){
692 //..may have at most one of ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC set: is checked above.
693 //..may also have ACC_STRICT set, but none of the other flags in table 4.5 (vmspec2, page 115)
694 if ( obj.isStatic() ||
695 obj.isFinal() ||
696 obj.isSynchronized() ||
697 obj.isNative() ||
698 obj.isAbstract() ){
699 throw new ClassConstraintException("Instance initialization method '"+tostring(obj)+"' must not have any of the ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT modifiers set.");
700 }
701 }
702
703 // Class and interface initialization methods...
704 if (name.equals(STATIC_INITIALIZER_NAME)){
705 if ((obj.getAccessFlags() & (~ACC_STRICT)) > 0){
706 addMessage("Class or interface initialization method '"+tostring(obj)+"' has superfluous access modifier(s) set: everything but ACC_STRICT is ignored.");
707 }
708 if (obj.isAbstract()){
709 throw new ClassConstraintException("Class or interface initialization method '"+tostring(obj)+"' must not be abstract. This contradicts the Java Language Specification, Second Edition (which omits this constraint) but is common practice of existing verifiers.");
710 }
711 }
712
713 if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE|ACC_ABSTRACT|ACC_STRICT)) > 0){
714 addMessage("Method '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT set (ignored).");
715 }
716
717 String nameanddesc = (name+sig);
718 if (method_names_and_desc.contains(nameanddesc)){
719 throw new ClassConstraintException("No two methods (like '"+tostring(obj)+"') are allowed have same names and desciptors!");
720 }
721 method_names_and_desc.add(nameanddesc);
722
723 Attribute[] atts = obj.getAttributes();
724 int num_code_atts = 0;
725 for (int i=0; i<atts.length; i++){
726 if ((! (atts[i] instanceof Code)) &&
727 (! (atts[i] instanceof ExceptionTable)) &&
728 (! (atts[i] instanceof Synthetic)) &&
729 (! (atts[i] instanceof Deprecated))){
730 addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Method '"+tostring(obj)+"' is unknown and will therefore be ignored.");
731 }
732 if ((! (atts[i] instanceof Code)) &&
733 (! (atts[i] instanceof ExceptionTable))){
734 addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Method '"+tostring(obj)+"' is neither Code nor Exceptions and is therefore only of use for debuggers and such.");
735 }
736 if ((atts[i] instanceof Code) && (obj.isNative() || obj.isAbstract())){
737 throw new ClassConstraintException("Native or abstract methods like '"+tostring(obj)+"' must not have a Code attribute like '"+tostring(atts[i])+"'."); //vmspec2 page120, 4.7.3
738 }
739 if (atts[i] instanceof Code) {
740 num_code_atts++;
741 }
742 }
743 if ( !obj.isNative() && !obj.isAbstract() && num_code_atts != 1){
744 throw new ClassConstraintException("Non-native, non-abstract methods like '"+tostring(obj)+"' must have exactly one Code attribute (found: "+num_code_atts+").");
745 }
746 }
747 ///////////////////////////////////////////////////////
748 // ClassFile-structure-ATTRIBUTES (vmspec2 4.1, 4.7) //
749 ///////////////////////////////////////////////////////
750 public void visitSourceFile(SourceFile obj){//vmspec2 4.7.7
751
752 // zero or one SourceFile attr per ClassFile: see visitJavaClass()
753
754 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
755
756 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
757 if (! name.equals("SourceFile")){
758 throw new ClassConstraintException("The SourceFile attribute '"+tostring(obj)+"' is not correctly named 'SourceFile' but '"+name+"'.");
759 }
760
761 checkIndex(obj, obj.getSourceFileIndex(), CONST_Utf8);
762
763 String sourcefilename = ((ConstantUtf8) cp.getConstant(obj.getSourceFileIndex())).getBytes(); //==obj.getSourceFileName() ?
764 String sourcefilenamelc = sourcefilename.toLowerCase(Locale.ENGLISH);
765
766 if ( (sourcefilename.indexOf('/') != -1) ||
767 (sourcefilename.indexOf('\\') != -1) ||
768 (sourcefilename.indexOf(':') != -1) ||
769 (sourcefilenamelc.lastIndexOf(".java") == -1) ){
770 addMessage("SourceFile attribute '"+tostring(obj)+"' has a funny name: remember not to confuse certain parsers working on javap's output. Also, this name ('"+sourcefilename+"') is considered an unqualified (simple) file name only.");
771 }
772 }
773 public void visitDeprecated(Deprecated obj){//vmspec2 4.7.10
774 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
775
776 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
777 if (! name.equals("Deprecated")){
778 throw new ClassConstraintException("The Deprecated attribute '"+tostring(obj)+"' is not correctly named 'Deprecated' but '"+name+"'.");
779 }
780 }
781 public void visitSynthetic(Synthetic obj){//vmspec2 4.7.6
782 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
783 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
784 if (! name.equals("Synthetic")){
785 throw new ClassConstraintException("The Synthetic attribute '"+tostring(obj)+"' is not correctly named 'Synthetic' but '"+name+"'.");
786 }
787 }
788 public void visitInnerClasses(InnerClasses obj){//vmspec2 4.7.5
789
790 // exactly one InnerClasses attr per ClassFile if some inner class is refernced: see visitJavaClass()
791
792 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
793
794 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
795 if (! name.equals("InnerClasses")){
796 throw new ClassConstraintException("The InnerClasses attribute '"+tostring(obj)+"' is not correctly named 'InnerClasses' but '"+name+"'.");
797 }
798
799 InnerClass[] ics = obj.getInnerClasses();
800
801 for (int i=0; i<ics.length; i++){
802 checkIndex(obj, ics[i].getInnerClassIndex(), CONST_Class);
803 int outer_idx = ics[i].getOuterClassIndex();
804 if (outer_idx != 0){
805 checkIndex(obj, outer_idx, CONST_Class);
806 }
807 int innername_idx = ics[i].getInnerNameIndex();
808 if (innername_idx != 0){
809 checkIndex(obj, innername_idx, CONST_Utf8);
810 }
811 int acc = ics[i].getInnerAccessFlags();
812 acc = acc & (~ (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL | ACC_INTERFACE | ACC_ABSTRACT));
813 if (acc != 0){
814 addMessage("Unknown access flag for inner class '"+tostring(ics[i])+"' set (InnerClasses attribute '"+tostring(obj)+"').");
815 }
816 }
817 // Semantical consistency is not yet checked by Sun, see vmspec2 4.7.5.
818 // [marked TODO in JustIce]
819 }
820 ////////////////////////////////////////////////////////
821 // field_info-structure-ATTRIBUTES (vmspec2 4.5, 4.7) //
822 ////////////////////////////////////////////////////////
823 public void visitConstantValue(ConstantValue obj){//vmspec2 4.7.2
824 // Despite its name, this really is an Attribute,
825 // not a constant!
826 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
827
828 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
829 if (! name.equals("ConstantValue")){
830 throw new ClassConstraintException("The ConstantValue attribute '"+tostring(obj)+"' is not correctly named 'ConstantValue' but '"+name+"'.");
831 }
832
833 Object pred = carrier.predecessor();
834 if (pred instanceof Field){ //ConstantValue attributes are quite senseless if the predecessor is not a field.
835 Field f = (Field) pred;
836 // Field constraints have been checked before -- so we are safe using their type information.
837 Type field_type = Type.getType(((ConstantUtf8) (cp.getConstant(f.getSignatureIndex()))).getBytes());
838
839 int index = obj.getConstantValueIndex();
840 if ((index < 0) || (index >= cplen)){
841 throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'.");
842 }
843 Constant c = cp.getConstant(index);
844
845 if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){
846 return;
847 }
848 if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){
849 return;
850 }
851 if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)){
852 return;
853 }
854 if (CONST_Integer.isInstance(c) && (field_type.equals(Type.INT) || field_type.equals(Type.SHORT) || field_type.equals(Type.CHAR) || field_type.equals(Type.BYTE) || field_type.equals(Type.BOOLEAN))){
855 return;
856 }
857 if (CONST_String.isInstance(c) && field_type.equals(Type.STRING)){
858 return;
859 }
860
861 throw new ClassConstraintException("Illegal type of ConstantValue '"+obj+"' embedding Constant '"+c+"'. It is referenced by field '"+tostring(f)+"' expecting a different type: '"+field_type+"'.");
862 }
863 }
864 // SYNTHETIC: see above
865 // DEPRECATED: see above
866 /////////////////////////////////////////////////////////
867 // method_info-structure-ATTRIBUTES (vmspec2 4.6, 4.7) //
868 /////////////////////////////////////////////////////////
869 public void visitCode(Code obj){//vmspec2 4.7.3
870 try {
871 // No code attribute allowed for native or abstract methods: see visitMethod(Method).
872 // Code array constraints are checked in Pass3 (3a and 3b).
873
874 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
875
876 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
877 if (! name.equals("Code")){
878 throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'.");
879 }
880
881 Method m = null; // satisfy compiler
882 if (!(carrier.predecessor() instanceof Method)){
883 addMessage("Code attribute '"+tostring(obj)+"' is not declared in a method_info structure but in '"+carrier.predecessor()+"'. Ignored.");
884 return;
885 }
886 else{
887 m = (Method) carrier.predecessor(); // we can assume this method was visited before;
888 // i.e. the data consistency was verified.
889 }
890
891 if (obj.getCode().length == 0){
892 throw new ClassConstraintException("Code array of Code attribute '"+tostring(obj)+"' (method '"+m+"') must not be empty.");
893 }
894
895 //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
896 CodeException[] exc_table = obj.getExceptionTable();
897 for (int i=0; i<exc_table.length; i++){
898 int exc_index = exc_table[i].getCatchType();
899 if (exc_index != 0){ // if 0, it catches all Throwables
900 checkIndex(obj, exc_index, CONST_Class);
901 ConstantClass cc = (ConstantClass) (cp.getConstant(exc_index));
902 checkIndex(cc, cc.getNameIndex(), CONST_Utf8); // cannot be sure this ConstantClass has already been visited (checked)!
903 String cname = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes().replace('/','.');
904
905 Verifier v = VerifierFactory.getVerifier(cname);
906 VerificationResult vr = v.doPass1();
907
908 if (vr != VerificationResult.VR_OK){
909 throw new ClassConstraintException("Code attribute '"+tostring(obj)+"' (method '"+m+"') has an exception_table entry '"+tostring(exc_table[i])+"' that references '"+cname+"' as an Exception but it does not pass verification pass 1: "+vr);
910 }
911 else{
912 // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
913 // the ancestor hierarchy.
914 JavaClass e = Repository.lookupClass(cname);
915 JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
916 JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
917 while (e != o){
918 if (e == t) {
919 break; // It's a subclass of Throwable, OKAY, leave.
920 }
921
922 v = VerifierFactory.getVerifier(e.getSuperclassName());
923 vr = v.doPass1();
924 if (vr != VerificationResult.VR_OK){
925 throw new ClassConstraintException("Code attribute '"+tostring(obj)+"' (method '"+m+"') has an exception_table entry '"+tostring(exc_table[i])+"' that references '"+cname+"' as an Exception but '"+e.getSuperclassName()+"' in the ancestor hierachy does not pass verification pass 1: "+vr);
926 }
927 else{
928 e = Repository.lookupClass(e.getSuperclassName());
929 }
930 }
931 if (e != t) {
932 throw new ClassConstraintException("Code attribute '"+tostring(obj)+"' (method '"+m+"') has an exception_table entry '"+tostring(exc_table[i])+"' that references '"+cname+"' as an Exception but it is not a subclass of '"+t.getClassName()+"'.");
933 }
934 }
935 }
936 }
937
938 // Create object for local variables information
939 // This is highly unelegant due to usage of the Visitor pattern.
940 // TODO: rework it.
941 int method_number = -1;
942 Method[] ms = Repository.lookupClass(myOwner.getClassName()).getMethods();
943 for (int mn=0; mn<ms.length; mn++){
944 if (m == ms[mn]){
945 method_number = mn;
946 break;
947 }
948 }
949 if (method_number < 0){ // Mmmmh. Can we be sure BCEL does not sometimes instantiate new objects?
950 throw new AssertionViolatedException("Could not find a known BCEL Method object in the corresponding BCEL JavaClass object.");
951 }
952 localVariablesInfos[method_number] = new LocalVariablesInfo(obj.getMaxLocals());
953
954 int num_of_lvt_attribs = 0;
955 // Now iterate through the attributes the Code attribute has.
956 Attribute[] atts = obj.getAttributes();
957 for (int a=0; a<atts.length; a++){
958 if ((! (atts[a] instanceof LineNumberTable)) &&
959 (! (atts[a] instanceof LocalVariableTable))){
960 addMessage("Attribute '"+tostring(atts[a])+"' as an attribute of Code attribute '"+tostring(obj)+"' (method '"+m+"') is unknown and will therefore be ignored.");
961 }
962 else{// LineNumberTable or LocalVariableTable
963 addMessage("Attribute '"+tostring(atts[a])+"' as an attribute of Code attribute '"+tostring(obj)+"' (method '"+m+"') will effectively be ignored and is only useful for debuggers and such.");
964 }
965
966 //LocalVariableTable check (partially delayed to Pass3a).
967 //Here because its easier to collect the information of the
968 //(possibly more than one) LocalVariableTables belonging to
969 //one certain Code attribute.
970 if (atts[a] instanceof LocalVariableTable){ // checks conforming to vmspec2 4.7.9
971
972 LocalVariableTable lvt = (LocalVariableTable) atts[a];
973
974 checkIndex(lvt, lvt.getNameIndex(), CONST_Utf8);
975
976 String lvtname = ((ConstantUtf8) cp.getConstant(lvt.getNameIndex())).getBytes();
977 if (! lvtname.equals("LocalVariableTable")){
978 throw new ClassConstraintException("The LocalVariableTable attribute '"+tostring(lvt)+"' is not correctly named 'LocalVariableTable' but '"+lvtname+"'.");
979 }
980
981 Code code = obj;
982
983 //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
984 LocalVariable[] localvariables = lvt.getLocalVariableTable();
985
986 for (int i=0; i<localvariables.length; i++){
987 checkIndex(lvt, localvariables[i].getNameIndex(), CONST_Utf8);
988 String localname = ((ConstantUtf8) cp.getConstant(localvariables[i].getNameIndex())).getBytes();
989 if (!validJavaIdentifier(localname)){
990 throw new ClassConstraintException("LocalVariableTable '"+tostring(lvt)+"' references a local variable by the name '"+localname+"' which is not a legal Java simple name.");
991 }
992
993 checkIndex(lvt, localvariables[i].getSignatureIndex(), CONST_Utf8);
994 String localsig = ((ConstantUtf8) (cp.getConstant(localvariables[i].getSignatureIndex()))).getBytes(); // Local signature(=descriptor)
995 Type t;
996 try{
997 t = Type.getType(localsig);
998 }
999 catch (ClassFormatException cfe){
1000 throw new ClassConstraintException("Illegal descriptor (==signature) '"+localsig+"' used by LocalVariable '"+tostring(localvariables[i])+"' referenced by '"+tostring(lvt)+"'.");
1001 }
1002 int localindex = localvariables[i].getIndex();
1003 if ( ( (t==Type.LONG || t==Type.DOUBLE)? localindex+1:localindex) >= code.getMaxLocals()){
1004 throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'.");
1005 }
1006
1007 try{
1008 localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t);
1009 }
1010 catch(LocalVariableInfoInconsistentException lviie){
1011 throw new ClassConstraintException("Conflicting information in LocalVariableTable '"+tostring(lvt)+"' found in Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"'). "+lviie.getMessage());
1012 }
1013 }// for all local variables localvariables[i] in the LocalVariableTable attribute atts[a] END
1014
1015 num_of_lvt_attribs++;
1016 if (num_of_lvt_attribs > obj.getMaxLocals()){
1017 throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.').");
1018 }
1019 }// if atts[a] instanceof LocalVariableTable END
1020 }// for all attributes atts[a] END
1021
1022 } catch (ClassNotFoundException e) {
1023 // FIXME: this might not be the best way to handle missing classes.
1024 throw new AssertionViolatedException("Missing class: " + e.toString());
1025 }
1026
1027 }// visitCode(Code) END
1028
1029 public void visitExceptionTable(ExceptionTable obj){//vmspec2 4.7.4
1030 try {
1031 // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4)
1032 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
1033
1034 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
1035 if (! name.equals("Exceptions")){
1036 throw new ClassConstraintException("The Exceptions attribute '"+tostring(obj)+"' is not correctly named 'Exceptions' but '"+name+"'.");
1037 }
1038
1039 int[] exc_indices = obj.getExceptionIndexTable();
1040
1041 for (int i=0; i<exc_indices.length; i++){
1042 checkIndex(obj, exc_indices[i], CONST_Class);
1043
1044 ConstantClass cc = (ConstantClass) (cp.getConstant(exc_indices[i]));
1045 checkIndex(cc, cc.getNameIndex(), CONST_Utf8); // cannot be sure this ConstantClass has already been visited (checked)!
1046 String cname = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes().replace('/','.'); //convert internal notation on-the-fly to external notation
1047
1048 Verifier v = VerifierFactory.getVerifier(cname);
1049 VerificationResult vr = v.doPass1();
1050
1051 if (vr != VerificationResult.VR_OK){
1052 throw new ClassConstraintException("Exceptions attribute '"+tostring(obj)+"' references '"+cname+"' as an Exception but it does not pass verification pass 1: "+vr);
1053 }
1054 else{
1055 // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
1056 // the ancestor hierarchy.
1057 JavaClass e = Repository.lookupClass(cname);
1058 JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
1059 JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
1060 while (e != o){
1061 if (e == t) {
1062 break; // It's a subclass of Throwable, OKAY, leave.
1063 }
1064
1065 v = VerifierFactory.getVerifier(e.getSuperclassName());
1066 vr = v.doPass1();
1067 if (vr != VerificationResult.VR_OK){
1068 throw new ClassConstraintException("Exceptions attribute '"+tostring(obj)+"' references '"+cname+"' as an Exception but '"+e.getSuperclassName()+"' in the ancestor hierachy does not pass verification pass 1: "+vr);
1069 }
1070 else{
1071 e = Repository.lookupClass(e.getSuperclassName());
1072 }
1073 }
1074 if (e != t) {
1075 throw new ClassConstraintException("Exceptions attribute '"+tostring(obj)+"' references '"+cname+"' as an Exception but it is not a subclass of '"+t.getClassName()+"'.");
1076 }
1077 }
1078 }
1079
1080 } catch (ClassNotFoundException e) {
1081 // FIXME: this might not be the best way to handle missing classes.
1082 throw new AssertionViolatedException("Missing class: " + e.toString());
1083 }
1084 }
1085 // SYNTHETIC: see above
1086 // DEPRECATED: see above
1087 //////////////////////////////////////////////////////////////
1088 // code_attribute-structure-ATTRIBUTES (vmspec2 4.7.3, 4.7) //
1089 //////////////////////////////////////////////////////////////
1090 public void visitLineNumberTable(LineNumberTable obj){//vmspec2 4.7.8
1091 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
1092
1093 String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
1094 if (! name.equals("LineNumberTable")){
1095 throw new ClassConstraintException("The LineNumberTable attribute '"+tostring(obj)+"' is not correctly named 'LineNumberTable' but '"+name+"'.");
1096 }
1097
1098 //In JustIce,this check is delayed to Pass 3a.
1099 //LineNumber[] linenumbers = obj.getLineNumberTable();
1100 // ...validity check...
1101
1102 }
1103 public void visitLocalVariableTable(LocalVariableTable obj){//vmspec2 4.7.9
1104 //In JustIce,this check is partially delayed to Pass 3a.
1105 //The other part can be found in the visitCode(Code) method.
1106 }
1107 ////////////////////////////////////////////////////
1108 // MISC-structure-ATTRIBUTES (vmspec2 4.7.1, 4.7) //
1109 ////////////////////////////////////////////////////
1110 public void visitUnknown(Unknown obj){//vmspec2 4.7.1
1111 // Represents an unknown attribute.
1112 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
1113
1114 // Maybe only misnamed? Give a (warning) message.
1115 addMessage("Unknown attribute '"+tostring(obj)+"'. This attribute is not known in any context!");
1116 }
1117 //////////
1118 // BCEL //
1119 //////////
1120 public void visitLocalVariable(LocalVariable obj){
1121 // This does not represent an Attribute but is only
1122 // related to internal BCEL data representation.
1123
1124 // see visitLocalVariableTable(LocalVariableTable)
1125 }
1126 public void visitCodeException(CodeException obj){
1127 // Code constraints are checked in Pass3 (3a and 3b).
1128 // This does not represent an Attribute but is only
1129 // related to internal BCEL data representation.
1130
1131 // see visitCode(Code)
1132 }
1133 public void visitConstantPool(ConstantPool obj){
1134 // No need to. We're piggybacked by the DescendingVisitor.
1135 // This does not represent an Attribute but is only
1136 // related to internal BCEL data representation.
1137 }
1138 public void visitInnerClass(InnerClass obj){
1139 // This does not represent an Attribute but is only
1140 // related to internal BCEL data representation.
1141 }
1142 public void visitLineNumber(LineNumber obj){
1143 // This does not represent an Attribute but is only
1144 // related to internal BCEL data representation.
1145
1146 // see visitLineNumberTable(LineNumberTable)
1147 }
1148 }
1149
1150 /**
1151 * Ensures that the ConstantCP-subclassed entries of the constant
1152 * pool are valid. According to "Yellin: Low Level Security in Java",
1153 * this method does not verify the existence of referenced entities
1154 * (such as classes) but only the formal correctness (such as well-formed
1155 * signatures).
1156 * The visitXXX() methods throw ClassConstraintException instances otherwise.
1157 * <B>Precondition: index-style cross referencing in the constant
1158 * pool must be valid. Simply invoke constant_pool_entries_satisfy_static_constraints()
1159 * before.</B>
1160 *
1161 * @throws ClassConstraintException otherwise.
1162 * @see #constant_pool_entries_satisfy_static_constraints()
1163 */
1164 private void field_and_method_refs_are_valid(){
1165 try {
1166 JavaClass jc = Repository.lookupClass(myOwner.getClassName());
1167 DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc));
1168 v.visit();
1169
1170 } catch (ClassNotFoundException e) {
1171 // FIXME: this might not be the best way to handle missing classes.
1172 throw new AssertionViolatedException("Missing class: " + e.toString());
1173 }
1174 }
1175
1176 /**
1177 * A Visitor class that ensures the ConstantCP-subclassed entries
1178 * of the constant pool are valid.
1179 * <B>Precondition: index-style cross referencing in the constant
1180 * pool must be valid.</B>
1181 *
1182 * @see #constant_pool_entries_satisfy_static_constraints()
1183 * @see org.apache.bcel.classfile.ConstantCP
1184 */
1185 private class FAMRAV_Visitor extends EmptyVisitor implements Visitor{
1186 private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work.
1187 private FAMRAV_Visitor(JavaClass _jc){
1188 cp = _jc.getConstantPool();
1189 }
1190
1191 public void visitConstantFieldref(ConstantFieldref obj){
1192 if (obj.getTag() != Constants.CONSTANT_Fieldref){
1193 throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!");
1194 }
1195 int name_and_type_index = obj.getNameAndTypeIndex();
1196 ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
1197 String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
1198 if (!validFieldName(name)){
1199 throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'.");
1200 }
1201
1202 int class_index = obj.getClassIndex();
1203 ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
1204 String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
1205 if (! validClassName(className)){
1206 throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
1207 }
1208
1209 String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
1210
1211 try{
1212 Type.getType(sig); /* Don't need the return value */
1213 }
1214 catch (ClassFormatException cfe){
1215 throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
1216 }
1217 }
1218
1219 public void visitConstantMethodref(ConstantMethodref obj){
1220 if (obj.getTag() != Constants.CONSTANT_Methodref){
1221 throw new ClassConstraintException("ConstantMethodref '"+tostring(obj)+"' has wrong tag!");
1222 }
1223 int name_and_type_index = obj.getNameAndTypeIndex();
1224 ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
1225 String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
1226 if (!validClassMethodName(name)){
1227 throw new ClassConstraintException("Invalid (non-interface) method name '"+name+"' referenced by '"+tostring(obj)+"'.");
1228 }
1229
1230 int class_index = obj.getClassIndex();
1231 ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
1232 String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
1233 if (! validClassName(className)){
1234 throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
1235 }
1236
1237 String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
1238
1239 try{
1240 Type t = Type.getReturnType(sig);
1241 if ( name.equals(CONSTRUCTOR_NAME) && (t != Type.VOID) ){
1242 throw new ClassConstraintException("Instance initialization method must have VOID return type.");
1243 }
1244 }
1245 catch (ClassFormatException cfe){
1246 throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
1247 }
1248 }
1249
1250 public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
1251 if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
1252 throw new ClassConstraintException("ConstantInterfaceMethodref '"+tostring(obj)+"' has wrong tag!");
1253 }
1254 int name_and_type_index = obj.getNameAndTypeIndex();
1255 ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
1256 String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
1257 if (!validInterfaceMethodName(name)){
1258 throw new ClassConstraintException("Invalid (interface) method name '"+name+"' referenced by '"+tostring(obj)+"'.");
1259 }
1260
1261 int class_index = obj.getClassIndex();
1262 ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
1263 String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
1264 if (! validClassName(className)){
1265 throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
1266 }
1267
1268 String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
1269
1270 try{
1271 Type t = Type.getReturnType(sig);
1272 if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){
1273 addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
1274 }
1275 }
1276 catch (ClassFormatException cfe){
1277 throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
1278 }
1279
1280 }
1281
1282 }
1283
1284 /**
1285 * This method returns true if and only if the supplied String
1286 * represents a valid Java class name.
1287 */
1288 private static final boolean validClassName(String name){
1289 /*
1290 * TODO: implement.
1291 * Are there any restrictions?
1292 */
1293 return true;
1294 }
1295 /**
1296 * This method returns true if and only if the supplied String
1297 * represents a valid method name.
1298 * This is basically the same as a valid identifier name in the
1299 * Java programming language, but the special name for
1300 * the instance initialization method is allowed and the special name
1301 * for the class/interface initialization method may be allowed.
1302 */
1303 private static boolean validMethodName(String name, boolean allowStaticInit){
1304 if (validJavaLangMethodName(name)) {
1305 return true;
1306 }
1307
1308 if (allowStaticInit){
1309 return (name.equals(CONSTRUCTOR_NAME) || name.equals(STATIC_INITIALIZER_NAME));
1310 }
1311 else{
1312 return name.equals(CONSTRUCTOR_NAME);
1313 }
1314 }
1315
1316 /**
1317 * This method returns true if and only if the supplied String
1318 * represents a valid method name that may be referenced by
1319 * ConstantMethodref objects.
1320 */
1321 private static boolean validClassMethodName(String name){
1322 return validMethodName(name, false);
1323 }
1324
1325 /**
1326 * This method returns true if and only if the supplied String
1327 * represents a valid Java programming language method name stored as a simple
1328 * (non-qualified) name.
1329 * Conforming to: The Java Virtual Machine Specification, Second Edition, §2.7, §2.7.1, §2.2.
1330 */
1331 private static boolean validJavaLangMethodName(String name){
1332 if (!Character.isJavaIdentifierStart(name.charAt(0))) {
1333 return false;
1334 }
1335
1336 for (int i=1; i<name.length(); i++){
1337 if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1338 return false;
1339 }
1340 }
1341 return true;
1342 }
1343
1344 /**
1345 * This method returns true if and only if the supplied String
1346 * represents a valid Java interface method name that may be
1347 * referenced by ConstantInterfaceMethodref objects.
1348 */
1349 private static boolean validInterfaceMethodName(String name){
1350 // I guess we should assume special names forbidden here.
1351 if (name.startsWith("<")) {
1352 return false;
1353 }
1354 return validJavaLangMethodName(name);
1355 }
1356
1357 /**
1358 * This method returns true if and only if the supplied String
1359 * represents a valid Java identifier (so-called simple name).
1360 */
1361 private static boolean validJavaIdentifier(String name){
1362 if (name.length() == 0) {
1363 return false; // must not be empty, reported by <francis.andre@easynet.fr>, thanks!
1364 }
1365
1366 // vmspec2 2.7, vmspec2 2.2
1367 if (!Character.isJavaIdentifierStart(name.charAt(0))) {
1368 return false;
1369 }
1370
1371 for (int i=1; i<name.length(); i++){
1372 if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1373 return false;
1374 }
1375 }
1376 return true;
1377 }
1378
1379 /**
1380 * This method returns true if and only if the supplied String
1381 * represents a valid Java field name.
1382 */
1383 private static boolean validFieldName(String name){
1384 // vmspec2 2.7, vmspec2 2.2
1385 return validJavaIdentifier(name);
1386 }
1387
1388 /**
1389 * This class serves for finding out if a given JavaClass' ConstantPool
1390 * references an Inner Class.
1391 * The Java Virtual Machine Specification, Second Edition is not very precise
1392 * about when an "InnerClasses" attribute has to appear. However, it states that
1393 * there has to be exactly one InnerClasses attribute in the ClassFile structure
1394 * if the constant pool of a class or interface refers to any class or interface
1395 * "that is not a member of a package". Sun does not mean "member of the default
1396 * package". In "Inner Classes Specification" they point out how a "bytecode name"
1397 * is derived so one has to deduce what a class name of a class "that is not a
1398 * member of a package" looks like: there is at least one character in the byte-
1399 * code name that cannot be part of a legal Java Language Class name (and not equal
1400 * to '/'). This assumption is wrong as the delimiter is '$' for which
1401 * Character.isJavaIdentifierPart() == true.
1402 * Hence, you really run into trouble if you have a toplevel class called
1403 * "A$XXX" and another toplevel class called "A" with in inner class called "XXX".
1404 * JustIce cannot repair this; please note that existing verifiers at this
1405 * time even fail to detect missing InnerClasses attributes in pass 2.
1406 */
1407 private static class InnerClassDetector extends EmptyVisitor{
1408 private boolean hasInnerClass = false;
1409 private JavaClass jc;
1410 private ConstantPool cp;
1411
1412 /** Constructs an InnerClassDetector working on the JavaClass _jc. */
1413 public InnerClassDetector(JavaClass _jc){
1414 jc = _jc;
1415 cp = jc.getConstantPool();
1416 (new DescendingVisitor(jc, this)).visit();
1417 }
1418 /**
1419 * Returns if the JavaClass this InnerClassDetector is working on
1420 * has an Inner Class reference in its constant pool.
1421 */
1422 public boolean innerClassReferenced(){
1423 return hasInnerClass;
1424 }
1425 /** This method casually visits ConstantClass references. */
1426 public void visitConstantClass(ConstantClass obj){
1427 Constant c = cp.getConstant(obj.getNameIndex());
1428 if (c instanceof ConstantUtf8){ //Ignore the case where it's not a ConstantUtf8 here, we'll find out later.
1429 String classname = ((ConstantUtf8) c).getBytes();
1430 if (classname.startsWith(jc.getClassName().replace('.','/')+"$")){
1431 hasInnerClass = true;
1432 }
1433 }
1434 }
1435 }
1436
1437 /**
1438 * This method is here to save typing work and improve code readability.
1439 */
1440 private static String tostring(Node n){
1441 return new StringRepresentation(n).toString();
1442 }
1443 }
+0
-1222
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.Repository;
21 import org.apache.bcel.classfile.Attribute;
22 import org.apache.bcel.classfile.Code;
23 import org.apache.bcel.classfile.CodeException;
24 import org.apache.bcel.classfile.Constant;
25 import org.apache.bcel.classfile.ConstantClass;
26 import org.apache.bcel.classfile.ConstantDouble;
27 import org.apache.bcel.classfile.ConstantFieldref;
28 import org.apache.bcel.classfile.ConstantFloat;
29 import org.apache.bcel.classfile.ConstantInteger;
30 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
31 import org.apache.bcel.classfile.ConstantLong;
32 import org.apache.bcel.classfile.ConstantMethodref;
33 import org.apache.bcel.classfile.ConstantNameAndType;
34 import org.apache.bcel.classfile.ConstantString;
35 import org.apache.bcel.classfile.ConstantUtf8;
36 import org.apache.bcel.classfile.Field;
37 import org.apache.bcel.classfile.JavaClass;
38 import org.apache.bcel.classfile.LineNumber;
39 import org.apache.bcel.classfile.LineNumberTable;
40 import org.apache.bcel.classfile.LocalVariable;
41 import org.apache.bcel.classfile.LocalVariableTable;
42 import org.apache.bcel.classfile.Method;
43 import org.apache.bcel.generic.ALOAD;
44 import org.apache.bcel.generic.ANEWARRAY;
45 import org.apache.bcel.generic.ASTORE;
46 import org.apache.bcel.generic.ATHROW;
47 import org.apache.bcel.generic.ArrayType;
48 import org.apache.bcel.generic.BREAKPOINT;
49 import org.apache.bcel.generic.CHECKCAST;
50 import org.apache.bcel.generic.ConstantPoolGen;
51 import org.apache.bcel.generic.DLOAD;
52 import org.apache.bcel.generic.DSTORE;
53 import org.apache.bcel.generic.FLOAD;
54 import org.apache.bcel.generic.FSTORE;
55 import org.apache.bcel.generic.FieldInstruction;
56 import org.apache.bcel.generic.GETSTATIC;
57 import org.apache.bcel.generic.GotoInstruction;
58 import org.apache.bcel.generic.IINC;
59 import org.apache.bcel.generic.ILOAD;
60 import org.apache.bcel.generic.IMPDEP1;
61 import org.apache.bcel.generic.IMPDEP2;
62 import org.apache.bcel.generic.INSTANCEOF;
63 import org.apache.bcel.generic.INVOKEINTERFACE;
64 import org.apache.bcel.generic.INVOKESPECIAL;
65 import org.apache.bcel.generic.INVOKESTATIC;
66 import org.apache.bcel.generic.INVOKEVIRTUAL;
67 import org.apache.bcel.generic.ISTORE;
68 import org.apache.bcel.generic.Instruction;
69 import org.apache.bcel.generic.InstructionHandle;
70 import org.apache.bcel.generic.InstructionList;
71 import org.apache.bcel.generic.InvokeInstruction;
72 import org.apache.bcel.generic.JsrInstruction;
73 import org.apache.bcel.generic.LDC;
74 import org.apache.bcel.generic.LDC2_W;
75 import org.apache.bcel.generic.LLOAD;
76 import org.apache.bcel.generic.LOOKUPSWITCH;
77 import org.apache.bcel.generic.LSTORE;
78 import org.apache.bcel.generic.LoadClass;
79 import org.apache.bcel.generic.MULTIANEWARRAY;
80 import org.apache.bcel.generic.NEW;
81 import org.apache.bcel.generic.NEWARRAY;
82 import org.apache.bcel.generic.ObjectType;
83 import org.apache.bcel.generic.PUTSTATIC;
84 import org.apache.bcel.generic.RET;
85 import org.apache.bcel.generic.ReturnInstruction;
86 import org.apache.bcel.generic.TABLESWITCH;
87 import org.apache.bcel.generic.Type;
88 import org.apache.bcel.verifier.PassVerifier;
89 import org.apache.bcel.verifier.VerificationResult;
90 import org.apache.bcel.verifier.Verifier;
91 import org.apache.bcel.verifier.VerifierFactory;
92 import org.apache.bcel.verifier.exc.AssertionViolatedException;
93 import org.apache.bcel.verifier.exc.ClassConstraintException;
94 import org.apache.bcel.verifier.exc.InvalidMethodException;
95 import org.apache.bcel.verifier.exc.StaticCodeConstraintException;
96 import org.apache.bcel.verifier.exc.StaticCodeInstructionConstraintException;
97 import org.apache.bcel.verifier.exc.StaticCodeInstructionOperandConstraintException;
98
99 /**
100 * This PassVerifier verifies a class file according to
101 * pass 3, static part as described in The Java Virtual
102 * Machine Specification, 2nd edition.
103 * More detailed information is to be found at the do_verify()
104 * method's documentation.
105 *
106 * @version $Id: Pass3aVerifier.java 386056 2006-03-15 11:31:56Z tcurdt $
107 * @author Enver Haase
108 * @see #do_verify()
109 */
110 public final class Pass3aVerifier extends PassVerifier{
111
112 /** The Verifier that created this. */
113 private Verifier myOwner;
114
115 /**
116 * The method number to verify.
117 * This is the index in the array returned
118 * by JavaClass.getMethods().
119 */
120 private int method_no;
121
122 /** The one and only InstructionList object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */
123 InstructionList instructionList;
124 /** The one and only Code object used by an instance of this class. It's here for performance reasons by do_verify() and its callees. */
125 Code code;
126
127 /** Should only be instantiated by a Verifier. */
128 public Pass3aVerifier(Verifier owner, int method_no){
129 myOwner = owner;
130 this.method_no = method_no;
131 }
132
133 /**
134 * Pass 3a is the verification of static constraints of
135 * JVM code (such as legal targets of branch instructions).
136 * This is the part of pass 3 where you do not need data
137 * flow analysis.
138 * JustIce also delays the checks for a correct exception
139 * table of a Code attribute and correct line number entries
140 * in a LineNumberTable attribute of a Code attribute (which
141 * conceptually belong to pass 2) to this pass. Also, most
142 * of the check for valid local variable entries in a
143 * LocalVariableTable attribute of a Code attribute is
144 * delayed until this pass.
145 * All these checks need access to the code array of the
146 * Code attribute.
147 *
148 * @throws InvalidMethodException if the method to verify does not exist.
149 */
150 public VerificationResult do_verify(){
151 try {
152 if (myOwner.doPass2().equals(VerificationResult.VR_OK)){
153 // Okay, class file was loaded correctly by Pass 1
154 // and satisfies static constraints of Pass 2.
155 JavaClass jc = Repository.lookupClass(myOwner.getClassName());
156 Method[] methods = jc.getMethods();
157 if (method_no >= methods.length){
158 throw new InvalidMethodException("METHOD DOES NOT EXIST!");
159 }
160 Method method = methods[method_no];
161 code = method.getCode();
162
163 // No Code? Nothing to verify!
164 if ( method.isAbstract() || method.isNative() ){ // IF mg HAS NO CODE (static constraint of Pass 2)
165 return VerificationResult.VR_OK;
166 }
167
168 // TODO:
169 // We want a very sophisticated code examination here with good explanations
170 // on where to look for an illegal instruction or such.
171 // Only after that we should try to build an InstructionList and throw an
172 // AssertionViolatedException if after our examination InstructionList building
173 // still fails.
174 // That examination should be implemented in a byte-oriented way, i.e. look for
175 // an instruction, make sure its validity, count its length, find the next
176 // instruction and so on.
177 try{
178 instructionList = new InstructionList(method.getCode().getCode());
179 }
180 catch(RuntimeException re){
181 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Bad bytecode in the code array of the Code attribute of method '"+method+"'.");
182 }
183
184 instructionList.setPositions(true);
185
186 // Start verification.
187 VerificationResult vr = VerificationResult.VR_OK; //default
188 try{
189 delayedPass2Checks();
190 }
191 catch(ClassConstraintException cce){
192 vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
193 return vr;
194 }
195 try{
196 pass3StaticInstructionChecks();
197 pass3StaticInstructionOperandsChecks();
198 }
199 catch(StaticCodeConstraintException scce){
200 vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, scce.getMessage());
201 }
202 catch(ClassCastException cce){
203 vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Class Cast Exception: " + cce.getMessage());
204 }
205 return vr;
206 }
207 else{ //did not pass Pass 2.
208 return VerificationResult.VR_NOTYET;
209 }
210 } catch (ClassNotFoundException e) {
211 // FIXME: maybe not the best way to handle this
212 throw new AssertionViolatedException("Missing class: " + e.toString());
213 }
214 }
215
216 /**
217 * These are the checks that could be done in pass 2 but are delayed to pass 3
218 * for performance reasons. Also, these checks need access to the code array
219 * of the Code attribute of a Method so it's okay to perform them here.
220 * Also see the description of the do_verify() method.
221 *
222 * @throws ClassConstraintException if the verification fails.
223 * @see #do_verify()
224 */
225 private void delayedPass2Checks(){
226
227 int[] instructionPositions = instructionList.getInstructionPositions();
228 int codeLength = code.getCode().length;
229
230 /////////////////////
231 // LineNumberTable //
232 /////////////////////
233 LineNumberTable lnt = code.getLineNumberTable();
234 if (lnt != null){
235 LineNumber[] lineNumbers = lnt.getLineNumberTable();
236 IntList offsets = new IntList();
237 lineNumber_loop: for (int i=0; i < lineNumbers.length; i++){ // may appear in any order.
238 for (int j=0; j < instructionPositions.length; j++){
239 // TODO: Make this a binary search! The instructionPositions array is naturally ordered!
240 int offset = lineNumbers[i].getStartPC();
241 if (instructionPositions[j] == offset){
242 if (offsets.contains(offset)){
243 addMessage("LineNumberTable attribute '"+code.getLineNumberTable()+"' refers to the same code offset ('"+offset+"') more than once which is violating the semantics [but is sometimes produced by IBM's 'jikes' compiler].");
244 }
245 else{
246 offsets.add(offset);
247 }
248 continue lineNumber_loop;
249 }
250 }
251 throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist.");
252 }
253 }
254
255 ///////////////////////////
256 // LocalVariableTable(s) //
257 ///////////////////////////
258 /* We cannot use code.getLocalVariableTable() because there could be more
259 than only one. This is a bug in BCEL. */
260 Attribute[] atts = code.getAttributes();
261 for (int a=0; a<atts.length; a++){
262 if (atts[a] instanceof LocalVariableTable){
263 LocalVariableTable lvt = (LocalVariableTable) atts[a];
264 if (lvt != null){
265 LocalVariable[] localVariables = lvt.getLocalVariableTable();
266 for (int i=0; i<localVariables.length; i++){
267 int startpc = localVariables[i].getStartPC();
268 int length = localVariables[i].getLength();
269
270 if (!contains(instructionPositions, startpc)){
271 throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset ('"+startpc+"') that does not exist.");
272 }
273 if ( (!contains(instructionPositions, startpc+length)) && (startpc+length != codeLength) ){
274 throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset start_pc+length ('"+(startpc+length)+"') that does not exist.");
275 }
276 }
277 }
278 }
279 }
280
281 ////////////////////
282 // ExceptionTable //
283 ////////////////////
284 // In BCEL's "classfile" API, the startPC/endPC-notation is
285 // inclusive/exclusive as in the Java Virtual Machine Specification.
286 // WARNING: This is not true for BCEL's "generic" API.
287 CodeException[] exceptionTable = code.getExceptionTable();
288 for (int i=0; i<exceptionTable.length; i++){
289 int startpc = exceptionTable[i].getStartPC();
290 int endpc = exceptionTable[i].getEndPC();
291 int handlerpc = exceptionTable[i].getHandlerPC();
292 if (startpc >= endpc){
293 throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has its start_pc ('"+startpc+"') not smaller than its end_pc ('"+endpc+"').");
294 }
295 if (!contains(instructionPositions, startpc)){
296 throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its start_pc ('"+startpc+"').");
297 }
298 if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)){
299 throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its end_pc ('"+startpc+"') [that is also not equal to code_length ('"+codeLength+"')].");
300 }
301 if (!contains(instructionPositions, handlerpc)){
302 throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its handler_pc ('"+handlerpc+"').");
303 }
304 }
305 }
306
307 /**
308 * These are the checks if constraints are satisfied which are described in the
309 * Java Virtual Machine Specification, Second Edition as Static Constraints on
310 * the instructions of Java Virtual Machine Code (chapter 4.8.1).
311 *
312 * @throws StaticCodeConstraintException if the verification fails.
313 */
314 private void pass3StaticInstructionChecks(){
315
316 // Code array must not be empty:
317 // Enforced in pass 2 (also stated in the static constraints of the Code
318 // array in vmspec2), together with pass 1 (reading code_length bytes and
319 // interpreting them as code[]). So this must not be checked again here.
320
321 if (! (code.getCode().length < 65536)){// contradicts vmspec2 page 152 ("Limitations"), but is on page 134.
322 throw new StaticCodeInstructionConstraintException("Code array in code attribute '"+code+"' too big: must be smaller than 65536 bytes.");
323 }
324
325 // First opcode at offset 0: okay, that's clear. Nothing to do.
326
327 // Only instances of the instructions documented in Section 6.4 may appear in
328 // the code array.
329
330 // For BCEL's sake, we cannot handle WIDE stuff, but hopefully BCEL does its job right :)
331
332 // The last byte of the last instruction in the code array must be the byte at index
333 // code_length-1 : See the do_verify() comments. We actually don't iterate through the
334 // byte array, but use an InstructionList so we cannot check for this. But BCEL does
335 // things right, so it's implicitly okay.
336
337 // TODO: Check how BCEL handles (and will handle) instructions like IMPDEP1, IMPDEP2,
338 // BREAKPOINT... that BCEL knows about but which are illegal anyway.
339 // We currently go the safe way here.
340 InstructionHandle ih = instructionList.getStart();
341 while (ih != null){
342 Instruction i = ih.getInstruction();
343 if (i instanceof IMPDEP1){
344 throw new StaticCodeInstructionConstraintException("IMPDEP1 must not be in the code, it is an illegal instruction for _internal_ JVM use!");
345 }
346 if (i instanceof IMPDEP2){
347 throw new StaticCodeInstructionConstraintException("IMPDEP2 must not be in the code, it is an illegal instruction for _internal_ JVM use!");
348 }
349 if (i instanceof BREAKPOINT){
350 throw new StaticCodeInstructionConstraintException("BREAKPOINT must not be in the code, it is an illegal instruction for _internal_ JVM use!");
351 }
352 ih = ih.getNext();
353 }
354
355 // The original verifier seems to do this check here, too.
356 // An unreachable last instruction may also not fall through the
357 // end of the code, which is stupid -- but with the original
358 // verifier's subroutine semantics one cannot predict reachability.
359 Instruction last = instructionList.getEnd().getInstruction();
360 if (! ((last instanceof ReturnInstruction) ||
361 (last instanceof RET) ||
362 (last instanceof GotoInstruction) ||
363 (last instanceof ATHROW) )) {
364 throw new StaticCodeInstructionConstraintException("Execution must not fall off the bottom of the code array. This constraint is enforced statically as some existing verifiers do - so it may be a false alarm if the last instruction is not reachable.");
365 }
366 }
367
368 /**
369 * These are the checks for the satisfaction of constraints which are described in the
370 * Java Virtual Machine Specification, Second Edition as Static Constraints on
371 * the operands of instructions of Java Virtual Machine Code (chapter 4.8.1).
372 * BCEL parses the code array to create an InstructionList and therefore has to check
373 * some of these constraints. Additional checks are also implemented here.
374 *
375 * @throws StaticCodeConstraintException if the verification fails.
376 */
377 private void pass3StaticInstructionOperandsChecks(){
378 try {
379 // When building up the InstructionList, BCEL has already done all those checks
380 // mentioned in The Java Virtual Machine Specification, Second Edition, as
381 // "static constraints on the operands of instructions in the code array".
382 // TODO: see the do_verify() comments. Maybe we should really work on the
383 // byte array first to give more comprehensive messages.
384 // TODO: Review Exception API, possibly build in some "offending instruction" thing
385 // when we're ready to insulate the offending instruction by doing the
386 // above thing.
387
388 // TODO: Implement as much as possible here. BCEL does _not_ check everything.
389
390 ConstantPoolGen cpg = new ConstantPoolGen(Repository.lookupClass(myOwner.getClassName()).getConstantPool());
391 InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg);
392
393 // Checks for the things BCEL does _not_ handle itself.
394 InstructionHandle ih = instructionList.getStart();
395 while (ih != null){
396 Instruction i = ih.getInstruction();
397
398 // An "own" constraint, due to JustIce's new definition of what "subroutine" means.
399 if (i instanceof JsrInstruction){
400 InstructionHandle target = ((JsrInstruction) i).getTarget();
401 if (target == instructionList.getStart()){
402 throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may have a top-level instruction (such as the very first instruction, which is targeted by instruction '"+ih+"' as its target.");
403 }
404 if (!(target.getInstruction() instanceof ASTORE)){
405 throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may target anything else than an ASTORE instruction. Instruction '"+ih+"' targets '"+target+"'.");
406 }
407 }
408
409 // vmspec2, page 134-137
410 ih.accept(v);
411
412 ih = ih.getNext();
413 }
414
415 } catch (ClassNotFoundException e) {
416 // FIXME: maybe not the best way to handle this
417 throw new AssertionViolatedException("Missing class: " + e.toString());
418 }
419 }
420
421 /** A small utility method returning if a given int i is in the given int[] ints. */
422 private static boolean contains(int[] ints, int i){
423 for (int j=0; j<ints.length; j++){
424 if (ints[j]==i) {
425 return true;
426 }
427 }
428 return false;
429 }
430
431 /** Returns the method number as supplied when instantiating. */
432 public int getMethodNo(){
433 return method_no;
434 }
435
436 /**
437 * This visitor class does the actual checking for the instruction
438 * operand's constraints.
439 */
440 private class InstOperandConstraintVisitor extends org.apache.bcel.generic.EmptyVisitor{
441 /** The ConstantPoolGen instance this Visitor operates on. */
442 private ConstantPoolGen cpg;
443
444 /** The only Constructor. */
445 InstOperandConstraintVisitor(ConstantPoolGen cpg){
446 this.cpg = cpg;
447 }
448
449 /**
450 * Utility method to return the max_locals value of the method verified
451 * by the surrounding Pass3aVerifier instance.
452 */
453 private int max_locals(){
454 try {
455 return Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getCode().getMaxLocals();
456 } catch (ClassNotFoundException e) {
457 // FIXME: maybe not the best way to handle this
458 throw new AssertionViolatedException("Missing class: " + e.toString());
459 }
460 }
461
462 /**
463 * A utility method to always raise an exeption.
464 */
465 private void constraintViolated(Instruction i, String message) {
466 throw new StaticCodeInstructionOperandConstraintException("Instruction "+i+" constraint violated: "+message);
467 }
468
469 /**
470 * A utility method to raise an exception if the index is not
471 * a valid constant pool index.
472 */
473 private void indexValid(Instruction i, int idx){
474 if (idx < 0 || idx >= cpg.getSize()){
475 constraintViolated(i, "Illegal constant pool index '"+idx+"'.");
476 }
477 }
478
479 ///////////////////////////////////////////////////////////
480 // The Java Virtual Machine Specification, pages 134-137 //
481 ///////////////////////////////////////////////////////////
482 /**
483 * Assures the generic preconditions of a LoadClass instance.
484 * The referenced class is loaded and pass2-verified.
485 */
486 public void visitLoadClass(LoadClass o){
487 ObjectType t = o.getLoadClassType(cpg);
488 if (t != null){// null means "no class is loaded"
489 Verifier v = VerifierFactory.getVerifier(t.getClassName());
490 VerificationResult vr = v.doPass1();
491 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
492 constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'.");
493 }
494 }
495 }
496
497 // The target of each jump and branch instruction [...] must be the opcode [...]
498 // BCEL _DOES_ handle this.
499
500 // tableswitch: BCEL will do it, supposedly.
501
502 // lookupswitch: BCEL will do it, supposedly.
503
504 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
505 // LDC and LDC_W (LDC_W is a subclass of LDC in BCEL's model)
506 public void visitLDC(LDC o){
507 indexValid(o, o.getIndex());
508 Constant c = cpg.getConstant(o.getIndex());
509 if (c instanceof ConstantClass){
510 addMessage("Operand of LDC or LDC_W is CONSTANT_Class '"+c+"' - this is only supported in JDK 1.5 and higher.");
511 }
512 else{
513 if (! ( (c instanceof ConstantInteger) ||
514 (c instanceof ConstantFloat) ||
515 (c instanceof ConstantString) ) ){
516 constraintViolated(o, "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '"+c+"'.");
517 }
518 }
519 }
520
521 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
522 // LDC2_W
523 public void visitLDC2_W(LDC2_W o){
524 indexValid(o, o.getIndex());
525 Constant c = cpg.getConstant(o.getIndex());
526 if (! ( (c instanceof ConstantLong) ||
527 (c instanceof ConstantDouble) ) ){
528 constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'.");
529 }
530 try{
531 indexValid(o, o.getIndex()+1);
532 }
533 catch(StaticCodeInstructionOperandConstraintException e){
534 throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem.");
535 }
536 }
537
538 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
539 //getfield, putfield, getstatic, putstatic
540 public void visitFieldInstruction(FieldInstruction o){
541 try {
542 indexValid(o, o.getIndex());
543 Constant c = cpg.getConstant(o.getIndex());
544 if (! (c instanceof ConstantFieldref)){
545 constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'.");
546 }
547
548 String field_name = o.getFieldName(cpg);
549
550 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
551 Field[] fields = jc.getFields();
552 Field f = null;
553 for (int i=0; i<fields.length; i++){
554 if (fields[i].getName().equals(field_name)){
555 Type f_type = Type.getType(fields[i].getSignature());
556 Type o_type = o.getType(cpg);
557 /* TODO: Check if assignment compatibility is sufficient.
558 * What does Sun do?
559 */
560 if (f_type.equals(o_type)){
561 f = fields[i];
562 break;
563 }
564 }
565 }
566 if (f == null){
567 JavaClass[] superclasses = jc.getSuperClasses();
568 outer:
569 for (int j=0; j<superclasses.length; j++){
570 fields = superclasses[j].getFields();
571 for (int i=0; i<fields.length; i++){
572 if (fields[i].getName().equals(field_name)){
573 Type f_type = Type.getType(fields[i].getSignature());
574 Type o_type = o.getType(cpg);
575 if (f_type.equals(o_type)){
576 f = fields[i];
577 if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0) {
578 f = null;
579 }
580 break outer;
581 }
582 }
583 }
584 }
585 if (f == null) {
586 constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
587 }
588 }
589 else{
590 /* TODO: Check if assignment compatibility is sufficient.
591 What does Sun do? */
592 Type f_type = Type.getType(f.getSignature());
593 Type o_type = o.getType(cpg);
594
595 // Argh. Sun's implementation allows us to have multiple fields of
596 // the same name but with a different signature.
597 //if (! f_type.equals(o_type)){
598 // constraintViolated(o, "Referenced field '"+field_name+"' has type '"+f_type+"' instead of '"+o_type+"' as expected.");
599 //}
600
601 /* TODO: Check for access modifiers here. */
602 }
603 } catch (ClassNotFoundException e) {
604 // FIXME: maybe not the best way to handle this
605 throw new AssertionViolatedException("Missing class: " + e.toString());
606 }
607 }
608
609 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
610 public void visitInvokeInstruction(InvokeInstruction o){
611 indexValid(o, o.getIndex());
612 if ( (o instanceof INVOKEVIRTUAL) ||
613 (o instanceof INVOKESPECIAL) ||
614 (o instanceof INVOKESTATIC) ){
615 Constant c = cpg.getConstant(o.getIndex());
616 if (! (c instanceof ConstantMethodref)){
617 constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'.");
618 }
619 else{
620 // Constants are okay due to pass2.
621 ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex()));
622 ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()));
623 if (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){
624 constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods.");
625 }
626 if ( (! (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){
627 constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods may be called by the method invocation instructions.");
628 }
629 }
630 }
631 else{ //if (o instanceof INVOKEINTERFACE){
632 Constant c = cpg.getConstant(o.getIndex());
633 if (! (c instanceof ConstantInterfaceMethodref)){
634 constraintViolated(o, "Indexing a constant that's not a CONSTANT_InterfaceMethodref but a '"+c+"'.");
635 }
636 // TODO: From time to time check if BCEL allows to detect if the
637 // 'count' operand is consistent with the information in the
638 // CONSTANT_InterfaceMethodref and if the last operand is zero.
639 // By now, BCEL hides those two operands because they're superfluous.
640
641 // Invoked method must not be <init> or <clinit>
642 ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex()));
643 String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes();
644 if (name.equals(Constants.CONSTRUCTOR_NAME)){
645 constraintViolated(o, "Method to invoke must not be '"+Constants.CONSTRUCTOR_NAME+"'.");
646 }
647 if (name.equals(Constants.STATIC_INITIALIZER_NAME)){
648 constraintViolated(o, "Method to invoke must not be '"+Constants.STATIC_INITIALIZER_NAME+"'.");
649 }
650 }
651
652 // The LoadClassType is the method-declaring class, so we have to check the other types.
653
654 Type t = o.getReturnType(cpg);
655 if (t instanceof ArrayType){
656 t = ((ArrayType) t).getBasicType();
657 }
658 if (t instanceof ObjectType){
659 Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName());
660 VerificationResult vr = v.doPass2();
661 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
662 constraintViolated(o, "Return type class/interface could not be verified successfully: '"+vr.getMessage()+"'.");
663 }
664 }
665
666 Type[] ts = o.getArgumentTypes(cpg);
667 for (int i=0; i<ts.length; i++){
668 t = ts[i];
669 if (t instanceof ArrayType){
670 t = ((ArrayType) t).getBasicType();
671 }
672 if (t instanceof ObjectType){
673 Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName());
674 VerificationResult vr = v.doPass2();
675 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
676 constraintViolated(o, "Argument type class/interface could not be verified successfully: '"+vr.getMessage()+"'.");
677 }
678 }
679 }
680
681 }
682
683 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
684 public void visitINSTANCEOF(INSTANCEOF o){
685 indexValid(o, o.getIndex());
686 Constant c = cpg.getConstant(o.getIndex());
687 if (! (c instanceof ConstantClass)){
688 constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
689 }
690 }
691
692 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
693 public void visitCHECKCAST(CHECKCAST o){
694 indexValid(o, o.getIndex());
695 Constant c = cpg.getConstant(o.getIndex());
696 if (! (c instanceof ConstantClass)){
697 constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
698 }
699 }
700
701 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
702 public void visitNEW(NEW o){
703 indexValid(o, o.getIndex());
704 Constant c = cpg.getConstant(o.getIndex());
705 if (! (c instanceof ConstantClass)){
706 constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
707 }
708 else{
709 ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() ));
710 Type t = Type.getType("L"+cutf8.getBytes()+";");
711 if (t instanceof ArrayType){
712 constraintViolated(o, "NEW must not be used to create an array.");
713 }
714 }
715
716 }
717
718 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
719 public void visitMULTIANEWARRAY(MULTIANEWARRAY o){
720 indexValid(o, o.getIndex());
721 Constant c = cpg.getConstant(o.getIndex());
722 if (! (c instanceof ConstantClass)){
723 constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
724 }
725 int dimensions2create = o.getDimensions();
726 if (dimensions2create < 1){
727 constraintViolated(o, "Number of dimensions to create must be greater than zero.");
728 }
729 Type t = o.getType(cpg);
730 if (t instanceof ArrayType){
731 int dimensions = ((ArrayType) t).getDimensions();
732 if (dimensions < dimensions2create){
733 constraintViolated(o, "Not allowed to create array with more dimensions ('+dimensions2create+') than the one referenced by the CONSTANT_Class '"+t+"'.");
734 }
735 }
736 else{
737 constraintViolated(o, "Expecting a CONSTANT_Class referencing an array type. [Constraint not found in The Java Virtual Machine Specification, Second Edition, 4.8.1]");
738 }
739 }
740
741 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
742 public void visitANEWARRAY(ANEWARRAY o){
743 indexValid(o, o.getIndex());
744 Constant c = cpg.getConstant(o.getIndex());
745 if (! (c instanceof ConstantClass)){
746 constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
747 }
748 Type t = o.getType(cpg);
749 if (t instanceof ArrayType){
750 int dimensions = ((ArrayType) t).getDimensions();
751 if (dimensions >= 255){
752 constraintViolated(o, "Not allowed to create an array with more than 255 dimensions.");
753 }
754 }
755 }
756
757 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
758 public void visitNEWARRAY(NEWARRAY o){
759 byte t = o.getTypecode();
760 if (! ( (t == Constants.T_BOOLEAN) ||
761 (t == Constants.T_CHAR) ||
762 (t == Constants.T_FLOAT) ||
763 (t == Constants.T_DOUBLE) ||
764 (t == Constants.T_BYTE) ||
765 (t == Constants.T_SHORT) ||
766 (t == Constants.T_INT) ||
767 (t == Constants.T_LONG) ) ){
768 constraintViolated(o, "Illegal type code '+t+' for 'atype' operand.");
769 }
770 }
771
772 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
773 public void visitILOAD(ILOAD o){
774 int idx = o.getIndex();
775 if (idx < 0){
776 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
777 }
778 else{
779 int maxminus1 = max_locals()-1;
780 if (idx > maxminus1){
781 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
782 }
783 }
784 }
785
786 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
787 public void visitFLOAD(FLOAD o){
788 int idx = o.getIndex();
789 if (idx < 0){
790 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
791 }
792 else{
793 int maxminus1 = max_locals()-1;
794 if (idx > maxminus1){
795 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
796 }
797 }
798 }
799
800 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
801 public void visitALOAD(ALOAD o){
802 int idx = o.getIndex();
803 if (idx < 0){
804 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
805 }
806 else{
807 int maxminus1 = max_locals()-1;
808 if (idx > maxminus1){
809 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
810 }
811 }
812 }
813
814 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
815 public void visitISTORE(ISTORE o){
816 int idx = o.getIndex();
817 if (idx < 0){
818 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
819 }
820 else{
821 int maxminus1 = max_locals()-1;
822 if (idx > maxminus1){
823 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
824 }
825 }
826 }
827
828 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
829 public void visitFSTORE(FSTORE o){
830 int idx = o.getIndex();
831 if (idx < 0){
832 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
833 }
834 else{
835 int maxminus1 = max_locals()-1;
836 if (idx > maxminus1){
837 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
838 }
839 }
840 }
841
842 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
843 public void visitASTORE(ASTORE o){
844 int idx = o.getIndex();
845 if (idx < 0){
846 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
847 }
848 else{
849 int maxminus1 = max_locals()-1;
850 if (idx > maxminus1){
851 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
852 }
853 }
854 }
855
856 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
857 public void visitIINC(IINC o){
858 int idx = o.getIndex();
859 if (idx < 0){
860 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
861 }
862 else{
863 int maxminus1 = max_locals()-1;
864 if (idx > maxminus1){
865 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
866 }
867 }
868 }
869
870 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
871 public void visitRET(RET o){
872 int idx = o.getIndex();
873 if (idx < 0){
874 constraintViolated(o, "Index '"+idx+"' must be non-negative.");
875 }
876 else{
877 int maxminus1 = max_locals()-1;
878 if (idx > maxminus1){
879 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'.");
880 }
881 }
882 }
883
884 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
885 public void visitLLOAD(LLOAD o){
886 int idx = o.getIndex();
887 if (idx < 0){
888 constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]");
889 }
890 else{
891 int maxminus2 = max_locals()-2;
892 if (idx > maxminus2){
893 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'.");
894 }
895 }
896 }
897
898 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
899 public void visitDLOAD(DLOAD o){
900 int idx = o.getIndex();
901 if (idx < 0){
902 constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]");
903 }
904 else{
905 int maxminus2 = max_locals()-2;
906 if (idx > maxminus2){
907 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'.");
908 }
909 }
910 }
911
912 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
913 public void visitLSTORE(LSTORE o){
914 int idx = o.getIndex();
915 if (idx < 0){
916 constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]");
917 }
918 else{
919 int maxminus2 = max_locals()-2;
920 if (idx > maxminus2){
921 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'.");
922 }
923 }
924 }
925
926 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
927 public void visitDSTORE(DSTORE o){
928 int idx = o.getIndex();
929 if (idx < 0){
930 constraintViolated(o, "Index '"+idx+"' must be non-negative. [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]");
931 }
932 else{
933 int maxminus2 = max_locals()-2;
934 if (idx > maxminus2){
935 constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'.");
936 }
937 }
938 }
939
940 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
941 public void visitLOOKUPSWITCH(LOOKUPSWITCH o){
942 int[] matchs = o.getMatchs();
943 int max = Integer.MIN_VALUE;
944 for (int i=0; i<matchs.length; i++){
945 if (matchs[i] == max && i != 0){
946 constraintViolated(o, "Match '"+matchs[i]+"' occurs more than once.");
947 }
948 if (matchs[i] < max){
949 constraintViolated(o, "Lookup table must be sorted but isn't.");
950 }
951 else{
952 max = matchs[i];
953 }
954 }
955 }
956
957 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
958 public void visitTABLESWITCH(TABLESWITCH o){
959 // "high" must be >= "low". We cannot check this, as BCEL hides
960 // it from us.
961 }
962
963 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
964 public void visitPUTSTATIC(PUTSTATIC o){
965 try {
966 String field_name = o.getFieldName(cpg);
967 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
968 Field[] fields = jc.getFields();
969 Field f = null;
970 for (int i=0; i<fields.length; i++){
971 if (fields[i].getName().equals(field_name)){
972 f = fields[i];
973 break;
974 }
975 }
976 if (f == null){
977 throw new AssertionViolatedException("Field not found?!?");
978 }
979
980 if (f.isFinal()){
981 if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){
982 constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'.");
983 }
984 }
985
986 if (! (f.isStatic())){
987 constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
988 }
989
990 String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();
991
992 // If it's an interface, it can be set only in <clinit>.
993 if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){
994 constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method.");
995 }
996 } catch (ClassNotFoundException e) {
997 // FIXME: maybe not the best way to handle this
998 throw new AssertionViolatedException("Missing class: " + e.toString());
999 }
1000 }
1001
1002 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
1003 public void visitGETSTATIC(GETSTATIC o){
1004 try {
1005 String field_name = o.getFieldName(cpg);
1006 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
1007 Field[] fields = jc.getFields();
1008 Field f = null;
1009 for (int i=0; i<fields.length; i++){
1010 if (fields[i].getName().equals(field_name)){
1011 f = fields[i];
1012 break;
1013 }
1014 }
1015 if (f == null){
1016 throw new AssertionViolatedException("Field not found?!?");
1017 }
1018
1019 if (! (f.isStatic())){
1020 constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
1021 }
1022 } catch (ClassNotFoundException e) {
1023 // FIXME: maybe not the best way to handle this
1024 throw new AssertionViolatedException("Missing class: " + e.toString());
1025 }
1026 }
1027
1028 /* Checks if the constraints of operands of the said instruction(s) are satisfied. */
1029 //public void visitPUTFIELD(PUTFIELD o){
1030 // for performance reasons done in Pass 3b
1031 //}
1032
1033 /* Checks if the constraints of operands of the said instruction(s) are satisfied. */
1034 //public void visitGETFIELD(GETFIELD o){
1035 // for performance reasons done in Pass 3b
1036 //}
1037
1038 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
1039 public void visitINVOKEINTERFACE(INVOKEINTERFACE o){
1040 try {
1041 // INVOKEINTERFACE is a LoadClass; the Class where the referenced method is declared in,
1042 // is therefore resolved/verified.
1043 // INVOKEINTERFACE is an InvokeInstruction, the argument and return types are resolved/verified,
1044 // too. So are the allowed method names.
1045 String classname = o.getClassName(cpg);
1046 JavaClass jc = Repository.lookupClass(classname);
1047 Method[] ms = jc.getMethods();
1048 Method m = null;
1049 for (int i=0; i<ms.length; i++){
1050 if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
1051 (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
1052 (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
1053 m = ms[i];
1054 break;
1055 }
1056 }
1057 if (m == null){
1058 constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superinterface, which the Java Virtual Machine Specification, Second Edition does not.");
1059 }
1060 if (jc.isClass()){
1061 constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is a class, but not an interface as expected.");
1062 }
1063 } catch (ClassNotFoundException e) {
1064 // FIXME: maybe not the best way to handle this
1065 throw new AssertionViolatedException("Missing class: " + e.toString());
1066 }
1067 }
1068
1069 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
1070 public void visitINVOKESPECIAL(INVOKESPECIAL o){
1071 try {
1072 // INVOKESPECIAL is a LoadClass; the Class where the referenced method is declared in,
1073 // is therefore resolved/verified.
1074 // INVOKESPECIAL is an InvokeInstruction, the argument and return types are resolved/verified,
1075 // too. So are the allowed method names.
1076 String classname = o.getClassName(cpg);
1077 JavaClass jc = Repository.lookupClass(classname);
1078 Method[] ms = jc.getMethods();
1079 Method m = null;
1080 for (int i=0; i<ms.length; i++){
1081 if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
1082 (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
1083 (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
1084 m = ms[i];
1085 break;
1086 }
1087 }
1088 if (m == null){
1089 constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
1090 }
1091
1092 JavaClass current = Repository.lookupClass(myOwner.getClassName());
1093 if (current.isSuper()){
1094
1095 if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){
1096
1097 if (! (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME) )){
1098 // Special lookup procedure for ACC_SUPER classes.
1099
1100 int supidx = -1;
1101
1102 Method meth = null;
1103 while (supidx != 0){
1104 supidx = current.getSuperclassNameIndex();
1105 current = Repository.lookupClass(current.getSuperclassName());
1106
1107 Method[] meths = current.getMethods();
1108 for (int i=0; i<meths.length; i++){
1109 if ( (meths[i].getName().equals(o.getMethodName(cpg))) &&
1110 (Type.getReturnType(meths[i].getSignature()).equals(o.getReturnType(cpg))) &&
1111 (objarrayequals(Type.getArgumentTypes(meths[i].getSignature()), o.getArgumentTypes(cpg))) ){
1112 meth = meths[i];
1113 break;
1114 }
1115 }
1116 if (meth != null) {
1117 break;
1118 }
1119 }
1120 if (meth == null){
1121 constraintViolated(o, "ACC_SUPER special lookup procedure not successful: method '"+o.getMethodName(cpg)+"' with proper signature not declared in superclass hierarchy.");
1122 }
1123 }
1124 }
1125 }
1126
1127 } catch (ClassNotFoundException e) {
1128 // FIXME: maybe not the best way to handle this
1129 throw new AssertionViolatedException("Missing class: " + e.toString());
1130 }
1131
1132 }
1133
1134 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
1135 public void visitINVOKESTATIC(INVOKESTATIC o){
1136 try {
1137 // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in,
1138 // is therefore resolved/verified.
1139 // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified,
1140 // too. So are the allowed method names.
1141 String classname = o.getClassName(cpg);
1142 JavaClass jc = Repository.lookupClass(classname);
1143 Method[] ms = jc.getMethods();
1144 Method m = null;
1145 for (int i=0; i<ms.length; i++){
1146 if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
1147 (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
1148 (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
1149 m = ms[i];
1150 break;
1151 }
1152 }
1153 if (m == null){
1154 constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg) +"' not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
1155 } else if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2.
1156 constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset.");
1157 }
1158
1159 } catch (ClassNotFoundException e) {
1160 // FIXME: maybe not the best way to handle this
1161 throw new AssertionViolatedException("Missing class: " + e.toString());
1162 }
1163 }
1164
1165
1166 /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
1167 public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
1168 try {
1169 // INVOKEVIRTUAL is a LoadClass; the Class where the referenced method is declared in,
1170 // is therefore resolved/verified.
1171 // INVOKEVIRTUAL is an InvokeInstruction, the argument and return types are resolved/verified,
1172 // too. So are the allowed method names.
1173 String classname = o.getClassName(cpg);
1174 JavaClass jc = Repository.lookupClass(classname);
1175 Method[] ms = jc.getMethods();
1176 Method m = null;
1177 for (int i=0; i<ms.length; i++){
1178 if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
1179 (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
1180 (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
1181 m = ms[i];
1182 break;
1183 }
1184 }
1185 if (m == null){
1186 constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
1187 }
1188 if (! (jc.isClass())){
1189 constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is an interface, but not a class as expected.");
1190 }
1191
1192 } catch (ClassNotFoundException e) {
1193 // FIXME: maybe not the best way to handle this
1194 throw new AssertionViolatedException("Missing class: " + e.toString());
1195 }
1196 }
1197
1198
1199 // WIDE stuff is BCEL-internal and cannot be checked here.
1200
1201 /**
1202 * A utility method like equals(Object) for arrays.
1203 * The equality of the elements is based on their equals(Object)
1204 * method instead of their object identity.
1205 */
1206 private boolean objarrayequals(Object[] o, Object[] p){
1207 if (o.length != p.length){
1208 return false;
1209 }
1210
1211 for (int i=0; i<o.length; i++){
1212 if (! (o[i].equals(p[i])) ){
1213 return false;
1214 }
1215 }
1216
1217 return true;
1218 }
1219
1220 }
1221 }
+0
-249
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/StringRepresentation.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.statics;
17
18
19 import org.apache.bcel.classfile.Code;
20 import org.apache.bcel.classfile.CodeException;
21 import org.apache.bcel.classfile.ConstantClass;
22 import org.apache.bcel.classfile.ConstantDouble;
23 import org.apache.bcel.classfile.ConstantFieldref;
24 import org.apache.bcel.classfile.ConstantFloat;
25 import org.apache.bcel.classfile.ConstantInteger;
26 import org.apache.bcel.classfile.ConstantInterfaceMethodref;
27 import org.apache.bcel.classfile.ConstantLong;
28 import org.apache.bcel.classfile.ConstantMethodref;
29 import org.apache.bcel.classfile.ConstantNameAndType;
30 import org.apache.bcel.classfile.ConstantPool;
31 import org.apache.bcel.classfile.ConstantString;
32 import org.apache.bcel.classfile.ConstantUtf8;
33 import org.apache.bcel.classfile.ConstantValue;
34 import org.apache.bcel.classfile.Deprecated;
35 import org.apache.bcel.classfile.ExceptionTable;
36 import org.apache.bcel.classfile.Field;
37 import org.apache.bcel.classfile.InnerClass;
38 import org.apache.bcel.classfile.InnerClasses;
39 import org.apache.bcel.classfile.JavaClass;
40 import org.apache.bcel.classfile.LineNumber;
41 import org.apache.bcel.classfile.LineNumberTable;
42 import org.apache.bcel.classfile.LocalVariable;
43 import org.apache.bcel.classfile.LocalVariableTable;
44 import org.apache.bcel.classfile.Method;
45 import org.apache.bcel.classfile.Node;
46 import org.apache.bcel.classfile.Signature;
47 import org.apache.bcel.classfile.SourceFile;
48 import org.apache.bcel.classfile.StackMap;
49 import org.apache.bcel.classfile.Synthetic;
50 import org.apache.bcel.classfile.Unknown;
51 import org.apache.bcel.classfile.Visitor;
52 import org.apache.bcel.verifier.exc.AssertionViolatedException;
53
54 /**
55 * BCEL's Node classes (those from the classfile API that <B>accept()</B> Visitor
56 * instances) have <B>toString()</B> methods that were not designed to be robust,
57 * this gap is closed by this class.
58 * When performing class file verification, it may be useful to output which
59 * entity (e.g. a <B>Code</B> instance) is not satisfying the verifier's
60 * constraints, but in this case it could be possible for the <B>toString()</B>
61 * method to throw a RuntimeException.
62 * A (new StringRepresentation(Node n)).toString() never throws any exception.
63 * Note that this class also serves as a placeholder for more sophisticated message
64 * handling in future versions of JustIce.
65 *
66 * @version $Id: StringRepresentation.java 386056 2006-03-15 11:31:56Z tcurdt $
67 * @author Enver Haase
68 */
69 public class StringRepresentation extends org.apache.bcel.classfile.EmptyVisitor implements Visitor {
70 /** The string representation, created by a visitXXX() method, output by toString(). */
71 private String tostring;
72 /** The node we ask for its string representation. Not really needed; only for debug output. */
73 private Node n;
74
75 /**
76 * Creates a new StringRepresentation object which is the representation of n.
77 *
78 * @see #toString()
79 */
80 public StringRepresentation(Node n) {
81 this.n = n;
82 n.accept(this); // assign a string representation to field 'tostring' if we know n's class.
83 }
84
85 /**
86 * Returns the String representation.
87 */
88 public String toString() {
89 // The run-time check below is needed because we don't want to omit inheritance
90 // of "EmptyVisitor" and provide a thousand empty methods.
91 // However, in terms of performance this would be a better idea.
92 // If some new "Node" is defined in BCEL (such as some concrete "Attribute"), we
93 // want to know that this class has also to be adapted.
94 if (tostring == null) {
95 throw new AssertionViolatedException("Please adapt '" + getClass() + "' to deal with objects of class '" + n.getClass() + "'.");
96 }
97 return tostring;
98 }
99
100 /**
101 * Returns the String representation of the Node object obj;
102 * this is obj.toString() if it does not throw any RuntimeException,
103 * or else it is a string derived only from obj's class name.
104 */
105 private String toString(Node obj) {
106 String ret;
107 try {
108 ret = obj.toString();
109 }
110 catch (RuntimeException e) { // including ClassFormatException, trying to convert the "signature" of a ReturnaddressType LocalVariable (shouldn't occur, but people do crazy things)
111 String s = obj.getClass().getName();
112 s = s.substring(s.lastIndexOf(".") + 1);
113 ret = "<<" + s + ">>";
114 }
115 return ret;
116 }
117
118 ////////////////////////////////
119 // Visitor methods start here //
120 ////////////////////////////////
121 // We don't of course need to call some default implementation:
122 // e.g. we could also simply output "Code" instead of a possibly
123 // lengthy Code attribute's toString().
124 public void visitCode(Code obj) {
125 //tostring = toString(obj);
126 tostring = "<CODE>"; // We don't need real code outputs.
127 }
128
129 public void visitCodeException(CodeException obj) {
130 tostring = toString(obj);
131 }
132
133 public void visitConstantClass(ConstantClass obj) {
134 tostring = toString(obj);
135 }
136
137 public void visitConstantDouble(ConstantDouble obj) {
138 tostring = toString(obj);
139 }
140
141 public void visitConstantFieldref(ConstantFieldref obj) {
142 tostring = toString(obj);
143 }
144
145 public void visitConstantFloat(ConstantFloat obj) {
146 tostring = toString(obj);
147 }
148
149 public void visitConstantInteger(ConstantInteger obj) {
150 tostring = toString(obj);
151 }
152
153 public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {
154 tostring = toString(obj);
155 }
156
157 public void visitConstantLong(ConstantLong obj) {
158 tostring = toString(obj);
159 }
160
161 public void visitConstantMethodref(ConstantMethodref obj) {
162 tostring = toString(obj);
163 }
164
165 public void visitConstantNameAndType(ConstantNameAndType obj) {
166 tostring = toString(obj);
167 }
168
169 public void visitConstantPool(ConstantPool obj) {
170 tostring = toString(obj);
171 }
172
173 public void visitConstantString(ConstantString obj) {
174 tostring = toString(obj);
175 }
176
177 public void visitConstantUtf8(ConstantUtf8 obj) {
178 tostring = toString(obj);
179 }
180
181 public void visitConstantValue(ConstantValue obj) {
182 tostring = toString(obj);
183 }
184
185 public void visitDeprecated(Deprecated obj) {
186 tostring = toString(obj);
187 }
188
189 public void visitExceptionTable(ExceptionTable obj) {
190 tostring = toString(obj);
191 }
192
193 public void visitField(Field obj) {
194 tostring = toString(obj);
195 }
196
197 public void visitInnerClass(InnerClass obj) {
198 tostring = toString(obj);
199 }
200
201 public void visitInnerClasses(InnerClasses obj) {
202 tostring = toString(obj);
203 }
204
205 public void visitJavaClass(JavaClass obj) {
206 tostring = toString(obj);
207 }
208
209 public void visitLineNumber(LineNumber obj) {
210 tostring = toString(obj);
211 }
212
213 public void visitLineNumberTable(LineNumberTable obj) {
214 tostring = "<LineNumberTable: " + toString(obj) + ">";
215 }
216
217 public void visitLocalVariable(LocalVariable obj) {
218 tostring = toString(obj);
219 }
220
221 public void visitLocalVariableTable(LocalVariableTable obj) {
222 tostring = "<LocalVariableTable: " + toString(obj) + ">";
223 }
224
225 public void visitMethod(Method obj) {
226 tostring = toString(obj);
227 }
228
229 public void visitSignature(Signature obj) {
230 tostring = toString(obj);
231 }
232
233 public void visitSourceFile(SourceFile obj) {
234 tostring = toString(obj);
235 }
236
237 public void visitStackMap(StackMap obj) {
238 tostring = toString(obj);
239 }
240
241 public void visitSynthetic(Synthetic obj) {
242 tostring = toString(obj);
243 }
244
245 public void visitUnknown(Unknown obj) {
246 tostring = toString(obj);
247 }
248 }
+0
-19
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/statics/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 371539 2006-01-23 14:08:00Z tcurdt $
5 -->
6 </head>
7 <body bgcolor="white">
8
9 Provides PassVerifier classes used internally by JustIce. You don't need to bother with them.
10
11 <h2>Package Specification</h2>
12
13 Contained in this package are PassVerifier classes for use with the JustIce verifier.
14 Only the passes performing what Sun calls 'static constraints' have PassVerifier classes
15 here.
16
17 </body>
18 </html>
+0
-460
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import java.util.ArrayList;
20 import java.util.Hashtable;
21 import java.util.Map;
22 import org.apache.bcel.generic.ATHROW;
23 import org.apache.bcel.generic.BranchInstruction;
24 import org.apache.bcel.generic.GotoInstruction;
25 import org.apache.bcel.generic.Instruction;
26 import org.apache.bcel.generic.InstructionHandle;
27 import org.apache.bcel.generic.JsrInstruction;
28 import org.apache.bcel.generic.MethodGen;
29 import org.apache.bcel.generic.RET;
30 import org.apache.bcel.generic.ReturnInstruction;
31 import org.apache.bcel.generic.Select;
32 import org.apache.bcel.verifier.exc.AssertionViolatedException;
33 import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
34
35 /**
36 * This class represents a control flow graph of a method.
37 *
38 * @version $Id: ControlFlowGraph.java 386056 2006-03-15 11:31:56Z tcurdt $
39 * @author Enver Haase
40 */
41 public class ControlFlowGraph{
42
43 /**
44 * Objects of this class represent a node in a ControlFlowGraph.
45 * These nodes are instructions, not basic blocks.
46 */
47 private class InstructionContextImpl implements InstructionContext{
48
49 /**
50 * The TAG field is here for external temporary flagging, such
51 * as graph colouring.
52 *
53 * @see #getTag()
54 * @see #setTag(int)
55 */
56 private int TAG;
57
58 /**
59 * The InstructionHandle this InstructionContext is wrapped around.
60 */
61 private InstructionHandle instruction;
62
63 /**
64 * The 'incoming' execution Frames.
65 */
66 private Map inFrames; // key: the last-executed JSR
67
68 /**
69 * The 'outgoing' execution Frames.
70 */
71 private Map outFrames; // key: the last-executed JSR
72
73 /**
74 * The 'execution predecessors' - a list of type InstructionContext
75 * of those instances that have been execute()d before in that order.
76 */
77 private ArrayList executionPredecessors = null; // Type: InstructionContext
78
79 /**
80 * Creates an InstructionHandleImpl object from an InstructionHandle.
81 * Creation of one per InstructionHandle suffices. Don't create more.
82 */
83 public InstructionContextImpl(InstructionHandle inst){
84 if (inst == null) {
85 throw new AssertionViolatedException("Cannot instantiate InstructionContextImpl from NULL.");
86 }
87
88 instruction = inst;
89 inFrames = new java.util.HashMap();
90 outFrames = new java.util.HashMap();
91 }
92
93 /* Satisfies InstructionContext.getTag(). */
94 public int getTag(){
95 return TAG;
96 }
97
98 /* Satisfies InstructionContext.setTag(int). */
99 public void setTag(int tag){
100 TAG = tag;
101 }
102
103 /**
104 * Returns the exception handlers of this instruction.
105 */
106 public ExceptionHandler[] getExceptionHandlers(){
107 return exceptionhandlers.getExceptionHandlers(getInstruction());
108 }
109
110 /**
111 * Returns a clone of the "outgoing" frame situation with respect to the given ExecutionChain.
112 */
113 public Frame getOutFrame(ArrayList execChain){
114 executionPredecessors = execChain;
115
116 Frame org;
117
118 InstructionContext jsr = lastExecutionJSR();
119
120 org = (Frame) outFrames.get(jsr);
121
122 if (org == null){
123 throw new AssertionViolatedException("outFrame not set! This:\n"+this+"\nExecutionChain: "+getExecutionChain()+"\nOutFrames: '"+outFrames+"'.");
124 }
125 return org.getClone();
126 }
127
128 public Frame getInFrame() {
129 Frame org;
130
131 InstructionContext jsr = lastExecutionJSR();
132
133 org = (Frame) inFrames.get(jsr);
134
135 if (org == null){
136 throw new AssertionViolatedException("inFrame not set! This:\n"+this+"\nInFrames: '"+inFrames+"'.");
137 }
138 return org.getClone();
139 }
140
141 /**
142 * "Merges in" (vmspec2, page 146) the "incoming" frame situation;
143 * executes the instructions symbolically
144 * and therefore calculates the "outgoing" frame situation.
145 * Returns: True iff the "incoming" frame situation changed after
146 * merging with "inFrame".
147 * The execPreds ArrayList must contain the InstructionContext
148 * objects executed so far in the correct order. This is just
149 * one execution path [out of many]. This is needed to correctly
150 * "merge" in the special case of a RET's successor.
151 * <B>The InstConstraintVisitor and ExecutionVisitor instances
152 * must be set up correctly.</B>
153 * @return true - if and only if the "outgoing" frame situation
154 * changed from the one before execute()ing.
155 */
156 public boolean execute(Frame inFrame, ArrayList execPreds, InstConstraintVisitor icv, ExecutionVisitor ev){
157
158 executionPredecessors = (ArrayList) execPreds.clone();
159
160 //sanity check
161 if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ){
162 throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?");
163 }
164 if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ){
165 throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?");
166 }
167
168 Frame inF = (Frame) inFrames.get(lastExecutionJSR());
169 if (inF == null){// no incoming frame was set, so set it.
170 inFrames.put(lastExecutionJSR(), inFrame);
171 inF = inFrame;
172 }
173 else{// if there was an "old" inFrame
174 if (inF.equals(inFrame)){ //shortcut: no need to merge equal frames.
175 return false;
176 }
177 if (! mergeInFrames(inFrame)){
178 return false;
179 }
180 }
181
182 // Now we're sure the inFrame has changed!
183
184 // new inFrame is already merged in, see above.
185 Frame workingFrame = inF.getClone();
186
187 try{
188 // This verifies the InstructionConstraint for the current
189 // instruction, but does not modify the workingFrame object.
190 //InstConstraintVisitor icv = InstConstraintVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName()));
191 icv.setFrame(workingFrame);
192 getInstruction().accept(icv);
193 }
194 catch(StructuralCodeConstraintException ce){
195 ce.extendMessage("","\nInstructionHandle: "+getInstruction()+"\n");
196 ce.extendMessage("","\nExecution Frame:\n"+workingFrame);
197 extendMessageWithFlow(ce);
198 throw ce;
199 }
200
201 // This executes the Instruction.
202 // Therefore the workingFrame object is modified.
203 //ExecutionVisitor ev = ExecutionVisitor.getInstance(VerifierFactory.getVerifier(method_gen.getClassName()));
204 ev.setFrame(workingFrame);
205 getInstruction().accept(ev);
206 //getInstruction().accept(ExecutionVisitor.withFrame(workingFrame));
207 outFrames.put(lastExecutionJSR(), workingFrame);
208
209 return true; // new inFrame was different from old inFrame so merging them
210 // yielded a different this.inFrame.
211 }
212
213 /**
214 * Returns a simple String representation of this InstructionContext.
215 */
216 public String toString(){
217 //TODO: Put information in the brackets, e.g.
218 // Is this an ExceptionHandler? Is this a RET? Is this the start of
219 // a subroutine?
220 String ret = getInstruction().toString(false)+"\t[InstructionContext]";
221 return ret;
222 }
223
224 /**
225 * Does the actual merging (vmspec2, page 146).
226 * Returns true IFF this.inFrame was changed in course of merging with inFrame.
227 */
228 private boolean mergeInFrames(Frame inFrame){
229 // TODO: Can be performance-improved.
230 Frame inF = (Frame) inFrames.get(lastExecutionJSR());
231 OperandStack oldstack = inF.getStack().getClone();
232 LocalVariables oldlocals = inF.getLocals().getClone();
233 try{
234 inF.getStack().merge(inFrame.getStack());
235 inF.getLocals().merge(inFrame.getLocals());
236 }
237 catch (StructuralCodeConstraintException sce){
238 extendMessageWithFlow(sce);
239 throw sce;
240 }
241 if ( oldstack.equals(inF.getStack()) &&
242 oldlocals.equals(inF.getLocals()) ){
243 return false;
244 }
245 else{
246 return true;
247 }
248 }
249
250 /**
251 * Returns the control flow execution chain. This is built
252 * while execute(Frame, ArrayList)-ing the code represented
253 * by the surrounding ControlFlowGraph.
254 */
255 private String getExecutionChain(){
256 String s = this.toString();
257 for (int i=executionPredecessors.size()-1; i>=0; i--){
258 s = executionPredecessors.get(i)+"\n" + s;
259 }
260 return s;
261 }
262
263
264 /**
265 * Extends the StructuralCodeConstraintException ("e") object with an at-the-end-extended message.
266 * This extended message will then reflect the execution flow needed to get to the constraint
267 * violation that triggered the throwing of the "e" object.
268 */
269 private void extendMessageWithFlow(StructuralCodeConstraintException e){
270 String s = "Execution flow:\n";
271 e.extendMessage("", s+getExecutionChain());
272 }
273
274 /*
275 * Fulfils the contract of InstructionContext.getInstruction().
276 */
277 public InstructionHandle getInstruction(){
278 return instruction;
279 }
280
281 /**
282 * Returns the InstructionContextImpl with an JSR/JSR_W
283 * that was last in the ExecutionChain, without
284 * a corresponding RET, i.e.
285 * we were called by this one.
286 * Returns null if we were called from the top level.
287 */
288 private InstructionContextImpl lastExecutionJSR(){
289
290 int size = executionPredecessors.size();
291 int retcount = 0;
292
293 for (int i=size-1; i>=0; i--){
294 InstructionContextImpl current = (InstructionContextImpl) (executionPredecessors.get(i));
295 Instruction currentlast = current.getInstruction().getInstruction();
296 if (currentlast instanceof RET) {
297 retcount++;
298 }
299 if (currentlast instanceof JsrInstruction){
300 retcount--;
301 if (retcount == -1) {
302 return current;
303 }
304 }
305 }
306 return null;
307 }
308
309 /* Satisfies InstructionContext.getSuccessors(). */
310 public InstructionContext[] getSuccessors(){
311 return contextsOf(_getSuccessors());
312 }
313
314 /**
315 * A utility method that calculates the successors of a given InstructionHandle
316 * That means, a RET does have successors as defined here.
317 * A JsrInstruction has its target as its successor
318 * (opposed to its physical successor) as defined here.
319 */
320 // TODO: implement caching!
321 private InstructionHandle[] _getSuccessors(){
322 final InstructionHandle[] empty = new InstructionHandle[0];
323 final InstructionHandle[] single = new InstructionHandle[1];
324 final InstructionHandle[] pair = new InstructionHandle[2];
325
326 Instruction inst = getInstruction().getInstruction();
327
328 if (inst instanceof RET){
329 Subroutine s = subroutines.subroutineOf(getInstruction());
330 if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project...
331 throw new AssertionViolatedException("Asking for successors of a RET in dead code?!");
332 }
333
334 //TODO: remove. Only JustIce must not use it, but foreign users of the ControlFlowGraph
335 // will want it. Thanks Johannes Wust.
336 //throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?");
337
338 InstructionHandle[] jsrs = s.getEnteringJsrInstructions();
339 InstructionHandle[] ret = new InstructionHandle[jsrs.length];
340 for (int i=0; i<jsrs.length; i++){
341 ret[i] = jsrs[i].getNext();
342 }
343 return ret;
344 }
345
346 // Terminates method normally.
347 if (inst instanceof ReturnInstruction){
348 return empty;
349 }
350
351 // Terminates method abnormally, because JustIce mandates
352 // subroutines not to be protected by exception handlers.
353 if (inst instanceof ATHROW){
354 return empty;
355 }
356
357 // See method comment.
358 if (inst instanceof JsrInstruction){
359 single[0] = ((JsrInstruction) inst).getTarget();
360 return single;
361 }
362
363 if (inst instanceof GotoInstruction){
364 single[0] = ((GotoInstruction) inst).getTarget();
365 return single;
366 }
367
368 if (inst instanceof BranchInstruction){
369 if (inst instanceof Select){
370 // BCEL's getTargets() returns only the non-default targets,
371 // thanks to Eli Tilevich for reporting.
372 InstructionHandle[] matchTargets = ((Select) inst).getTargets();
373 InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
374 ret[0] = ((Select) inst).getTarget();
375 System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
376 return ret;
377 }
378 else{
379 pair[0] = getInstruction().getNext();
380 pair[1] = ((BranchInstruction) inst).getTarget();
381 return pair;
382 }
383 }
384
385 // default case: Fall through.
386 single[0] = getInstruction().getNext();
387 return single;
388 }
389
390 } // End Inner InstructionContextImpl Class.
391
392 /** The MethodGen object we're working on. */
393 private final MethodGen method_gen;
394
395 /** The Subroutines object for the method whose control flow is represented by this ControlFlowGraph. */
396 private final Subroutines subroutines;
397
398 /** The ExceptionHandlers object for the method whose control flow is represented by this ControlFlowGraph. */
399 private final ExceptionHandlers exceptionhandlers;
400
401 /** All InstructionContext instances of this ControlFlowGraph. */
402 private Hashtable instructionContexts = new Hashtable(); //keys: InstructionHandle, values: InstructionContextImpl
403
404 /**
405 * A Control Flow Graph.
406 */
407 public ControlFlowGraph(MethodGen method_gen){
408 subroutines = new Subroutines(method_gen);
409 exceptionhandlers = new ExceptionHandlers(method_gen);
410
411 InstructionHandle[] instructionhandles = method_gen.getInstructionList().getInstructionHandles();
412 for (int i=0; i<instructionhandles.length; i++){
413 instructionContexts.put(instructionhandles[i], new InstructionContextImpl(instructionhandles[i]));
414 }
415
416 this.method_gen = method_gen;
417 }
418
419 /**
420 * Returns the InstructionContext of a given instruction.
421 */
422 public InstructionContext contextOf(InstructionHandle inst){
423 InstructionContext ic = (InstructionContext) instructionContexts.get(inst);
424 if (ic == null){
425 throw new AssertionViolatedException("InstructionContext requested for an InstructionHandle that's not known!");
426 }
427 return ic;
428 }
429
430 /**
431 * Returns the InstructionContext[] of a given InstructionHandle[],
432 * in a naturally ordered manner.
433 */
434 public InstructionContext[] contextsOf(InstructionHandle[] insts){
435 InstructionContext[] ret = new InstructionContext[insts.length];
436 for (int i=0; i<insts.length; i++){
437 ret[i] = contextOf(insts[i]);
438 }
439 return ret;
440 }
441
442 /**
443 * Returns an InstructionContext[] with all the InstructionContext instances
444 * for the method whose control flow is represented by this ControlFlowGraph
445 * <B>(NOT ORDERED!)</B>.
446 */
447 public InstructionContext[] getInstructionContexts(){
448 InstructionContext[] ret = new InstructionContext[instructionContexts.values().size()];
449 return (InstructionContext[]) instructionContexts.values().toArray(ret);
450 }
451
452 /**
453 * Returns true, if and only if the said instruction is not reachable; that means,
454 * if it is not part of this ControlFlowGraph.
455 */
456 public boolean isDead(InstructionHandle i){
457 return subroutines.subroutineOf(i) == null;
458 }
459 }
+0
-57
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.generic.InstructionHandle;
20 import org.apache.bcel.generic.ObjectType;
21
22 /**
23 * This class represents an exception handler; that is, an ObjectType
24 * representing a subclass of java.lang.Throwable and the instruction
25 * the handler starts off (represented by an InstructionContext).
26 *
27 * @version $Id: ExceptionHandler.java 371539 2006-01-23 14:08:00Z tcurdt $
28 * @author Enver Haase
29 */
30 public class ExceptionHandler{
31 /** The type of the exception to catch. NULL means ANY. */
32 private ObjectType catchtype;
33
34 /** The InstructionHandle where the handling begins. */
35 private InstructionHandle handlerpc;
36
37 /** Leave instance creation to JustIce. */
38 ExceptionHandler(ObjectType catch_type, InstructionHandle handler_pc){
39 catchtype = catch_type;
40 handlerpc = handler_pc;
41 }
42
43 /**
44 * Returns the type of the exception that's handled. <B>'null' means 'ANY'.</B>
45 */
46 public ObjectType getExceptionType(){
47 return catchtype;
48 }
49
50 /**
51 * Returns the InstructionHandle where the handler starts off.
52 */
53 public InstructionHandle getHandlerStart(){
54 return handlerpc;
55 }
56 }
+0
-74
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import java.util.HashSet;
20 import java.util.Hashtable;
21 import java.util.Set;
22 import org.apache.bcel.generic.CodeExceptionGen;
23 import org.apache.bcel.generic.InstructionHandle;
24 import org.apache.bcel.generic.MethodGen;
25
26 /**
27 * This class allows easy access to ExceptionHandler objects.
28 *
29 * @version $Id: ExceptionHandlers.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author Enver Haase
31 */
32 public class ExceptionHandlers{
33 /**
34 * The ExceptionHandler instances.
35 * Key: InstructionHandle objects, Values: HashSet<ExceptionHandler> instances.
36 */
37 private Hashtable exceptionhandlers;
38
39 /**
40 * Constructor. Creates a new ExceptionHandlers instance.
41 */
42 public ExceptionHandlers(MethodGen mg){
43 exceptionhandlers = new Hashtable();
44 CodeExceptionGen[] cegs = mg.getExceptionHandlers();
45 for (int i=0; i<cegs.length; i++){
46 ExceptionHandler eh = new ExceptionHandler(cegs[i].getCatchType(), cegs[i].getHandlerPC());
47 for (InstructionHandle ih=cegs[i].getStartPC(); ih != cegs[i].getEndPC().getNext(); ih=ih.getNext()){
48 Set hs;
49 hs = (Set) exceptionhandlers.get(ih);
50 if (hs == null){
51 hs = new HashSet();
52 exceptionhandlers.put(ih, hs);
53 }
54 hs.add(eh);
55 }
56 }
57 }
58
59 /**
60 * Returns all the ExceptionHandler instances representing exception
61 * handlers that protect the instruction ih.
62 */
63 public ExceptionHandler[] getExceptionHandlers(InstructionHandle ih){
64 Set hs = (Set) exceptionhandlers.get(ih);
65 if (hs == null) {
66 return new ExceptionHandler[0];
67 } else{
68 ExceptionHandler[] ret = new ExceptionHandler[hs.size()];
69 return (ExceptionHandler[]) (hs.toArray(ret));
70 }
71 }
72
73 }
+0
-1090
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.classfile.Constant;
21 import org.apache.bcel.classfile.ConstantDouble;
22 import org.apache.bcel.classfile.ConstantFloat;
23 import org.apache.bcel.classfile.ConstantInteger;
24 import org.apache.bcel.classfile.ConstantLong;
25 import org.apache.bcel.classfile.ConstantString;
26 import org.apache.bcel.generic.*;
27
28 /**
29 * This Visitor class may be used for a type-based Java Virtual Machine
30 * simulation.
31 * It does not check for correct types on the OperandStack or in the
32 * LocalVariables; nor does it check their sizes are sufficiently big.
33 * Thus, to use this Visitor for bytecode verifying, you have to make sure
34 * externally that the type constraints of the Java Virtual Machine instructions
35 * are satisfied. An InstConstraintVisitor may be used for this.
36 * Anyway, this Visitor does not mandate it. For example, when you
37 * visitIADD(IADD o), then there are two stack slots popped and one
38 * stack slot containing a Type.INT is pushed (where you could also
39 * pop only one slot if you know there are two Type.INT on top of the
40 * stack). Monitor-specific behaviour is not simulated.
41 *
42 * </P><B>Conventions:</B>
43 *
44 * Type.VOID will never be pushed onto the stack. Type.DOUBLE and Type.LONG
45 * that would normally take up two stack slots (like Double_HIGH and
46 * Double_LOW) are represented by a simple single Type.DOUBLE or Type.LONG
47 * object on the stack here.
48 * If a two-slot type is stored into a local variable, the next variable
49 * is given the type Type.UNKNOWN.
50 *
51 * @version $Id: ExecutionVisitor.java 386056 2006-03-15 11:31:56Z tcurdt $
52 * @author Enver Haase
53 * @see #visitDSTORE(DSTORE o)
54 * @see InstConstraintVisitor
55 */
56 public class ExecutionVisitor extends EmptyVisitor implements Visitor{
57
58 /**
59 * The executionframe we're operating on.
60 */
61 private Frame frame = null;
62
63 /**
64 * The ConstantPoolGen we're working with.
65 * @see #setConstantPoolGen(ConstantPoolGen)
66 */
67 private ConstantPoolGen cpg = null;
68
69 /**
70 * Constructor. Constructs a new instance of this class.
71 */
72 public ExecutionVisitor(){}
73
74 /**
75 * The OperandStack from the current Frame we're operating on.
76 * @see #setFrame(Frame)
77 */
78 private OperandStack stack(){
79 return frame.getStack();
80 }
81
82 /**
83 * The LocalVariables from the current Frame we're operating on.
84 * @see #setFrame(Frame)
85 */
86 private LocalVariables locals(){
87 return frame.getLocals();
88 }
89
90 /**
91 * Sets the ConstantPoolGen needed for symbolic execution.
92 */
93 public void setConstantPoolGen(ConstantPoolGen cpg){
94 this.cpg = cpg;
95 }
96
97 /**
98 * The only method granting access to the single instance of
99 * the ExecutionVisitor class. Before actively using this
100 * instance, <B>SET THE ConstantPoolGen FIRST</B>.
101 * @see #setConstantPoolGen(ConstantPoolGen)
102 */
103 public void setFrame(Frame f){
104 this.frame = f;
105 }
106
107 ///** Symbolically executes the corresponding Java Virtual Machine instruction. */
108 //public void visitWIDE(WIDE o){
109 // The WIDE instruction is modelled as a flag
110 // of the embedded instructions in BCEL.
111 // Therefore BCEL checks for possible errors
112 // when parsing in the .class file: We don't
113 // have even the possibilty to care for WIDE
114 // here.
115 //}
116
117 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
118 public void visitAALOAD(AALOAD o){
119 stack().pop(); // pop the index int
120 //System.out.print(stack().peek());
121 Type t = stack().pop(); // Pop Array type
122 if (t == Type.NULL){
123 stack().push(Type.NULL);
124 } // Do nothing stackwise --- a NullPointerException is thrown at Run-Time
125 else{
126 ArrayType at = (ArrayType) t;
127 stack().push(at.getElementType());
128 }
129 }
130 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
131 public void visitAASTORE(AASTORE o){
132 stack().pop();
133 stack().pop();
134 stack().pop();
135 }
136 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
137 public void visitACONST_NULL(ACONST_NULL o){
138 stack().push(Type.NULL);
139 }
140 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
141 public void visitALOAD(ALOAD o){
142 stack().push(locals().get(o.getIndex()));
143 }
144 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
145 public void visitANEWARRAY(ANEWARRAY o){
146 stack().pop(); //count
147 stack().push( new ArrayType(o.getType(cpg), 1) );
148 }
149 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
150 public void visitARETURN(ARETURN o){
151 stack().pop();
152 }
153 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
154 public void visitARRAYLENGTH(ARRAYLENGTH o){
155 stack().pop();
156 stack().push(Type.INT);
157 }
158
159 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
160 public void visitASTORE(ASTORE o){
161 locals().set(o.getIndex(), stack().pop());
162 //System.err.println("TODO-DEBUG: set LV '"+o.getIndex()+"' to '"+locals().get(o.getIndex())+"'.");
163 }
164
165 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
166 public void visitATHROW(ATHROW o){
167 Type t = stack().pop();
168 stack().clear();
169 if (t.equals(Type.NULL)) {
170 stack().push(Type.getType("Ljava/lang/NullPointerException;"));
171 } else {
172 stack().push(t);
173 }
174 }
175
176 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
177 public void visitBALOAD(BALOAD o){
178 stack().pop();
179 stack().pop();
180 stack().push(Type.INT);
181 }
182
183 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
184 public void visitBASTORE(BASTORE o){
185 stack().pop();
186 stack().pop();
187 stack().pop();
188 }
189
190 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
191 public void visitBIPUSH(BIPUSH o){
192 stack().push(Type.INT);
193 }
194
195 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
196 public void visitCALOAD(CALOAD o){
197 stack().pop();
198 stack().pop();
199 stack().push(Type.INT);
200 }
201 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
202 public void visitCASTORE(CASTORE o){
203 stack().pop();
204 stack().pop();
205 stack().pop();
206 }
207 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
208 public void visitCHECKCAST(CHECKCAST o){
209 // It's possibly wrong to do so, but SUN's
210 // ByteCode verifier seems to do (only) this, too.
211 // TODO: One could use a sophisticated analysis here to check
212 // if a type cannot possibly be cated to another and by
213 // so doing predict the ClassCastException at run-time.
214 stack().pop();
215 stack().push(o.getType(cpg));
216 }
217
218 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
219 public void visitD2F(D2F o){
220 stack().pop();
221 stack().push(Type.FLOAT);
222 }
223 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
224 public void visitD2I(D2I o){
225 stack().pop();
226 stack().push(Type.INT);
227 }
228 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
229 public void visitD2L(D2L o){
230 stack().pop();
231 stack().push(Type.LONG);
232 }
233 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
234 public void visitDADD(DADD o){
235 stack().pop();
236 stack().pop();
237 stack().push(Type.DOUBLE);
238 }
239 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
240 public void visitDALOAD(DALOAD o){
241 stack().pop();
242 stack().pop();
243 stack().push(Type.DOUBLE);
244 }
245 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
246 public void visitDASTORE(DASTORE o){
247 stack().pop();
248 stack().pop();
249 stack().pop();
250 }
251 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
252 public void visitDCMPG(DCMPG o){
253 stack().pop();
254 stack().pop();
255 stack().push(Type.INT);
256 }
257 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
258 public void visitDCMPL(DCMPL o){
259 stack().pop();
260 stack().pop();
261 stack().push(Type.INT);
262 }
263 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
264 public void visitDCONST(DCONST o){
265 stack().push(Type.DOUBLE);
266 }
267 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
268 public void visitDDIV(DDIV o){
269 stack().pop();
270 stack().pop();
271 stack().push(Type.DOUBLE);
272 }
273 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
274 public void visitDLOAD(DLOAD o){
275 stack().push(Type.DOUBLE);
276 }
277 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
278 public void visitDMUL(DMUL o){
279 stack().pop();
280 stack().pop();
281 stack().push(Type.DOUBLE);
282 }
283 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
284 public void visitDNEG(DNEG o){
285 stack().pop();
286 stack().push(Type.DOUBLE);
287 }
288 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
289 public void visitDREM(DREM o){
290 stack().pop();
291 stack().pop();
292 stack().push(Type.DOUBLE);
293 }
294 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
295 public void visitDRETURN(DRETURN o){
296 stack().pop();
297 }
298 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
299 public void visitDSTORE(DSTORE o){
300 locals().set(o.getIndex(), stack().pop());
301 locals().set(o.getIndex()+1, Type.UNKNOWN);
302 }
303 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
304 public void visitDSUB(DSUB o){
305 stack().pop();
306 stack().pop();
307 stack().push(Type.DOUBLE);
308 }
309 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
310 public void visitDUP(DUP o){
311 Type t = stack().pop();
312 stack().push(t);
313 stack().push(t);
314 }
315 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
316 public void visitDUP_X1(DUP_X1 o){
317 Type w1 = stack().pop();
318 Type w2 = stack().pop();
319 stack().push(w1);
320 stack().push(w2);
321 stack().push(w1);
322 }
323 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
324 public void visitDUP_X2(DUP_X2 o){
325 Type w1 = stack().pop();
326 Type w2 = stack().pop();
327 if (w2.getSize() == 2){
328 stack().push(w1);
329 stack().push(w2);
330 stack().push(w1);
331 }
332 else{
333 Type w3 = stack().pop();
334 stack().push(w1);
335 stack().push(w3);
336 stack().push(w2);
337 stack().push(w1);
338 }
339 }
340 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
341 public void visitDUP2(DUP2 o){
342 Type t = stack().pop();
343 if (t.getSize() == 2){
344 stack().push(t);
345 stack().push(t);
346 }
347 else{ // t.getSize() is 1
348 Type u = stack().pop();
349 stack().push(u);
350 stack().push(t);
351 stack().push(u);
352 stack().push(t);
353 }
354 }
355 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
356 public void visitDUP2_X1(DUP2_X1 o){
357 Type t = stack().pop();
358 if (t.getSize() == 2){
359 Type u = stack().pop();
360 stack().push(t);
361 stack().push(u);
362 stack().push(t);
363 }
364 else{ //t.getSize() is1
365 Type u = stack().pop();
366 Type v = stack().pop();
367 stack().push(u);
368 stack().push(t);
369 stack().push(v);
370 stack().push(u);
371 stack().push(t);
372 }
373 }
374 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
375 public void visitDUP2_X2(DUP2_X2 o){
376 Type t = stack().pop();
377 if (t.getSize() == 2){
378 Type u = stack().pop();
379 if (u.getSize() == 2){
380 stack().push(t);
381 stack().push(u);
382 stack().push(t);
383 }else{
384 Type v = stack().pop();
385 stack().push(t);
386 stack().push(v);
387 stack().push(u);
388 stack().push(t);
389 }
390 }
391 else{ //t.getSize() is 1
392 Type u = stack().pop();
393 Type v = stack().pop();
394 if (v.getSize() == 2){
395 stack().push(u);
396 stack().push(t);
397 stack().push(v);
398 stack().push(u);
399 stack().push(t);
400 }else{
401 Type w = stack().pop();
402 stack().push(u);
403 stack().push(t);
404 stack().push(w);
405 stack().push(v);
406 stack().push(u);
407 stack().push(t);
408 }
409 }
410 }
411 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
412 public void visitF2D(F2D o){
413 stack().pop();
414 stack().push(Type.DOUBLE);
415 }
416 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
417 public void visitF2I(F2I o){
418 stack().pop();
419 stack().push(Type.INT);
420 }
421 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
422 public void visitF2L(F2L o){
423 stack().pop();
424 stack().push(Type.LONG);
425 }
426 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
427 public void visitFADD(FADD o){
428 stack().pop();
429 stack().pop();
430 stack().push(Type.FLOAT);
431 }
432 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
433 public void visitFALOAD(FALOAD o){
434 stack().pop();
435 stack().pop();
436 stack().push(Type.FLOAT);
437 }
438 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
439 public void visitFASTORE(FASTORE o){
440 stack().pop();
441 stack().pop();
442 stack().pop();
443 }
444 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
445 public void visitFCMPG(FCMPG o){
446 stack().pop();
447 stack().pop();
448 stack().push(Type.INT);
449 }
450 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
451 public void visitFCMPL(FCMPL o){
452 stack().pop();
453 stack().pop();
454 stack().push(Type.INT);
455 }
456 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
457 public void visitFCONST(FCONST o){
458 stack().push(Type.FLOAT);
459 }
460 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
461 public void visitFDIV(FDIV o){
462 stack().pop();
463 stack().pop();
464 stack().push(Type.FLOAT);
465 }
466 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
467 public void visitFLOAD(FLOAD o){
468 stack().push(Type.FLOAT);
469 }
470 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
471 public void visitFMUL(FMUL o){
472 stack().pop();
473 stack().pop();
474 stack().push(Type.FLOAT);
475 }
476 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
477 public void visitFNEG(FNEG o){
478 stack().pop();
479 stack().push(Type.FLOAT);
480 }
481 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
482 public void visitFREM(FREM o){
483 stack().pop();
484 stack().pop();
485 stack().push(Type.FLOAT);
486 }
487 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
488 public void visitFRETURN(FRETURN o){
489 stack().pop();
490 }
491 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
492 public void visitFSTORE(FSTORE o){
493 locals().set(o.getIndex(), stack().pop());
494 }
495 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
496 public void visitFSUB(FSUB o){
497 stack().pop();
498 stack().pop();
499 stack().push(Type.FLOAT);
500 }
501 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
502 public void visitGETFIELD(GETFIELD o){
503 stack().pop();
504 Type t = o.getFieldType(cpg);
505 if ( t.equals(Type.BOOLEAN) ||
506 t.equals(Type.CHAR) ||
507 t.equals(Type.BYTE) ||
508 t.equals(Type.SHORT) ) {
509 t = Type.INT;
510 }
511 stack().push(t);
512 }
513 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
514 public void visitGETSTATIC(GETSTATIC o){
515 Type t = o.getFieldType(cpg);
516 if ( t.equals(Type.BOOLEAN) ||
517 t.equals(Type.CHAR) ||
518 t.equals(Type.BYTE) ||
519 t.equals(Type.SHORT) ) {
520 t = Type.INT;
521 }
522 stack().push(t);
523 }
524 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
525 public void visitGOTO(GOTO o){
526 // no stack changes.
527 }
528 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
529 public void visitGOTO_W(GOTO_W o){
530 // no stack changes.
531 }
532 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
533 public void visitI2B(I2B o){
534 stack().pop();
535 stack().push(Type.INT);
536 }
537 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
538 public void visitI2C(I2C o){
539 stack().pop();
540 stack().push(Type.INT);
541 }
542 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
543 public void visitI2D(I2D o){
544 stack().pop();
545 stack().push(Type.DOUBLE);
546 }
547 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
548 public void visitI2F(I2F o){
549 stack().pop();
550 stack().push(Type.FLOAT);
551 }
552 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
553 public void visitI2L(I2L o){
554 stack().pop();
555 stack().push(Type.LONG);
556 }
557 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
558 public void visitI2S(I2S o){
559 stack().pop();
560 stack().push(Type.INT);
561 }
562 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
563 public void visitIADD(IADD o){
564 stack().pop();
565 stack().pop();
566 stack().push(Type.INT);
567 }
568 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
569 public void visitIALOAD(IALOAD o){
570 stack().pop();
571 stack().pop();
572 stack().push(Type.INT);
573 }
574 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
575 public void visitIAND(IAND o){
576 stack().pop();
577 stack().pop();
578 stack().push(Type.INT);
579 }
580 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
581 public void visitIASTORE(IASTORE o){
582 stack().pop();
583 stack().pop();
584 stack().pop();
585 }
586 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
587 public void visitICONST(ICONST o){
588 stack().push(Type.INT);
589 }
590 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
591 public void visitIDIV(IDIV o){
592 stack().pop();
593 stack().pop();
594 stack().push(Type.INT);
595 }
596 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
597 public void visitIF_ACMPEQ(IF_ACMPEQ o){
598 stack().pop();
599 stack().pop();
600 }
601 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
602 public void visitIF_ACMPNE(IF_ACMPNE o){
603 stack().pop();
604 stack().pop();
605 }
606 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
607 public void visitIF_ICMPEQ(IF_ICMPEQ o){
608 stack().pop();
609 stack().pop();
610 }
611 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
612 public void visitIF_ICMPGE(IF_ICMPGE o){
613 stack().pop();
614 stack().pop();
615 }
616 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
617 public void visitIF_ICMPGT(IF_ICMPGT o){
618 stack().pop();
619 stack().pop();
620 }
621 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
622 public void visitIF_ICMPLE(IF_ICMPLE o){
623 stack().pop();
624 stack().pop();
625 }
626 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
627 public void visitIF_ICMPLT(IF_ICMPLT o){
628 stack().pop();
629 stack().pop();
630 }
631 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
632 public void visitIF_ICMPNE(IF_ICMPNE o){
633 stack().pop();
634 stack().pop();
635 }
636 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
637 public void visitIFEQ(IFEQ o){
638 stack().pop();
639 }
640 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
641 public void visitIFGE(IFGE o){
642 stack().pop();
643 }
644 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
645 public void visitIFGT(IFGT o){
646 stack().pop();
647 }
648 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
649 public void visitIFLE(IFLE o){
650 stack().pop();
651 }
652 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
653 public void visitIFLT(IFLT o){
654 stack().pop();
655 }
656 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
657 public void visitIFNE(IFNE o){
658 stack().pop();
659 }
660 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
661 public void visitIFNONNULL(IFNONNULL o){
662 stack().pop();
663 }
664 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
665 public void visitIFNULL(IFNULL o){
666 stack().pop();
667 }
668 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
669 public void visitIINC(IINC o){
670 // stack is not changed.
671 }
672 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
673 public void visitILOAD(ILOAD o){
674 stack().push(Type.INT);
675 }
676 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
677 public void visitIMUL(IMUL o){
678 stack().pop();
679 stack().pop();
680 stack().push(Type.INT);
681 }
682 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
683 public void visitINEG(INEG o){
684 stack().pop();
685 stack().push(Type.INT);
686 }
687 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
688 public void visitINSTANCEOF(INSTANCEOF o){
689 stack().pop();
690 stack().push(Type.INT);
691 }
692 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
693 public void visitINVOKEINTERFACE(INVOKEINTERFACE o){
694 stack().pop(); //objectref
695 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
696 stack().pop();
697 }
698 // We are sure the invoked method will xRETURN eventually
699 // We simulate xRETURNs functionality here because we
700 // don't really "jump into" and simulate the invoked
701 // method.
702 if (o.getReturnType(cpg) != Type.VOID){
703 Type t = o.getReturnType(cpg);
704 if ( t.equals(Type.BOOLEAN) ||
705 t.equals(Type.CHAR) ||
706 t.equals(Type.BYTE) ||
707 t.equals(Type.SHORT) ) {
708 t = Type.INT;
709 }
710 stack().push(t);
711 }
712 }
713 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
714 public void visitINVOKESPECIAL(INVOKESPECIAL o){
715 if (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)){
716 UninitializedObjectType t = (UninitializedObjectType) stack().peek(o.getArgumentTypes(cpg).length);
717 if (t == Frame._this){
718 Frame._this = null;
719 }
720 stack().initializeObject(t);
721 locals().initializeObject(t);
722 }
723 stack().pop(); //objectref
724 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
725 stack().pop();
726 }
727 // We are sure the invoked method will xRETURN eventually
728 // We simulate xRETURNs functionality here because we
729 // don't really "jump into" and simulate the invoked
730 // method.
731 if (o.getReturnType(cpg) != Type.VOID){
732 Type t = o.getReturnType(cpg);
733 if ( t.equals(Type.BOOLEAN) ||
734 t.equals(Type.CHAR) ||
735 t.equals(Type.BYTE) ||
736 t.equals(Type.SHORT) ) {
737 t = Type.INT;
738 }
739 stack().push(t);
740 }
741 }
742 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
743 public void visitINVOKESTATIC(INVOKESTATIC o){
744 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
745 stack().pop();
746 }
747 // We are sure the invoked method will xRETURN eventually
748 // We simulate xRETURNs functionality here because we
749 // don't really "jump into" and simulate the invoked
750 // method.
751 if (o.getReturnType(cpg) != Type.VOID){
752 Type t = o.getReturnType(cpg);
753 if ( t.equals(Type.BOOLEAN) ||
754 t.equals(Type.CHAR) ||
755 t.equals(Type.BYTE) ||
756 t.equals(Type.SHORT) ) {
757 t = Type.INT;
758 }
759 stack().push(t);
760 }
761 }
762 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
763 public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
764 stack().pop(); //objectref
765 for (int i=0; i<o.getArgumentTypes(cpg).length; i++){
766 stack().pop();
767 }
768 // We are sure the invoked method will xRETURN eventually
769 // We simulate xRETURNs functionality here because we
770 // don't really "jump into" and simulate the invoked
771 // method.
772 if (o.getReturnType(cpg) != Type.VOID){
773 Type t = o.getReturnType(cpg);
774 if ( t.equals(Type.BOOLEAN) ||
775 t.equals(Type.CHAR) ||
776 t.equals(Type.BYTE) ||
777 t.equals(Type.SHORT) ) {
778 t = Type.INT;
779 }
780 stack().push(t);
781 }
782 }
783 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
784 public void visitIOR(IOR o){
785 stack().pop();
786 stack().pop();
787 stack().push(Type.INT);
788 }
789 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
790 public void visitIREM(IREM o){
791 stack().pop();
792 stack().pop();
793 stack().push(Type.INT);
794 }
795 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
796 public void visitIRETURN(IRETURN o){
797 stack().pop();
798 }
799 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
800 public void visitISHL(ISHL o){
801 stack().pop();
802 stack().pop();
803 stack().push(Type.INT);
804 }
805 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
806 public void visitISHR(ISHR o){
807 stack().pop();
808 stack().pop();
809 stack().push(Type.INT);
810 }
811 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
812 public void visitISTORE(ISTORE o){
813 locals().set(o.getIndex(), stack().pop());
814 }
815 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
816 public void visitISUB(ISUB o){
817 stack().pop();
818 stack().pop();
819 stack().push(Type.INT);
820 }
821 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
822 public void visitIUSHR(IUSHR o){
823 stack().pop();
824 stack().pop();
825 stack().push(Type.INT);
826 }
827 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
828 public void visitIXOR(IXOR o){
829 stack().pop();
830 stack().pop();
831 stack().push(Type.INT);
832 }
833
834 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
835 public void visitJSR(JSR o){
836 stack().push(new ReturnaddressType(o.physicalSuccessor()));
837 //System.err.println("TODO-----------:"+o.physicalSuccessor());
838 }
839
840 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
841 public void visitJSR_W(JSR_W o){
842 stack().push(new ReturnaddressType(o.physicalSuccessor()));
843 }
844
845 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
846 public void visitL2D(L2D o){
847 stack().pop();
848 stack().push(Type.DOUBLE);
849 }
850 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
851 public void visitL2F(L2F o){
852 stack().pop();
853 stack().push(Type.FLOAT);
854 }
855 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
856 public void visitL2I(L2I o){
857 stack().pop();
858 stack().push(Type.INT);
859 }
860 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
861 public void visitLADD(LADD o){
862 stack().pop();
863 stack().pop();
864 stack().push(Type.LONG);
865 }
866 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
867 public void visitLALOAD(LALOAD o){
868 stack().pop();
869 stack().pop();
870 stack().push(Type.LONG);
871 }
872 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
873 public void visitLAND(LAND o){
874 stack().pop();
875 stack().pop();
876 stack().push(Type.LONG);
877 }
878 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
879 public void visitLASTORE(LASTORE o){
880 stack().pop();
881 stack().pop();
882 stack().pop();
883 }
884 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
885 public void visitLCMP(LCMP o){
886 stack().pop();
887 stack().pop();
888 stack().push(Type.INT);
889 }
890 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
891 public void visitLCONST(LCONST o){
892 stack().push(Type.LONG);
893 }
894 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
895 public void visitLDC(LDC o){
896 Constant c = cpg.getConstant(o.getIndex());
897 if (c instanceof ConstantInteger){
898 stack().push(Type.INT);
899 }
900 if (c instanceof ConstantFloat){
901 stack().push(Type.FLOAT);
902 }
903 if (c instanceof ConstantString){
904 stack().push(Type.STRING);
905 }
906 }
907 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
908 public void visitLDC_W(LDC_W o){
909 Constant c = cpg.getConstant(o.getIndex());
910 if (c instanceof ConstantInteger){
911 stack().push(Type.INT);
912 }
913 if (c instanceof ConstantFloat){
914 stack().push(Type.FLOAT);
915 }
916 if (c instanceof ConstantString){
917 stack().push(Type.STRING);
918 }
919 }
920 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
921 public void visitLDC2_W(LDC2_W o){
922 Constant c = cpg.getConstant(o.getIndex());
923 if (c instanceof ConstantLong){
924 stack().push(Type.LONG);
925 }
926 if (c instanceof ConstantDouble){
927 stack().push(Type.DOUBLE);
928 }
929 }
930 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
931 public void visitLDIV(LDIV o){
932 stack().pop();
933 stack().pop();
934 stack().push(Type.LONG);
935 }
936 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
937 public void visitLLOAD(LLOAD o){
938 stack().push(locals().get(o.getIndex()));
939 }
940 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
941 public void visitLMUL(LMUL o){
942 stack().pop();
943 stack().pop();
944 stack().push(Type.LONG);
945 }
946 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
947 public void visitLNEG(LNEG o){
948 stack().pop();
949 stack().push(Type.LONG);
950 }
951 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
952 public void visitLOOKUPSWITCH(LOOKUPSWITCH o){
953 stack().pop(); //key
954 }
955 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
956 public void visitLOR(LOR o){
957 stack().pop();
958 stack().pop();
959 stack().push(Type.LONG);
960 }
961 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
962 public void visitLREM(LREM o){
963 stack().pop();
964 stack().pop();
965 stack().push(Type.LONG);
966 }
967 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
968 public void visitLRETURN(LRETURN o){
969 stack().pop();
970 }
971 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
972 public void visitLSHL(LSHL o){
973 stack().pop();
974 stack().pop();
975 stack().push(Type.LONG);
976 }
977 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
978 public void visitLSHR(LSHR o){
979 stack().pop();
980 stack().pop();
981 stack().push(Type.LONG);
982 }
983 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
984 public void visitLSTORE(LSTORE o){
985 locals().set(o.getIndex(), stack().pop());
986 locals().set(o.getIndex()+1, Type.UNKNOWN);
987 }
988 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
989 public void visitLSUB(LSUB o){
990 stack().pop();
991 stack().pop();
992 stack().push(Type.LONG);
993 }
994 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
995 public void visitLUSHR(LUSHR o){
996 stack().pop();
997 stack().pop();
998 stack().push(Type.LONG);
999 }
1000 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1001 public void visitLXOR(LXOR o){
1002 stack().pop();
1003 stack().pop();
1004 stack().push(Type.LONG);
1005 }
1006 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1007 public void visitMONITORENTER(MONITORENTER o){
1008 stack().pop();
1009 }
1010 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1011 public void visitMONITOREXIT(MONITOREXIT o){
1012 stack().pop();
1013 }
1014 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1015 public void visitMULTIANEWARRAY(MULTIANEWARRAY o){
1016 for (int i=0; i<o.getDimensions(); i++){
1017 stack().pop();
1018 }
1019 stack().push(o.getType(cpg));
1020 }
1021 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1022 public void visitNEW(NEW o){
1023 stack().push(new UninitializedObjectType((ObjectType) (o.getType(cpg))));
1024 }
1025 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1026 public void visitNEWARRAY(NEWARRAY o){
1027 stack().pop();
1028 stack().push(o.getType());
1029 }
1030 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1031 public void visitNOP(NOP o){
1032 }
1033 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1034 public void visitPOP(POP o){
1035 stack().pop();
1036 }
1037 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1038 public void visitPOP2(POP2 o){
1039 Type t = stack().pop();
1040 if (t.getSize() == 1){
1041 stack().pop();
1042 }
1043 }
1044 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1045 public void visitPUTFIELD(PUTFIELD o){
1046 stack().pop();
1047 stack().pop();
1048 }
1049 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1050 public void visitPUTSTATIC(PUTSTATIC o){
1051 stack().pop();
1052 }
1053 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1054 public void visitRET(RET o){
1055 // do nothing, return address
1056 // is in in the local variables.
1057 }
1058 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1059 public void visitRETURN(RETURN o){
1060 // do nothing.
1061 }
1062 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1063 public void visitSALOAD(SALOAD o){
1064 stack().pop();
1065 stack().pop();
1066 stack().push(Type.INT);
1067 }
1068 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1069 public void visitSASTORE(SASTORE o){
1070 stack().pop();
1071 stack().pop();
1072 stack().pop();
1073 }
1074 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1075 public void visitSIPUSH(SIPUSH o){
1076 stack().push(Type.INT);
1077 }
1078 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1079 public void visitSWAP(SWAP o){
1080 Type t = stack().pop();
1081 Type u = stack().pop();
1082 stack().push(t);
1083 stack().push(u);
1084 }
1085 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
1086 public void visitTABLESWITCH(TABLESWITCH o){
1087 stack().pop();
1088 }
1089 }
+0
-119
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/Frame.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19
20 /**
21 * This class represents a JVM execution frame; that means,
22 * a local variable array and an operand stack.
23 *
24 * @version $Id: Frame.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author Enver Haase
26 */
27
28 public class Frame{
29
30 /**
31 * For instance initialization methods, it is important to remember
32 * which instance it is that is not initialized yet. It will be
33 * initialized invoking another constructor later.
34 * NULL means the instance already *is* initialized.
35 */
36 protected static UninitializedObjectType _this;
37
38 /**
39 *
40 */
41 private LocalVariables locals;
42
43 /**
44 *
45 */
46 private OperandStack stack;
47
48 /**
49 *
50 */
51 public Frame(int maxLocals, int maxStack){
52 locals = new LocalVariables(maxLocals);
53 stack = new OperandStack(maxStack);
54 }
55
56 /**
57 *
58 */
59 public Frame(LocalVariables locals, OperandStack stack){
60 this.locals = locals;
61 this.stack = stack;
62 }
63
64 /**
65 *
66 */
67 protected Object clone(){
68 Frame f = new Frame(locals.getClone(), stack.getClone());
69 return f;
70 }
71
72 /**
73 *
74 */
75 public Frame getClone(){
76 return (Frame) clone();
77 }
78
79 /**
80 *
81 */
82 public LocalVariables getLocals(){
83 return locals;
84 }
85
86 /**
87 *
88 */
89 public OperandStack getStack(){
90 return stack;
91 }
92
93 /** @return a hash code value for the object.
94 */
95 public int hashCode() { return stack.hashCode() ^ locals.hashCode(); }
96
97 /**
98 *
99 */
100 public boolean equals(Object o){
101 if (!(o instanceof Frame)) {
102 return false; // implies "null" is non-equal.
103 }
104 Frame f = (Frame) o;
105 return this.stack.equals(f.stack) && this.locals.equals(f.locals);
106 }
107
108 /**
109 * Returns a String representation of the Frame instance.
110 */
111 public String toString(){
112 String s="Local Variables:\n";
113 s += locals;
114 s += "OperandStack:\n";
115 s += stack;
116 return s;
117 }
118 }
+0
-33
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/GenericArray.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 /**
20 * A placeholder class that can be used to create an ObjectType of which
21 * has some of the properties arrays have. They implement java.lang.Cloneable
22 * and java.io.Serializable and they extend java.lang.Object.
23 *
24 * @version $Id: GenericArray.java 371539 2006-01-23 14:08:00Z tcurdt $
25 * @author Enver Haase
26 */
27 public class GenericArray extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable{
28
29 protected Object clone() throws CloneNotSupportedException {
30 return super.clone();
31 }
32 }
+0
-2718
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.Repository;
21 import org.apache.bcel.classfile.Constant;
22 import org.apache.bcel.classfile.ConstantClass;
23 import org.apache.bcel.classfile.ConstantDouble;
24 import org.apache.bcel.classfile.ConstantFieldref;
25 import org.apache.bcel.classfile.ConstantFloat;
26 import org.apache.bcel.classfile.ConstantInteger;
27 import org.apache.bcel.classfile.ConstantLong;
28 import org.apache.bcel.classfile.ConstantString;
29 import org.apache.bcel.classfile.Field;
30 import org.apache.bcel.classfile.JavaClass;
31 import org.apache.bcel.generic.*;
32 import org.apache.bcel.verifier.VerificationResult;
33 import org.apache.bcel.verifier.Verifier;
34 import org.apache.bcel.verifier.VerifierFactory;
35 import org.apache.bcel.verifier.exc.AssertionViolatedException;
36 import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
37
38
39 /**
40 * A Visitor class testing for valid preconditions of JVM instructions.
41 * The instance of this class will throw a StructuralCodeConstraintException
42 * instance if an instruction is visitXXX()ed which has preconditions that are
43 * not satisfied.
44 * TODO: Currently, the JVM's behaviour concerning monitors (MONITORENTER,
45 * MONITOREXIT) is not modeled in JustIce.
46 *
47 * @version $Id: InstConstraintVisitor.java 386056 2006-03-15 11:31:56Z tcurdt $
48 * @author Enver Haase
49 * @see org.apache.bcel.verifier.exc.StructuralCodeConstraintException
50 * @see org.apache.bcel.verifier.exc.LinkingConstraintException
51 */
52 public class InstConstraintVisitor extends EmptyVisitor implements org.apache.bcel.generic.Visitor{
53
54 private static ObjectType GENERIC_ARRAY = ObjectType.getInstance("org.apache.bcel.verifier.structurals.GenericArray");
55
56 /**
57 * The constructor. Constructs a new instance of this class.
58 */
59 public InstConstraintVisitor(){}
60
61 /**
62 * The Execution Frame we're working on.
63 *
64 * @see #setFrame(Frame f)
65 * @see #locals()
66 * @see #stack()
67 */
68 private Frame frame = null;
69
70 /**
71 * The ConstantPoolGen we're working on.
72 *
73 * @see #setConstantPoolGen(ConstantPoolGen cpg)
74 */
75 private ConstantPoolGen cpg = null;
76
77 /**
78 * The MethodGen we're working on.
79 *
80 * @see #setMethodGen(MethodGen mg)
81 */
82 private MethodGen mg = null;
83
84 /**
85 * The OperandStack we're working on.
86 *
87 * @see #setFrame(Frame f)
88 */
89 private OperandStack stack(){
90 return frame.getStack();
91 }
92
93 /**
94 * The LocalVariables we're working on.
95 *
96 * @see #setFrame(Frame f)
97 */
98 private LocalVariables locals(){
99 return frame.getLocals();
100 }
101
102 /**
103 * This method is called by the visitXXX() to notify the acceptor of this InstConstraintVisitor
104 * that a constraint violation has occured. This is done by throwing an instance of a
105 * StructuralCodeConstraintException.
106 * @throws org.apache.bcel.verifier.exc.StructuralCodeConstraintException always.
107 */
108 private void constraintViolated(Instruction violator, String description){
109 String fq_classname = violator.getClass().getName();
110 throw new StructuralCodeConstraintException("Instruction "+ fq_classname.substring(fq_classname.lastIndexOf('.')+1) +" constraint violated: " + description);
111 }
112
113 /**
114 * This returns the single instance of the InstConstraintVisitor class.
115 * To operate correctly, other values must have been set before actually
116 * using the instance.
117 * Use this method for performance reasons.
118 *
119 * @see #setConstantPoolGen(ConstantPoolGen cpg)
120 * @see #setMethodGen(MethodGen mg)
121 */
122 public void setFrame(Frame f){
123 this.frame = f;
124 //if (singleInstance.mg == null || singleInstance.cpg == null) throw new AssertionViolatedException("Forgot to set important values first.");
125 }
126
127 /**
128 * Sets the ConstantPoolGen instance needed for constraint
129 * checking prior to execution.
130 */
131 public void setConstantPoolGen(ConstantPoolGen cpg){
132 this.cpg = cpg;
133 }
134
135 /**
136 * Sets the MethodGen instance needed for constraint
137 * checking prior to execution.
138 */
139 public void setMethodGen(MethodGen mg){
140 this.mg = mg;
141 }
142
143 /**
144 * Assures index is of type INT.
145 * @throws org.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied.
146 */
147 private void indexOfInt(Instruction o, Type index){
148 if (! index.equals(Type.INT)) {
149 constraintViolated(o, "The 'index' is not of type int but of type "+index+".");
150 }
151 }
152
153 /**
154 * Assures the ReferenceType r is initialized (or Type.NULL).
155 * Formally, this means (!(r instanceof UninitializedObjectType)), because
156 * there are no uninitialized array types.
157 * @throws org.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is not satisfied.
158 */
159 private void referenceTypeIsInitialized(Instruction o, ReferenceType r){
160 if (r instanceof UninitializedObjectType){
161 constraintViolated(o, "Working on an uninitialized object '"+r+"'.");
162 }
163 }
164
165 /** Assures value is of type INT. */
166 private void valueOfInt(Instruction o, Type value){
167 if (! value.equals(Type.INT)) {
168 constraintViolated(o, "The 'value' is not of type int but of type "+value+".");
169 }
170 }
171
172 /**
173 * Assures arrayref is of ArrayType or NULL;
174 * returns true if and only if arrayref is non-NULL.
175 * @throws org.apache.bcel.verifier.exc.StructuralCodeConstraintException if the above constraint is violated.
176 */
177 private boolean arrayrefOfArrayType(Instruction o, Type arrayref){
178 if (! ((arrayref instanceof ArrayType) || arrayref.equals(Type.NULL)) ) {
179 constraintViolated(o, "The 'arrayref' does not refer to an array but is of type "+arrayref+".");
180 }
181 return (arrayref instanceof ArrayType);
182 }
183
184 /***************************************************************/
185 /* MISC */
186 /***************************************************************/
187 /**
188 * Ensures the general preconditions of an instruction that accesses the stack.
189 * This method is here because BCEL has no such superinterface for the stack
190 * accessing instructions; and there are funny unexpected exceptions in the
191 * semantices of the superinterfaces and superclasses provided.
192 * E.g. SWAP is a StackConsumer, but DUP_X1 is not a StackProducer.
193 * Therefore, this method is called by all StackProducer, StackConsumer,
194 * and StackInstruction instances via their visitXXX() method.
195 * Unfortunately, as the superclasses and superinterfaces overlap, some instructions
196 * cause this method to be called two or three times. [TODO: Fix this.]
197 *
198 * @see #visitStackConsumer(StackConsumer o)
199 * @see #visitStackProducer(StackProducer o)
200 * @see #visitStackInstruction(StackInstruction o)
201 */
202 private void _visitStackAccessor(Instruction o){
203 int consume = o.consumeStack(cpg); // Stack values are always consumed first; then produced.
204 if (consume > stack().slotsUsed()){
205 constraintViolated((Instruction) o, "Cannot consume "+consume+" stack slots: only "+stack().slotsUsed()+" slot(s) left on stack!\nStack:\n"+stack());
206 }
207
208 int produce = o.produceStack(cpg) - ((Instruction) o).consumeStack(cpg); // Stack values are always consumed first; then produced.
209 if ( produce + stack().slotsUsed() > stack().maxStack() ){
210 constraintViolated((Instruction) o, "Cannot produce "+produce+" stack slots: only "+(stack().maxStack()-stack().slotsUsed())+" free stack slot(s) left.\nStack:\n"+stack());
211 }
212 }
213
214 /***************************************************************/
215 /* "generic"visitXXXX methods where XXXX is an interface */
216 /* therefore, we don't know the order of visiting; but we know */
217 /* these methods are called before the visitYYYY methods below */
218 /***************************************************************/
219
220 /**
221 * Assures the generic preconditions of a LoadClass instance.
222 * The referenced class is loaded and pass2-verified.
223 */
224 public void visitLoadClass(LoadClass o){
225 ObjectType t = o.getLoadClassType(cpg);
226 if (t != null){// null means "no class is loaded"
227 Verifier v = VerifierFactory.getVerifier(t.getClassName());
228 VerificationResult vr = v.doPass2();
229 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
230 constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
231 }
232 }
233 }
234
235 /**
236 * Ensures the general preconditions of a StackConsumer instance.
237 */
238 public void visitStackConsumer(StackConsumer o){
239 _visitStackAccessor((Instruction) o);
240 }
241
242 /**
243 * Ensures the general preconditions of a StackProducer instance.
244 */
245 public void visitStackProducer(StackProducer o){
246 _visitStackAccessor((Instruction) o);
247 }
248
249
250 /***************************************************************/
251 /* "generic" visitYYYY methods where YYYY is a superclass. */
252 /* therefore, we know the order of visiting; we know */
253 /* these methods are called after the visitXXXX methods above. */
254 /***************************************************************/
255 /**
256 * Ensures the general preconditions of a CPInstruction instance.
257 */
258 public void visitCPInstruction(CPInstruction o){
259 int idx = o.getIndex();
260 if ((idx < 0) || (idx >= cpg.getSize())){
261 throw new AssertionViolatedException("Huh?! Constant pool index of instruction '"+o+"' illegal? Pass 3a should have checked this!");
262 }
263 }
264
265 /**
266 * Ensures the general preconditions of a FieldInstruction instance.
267 */
268 public void visitFieldInstruction(FieldInstruction o){
269 // visitLoadClass(o) has been called before: Every FieldOrMethod
270 // implements LoadClass.
271 // visitCPInstruction(o) has been called before.
272 // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC
273 Constant c = cpg.getConstant(o.getIndex());
274 if (!(c instanceof ConstantFieldref)){
275 constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'.");
276 }
277 // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
278 Type t = o.getType(cpg);
279 if (t instanceof ObjectType){
280 String name = ((ObjectType)t).getClassName();
281 Verifier v = VerifierFactory.getVerifier( name );
282 VerificationResult vr = v.doPass2();
283 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
284 constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
285 }
286 }
287 }
288
289 /**
290 * Ensures the general preconditions of an InvokeInstruction instance.
291 */
292 public void visitInvokeInstruction(InvokeInstruction o){
293 // visitLoadClass(o) has been called before: Every FieldOrMethod
294 // implements LoadClass.
295 // visitCPInstruction(o) has been called before.
296 //TODO
297 }
298
299 /**
300 * Ensures the general preconditions of a StackInstruction instance.
301 */
302 public void visitStackInstruction(StackInstruction o){
303 _visitStackAccessor(o);
304 }
305
306 /**
307 * Assures the generic preconditions of a LocalVariableInstruction instance.
308 * That is, the index of the local variable must be valid.
309 */
310 public void visitLocalVariableInstruction(LocalVariableInstruction o){
311 if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ){
312 constraintViolated(o, "The 'index' is not a valid index into the local variable array.");
313 }
314 }
315
316 /**
317 * Assures the generic preconditions of a LoadInstruction instance.
318 */
319 public void visitLoadInstruction(LoadInstruction o){
320 //visitLocalVariableInstruction(o) is called before, because it is more generic.
321
322 // LOAD instructions must not read Type.UNKNOWN
323 if (locals().get(o.getIndex()) == Type.UNKNOWN){
324 constraintViolated(o, "Read-Access on local variable "+o.getIndex()+" with unknown content.");
325 }
326
327 // LOAD instructions, two-slot-values at index N must have Type.UNKNOWN
328 // as a symbol for the higher halve at index N+1
329 // [suppose some instruction put an int at N+1--- our double at N is defective]
330 if (o.getType(cpg).getSize() == 2){
331 if (locals().get(o.getIndex()+1) != Type.UNKNOWN){
332 constraintViolated(o, "Reading a two-locals value from local variables "+o.getIndex()+" and "+(o.getIndex()+1)+" where the latter one is destroyed.");
333 }
334 }
335
336 // LOAD instructions must read the correct type.
337 if (!(o instanceof ALOAD)){
338 if (locals().get(o.getIndex()) != o.getType(cpg) ){
339 constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction type: '"+o.getType(cpg)+"'.");
340 }
341 }
342 else{ // we deal with an ALOAD
343 if (!(locals().get(o.getIndex()) instanceof ReferenceType)){
344 constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"+locals().get(o.getIndex())+"'; Instruction expects a ReferenceType.");
345 }
346 // ALOAD __IS ALLOWED__ to put uninitialized objects onto the stack!
347 //referenceTypeIsInitialized(o, (ReferenceType) (locals().get(o.getIndex())));
348 }
349
350 // LOAD instructions must have enough free stack slots.
351 if ((stack().maxStack() - stack().slotsUsed()) < o.getType(cpg).getSize()){
352 constraintViolated(o, "Not enough free stack slots to load a '"+o.getType(cpg)+"' onto the OperandStack.");
353 }
354 }
355
356 /**
357 * Assures the generic preconditions of a StoreInstruction instance.
358 */
359 public void visitStoreInstruction(StoreInstruction o){
360 //visitLocalVariableInstruction(o) is called before, because it is more generic.
361
362 if (stack().isEmpty()){ // Don't bother about 1 or 2 stack slots used. This check is implicitely done below while type checking.
363 constraintViolated(o, "Cannot STORE: Stack to read from is empty.");
364 }
365
366 if ( (!(o instanceof ASTORE)) ){
367 if (! (stack().peek() == o.getType(cpg)) ){// the other xSTORE types are singletons in BCEL.
368 constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction type: '"+o.getType(cpg)+"'.");
369 }
370 }
371 else{ // we deal with ASTORE
372 Type stacktop = stack().peek();
373 if ( (!(stacktop instanceof ReferenceType)) && (!(stacktop instanceof ReturnaddressType)) ){
374 constraintViolated(o, "Stack top type and STOREing Instruction type mismatch: Stack top: '"+stack().peek()+"'; Instruction expects a ReferenceType or a ReturnadressType.");
375 }
376 //if (stacktop instanceof ReferenceType){
377 // referenceTypeIsInitialized(o, (ReferenceType) stacktop);
378 //}
379 }
380 }
381
382 /**
383 * Assures the generic preconditions of a ReturnInstruction instance.
384 */
385 public void visitReturnInstruction(ReturnInstruction o){
386 Type method_type = mg.getType();
387 if (method_type == Type.BOOLEAN ||
388 method_type == Type.BYTE ||
389 method_type == Type.SHORT ||
390 method_type == Type.CHAR){
391 method_type = Type.INT;
392 }
393
394 if (o instanceof RETURN){
395 if (method_type != Type.VOID){
396 constraintViolated(o, "RETURN instruction in non-void method.");
397 }
398 else{
399 return;
400 }
401 }
402 if (o instanceof ARETURN){
403 if (stack().peek() == Type.NULL){
404 return;
405 }
406 else{
407 if (! (stack().peek() instanceof ReferenceType)){
408 constraintViolated(o, "Reference type expected on top of stack, but is: '"+stack().peek()+"'.");
409 }
410 referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()));
411 //ReferenceType objectref = (ReferenceType) (stack().peek());
412 // TODO: This can only be checked if using Staerk-et-al's "set of object types" instead of a
413 // "wider cast object type" created during verification.
414 //if (! (objectref.isAssignmentCompatibleWith(mg.getType())) ){
415 // constraintViolated(o, "Type on stack top which should be returned is a '"+stack().peek()+"' which is not assignment compatible with the return type of this method, '"+mg.getType()+"'.");
416 //}
417 }
418 }
419 else{
420 if (! ( method_type.equals( stack().peek() ))){
421 constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+"' on top of the stack. But stack top is a '"+stack().peek()+"'.");
422 }
423 }
424 }
425
426 /***************************************************************/
427 /* "special"visitXXXX methods for one type of instruction each */
428 /***************************************************************/
429
430 /**
431 * Ensures the specific preconditions of the said instruction.
432 */
433 public void visitAALOAD(AALOAD o){
434 Type arrayref = stack().peek(1);
435 Type index = stack().peek(0);
436
437 indexOfInt(o, index);
438 if (arrayrefOfArrayType(o, arrayref)){
439 if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){
440 constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+".");
441 }
442 //referenceTypeIsInitialized(o, (ReferenceType) (((ArrayType) arrayref).getElementType()));
443 }
444 }
445
446 /**
447 * Ensures the specific preconditions of the said instruction.
448 */
449 public void visitAASTORE(AASTORE o){
450 try {
451 Type arrayref = stack().peek(2);
452 Type index = stack().peek(1);
453 Type value = stack().peek(0);
454
455 indexOfInt(o, index);
456 if (!(value instanceof ReferenceType)){
457 constraintViolated(o, "The 'value' is not of a ReferenceType but of type "+value+".");
458 }else{
459 //referenceTypeIsInitialized(o, (ReferenceType) value);
460 }
461 // Don't bother further with "referenceTypeIsInitialized()", there are no arrays
462 // of an uninitialized object type.
463 if (arrayrefOfArrayType(o, arrayref)){
464 if (! (((ArrayType) arrayref).getElementType() instanceof ReferenceType)){
465 constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a ReferenceType but to an array of "+((ArrayType) arrayref).getElementType()+".");
466 }
467 if (! ((ReferenceType)value).isAssignmentCompatibleWith((ReferenceType) ((ArrayType) arrayref).getElementType())){
468 constraintViolated(o, "The type of 'value' ('"+value+"') is not assignment compatible to the components of the array 'arrayref' refers to. ('"+((ArrayType) arrayref).getElementType()+"')");
469 }
470 }
471 } catch (ClassNotFoundException e) {
472 // FIXME: maybe not the best way to handle this
473 throw new AssertionViolatedException("Missing class: " + e.toString());
474 }
475 }
476
477 /**
478 * Ensures the specific preconditions of the said instruction.
479 */
480 public void visitACONST_NULL(ACONST_NULL o){
481 // Nothing needs to be done here.
482 }
483
484 /**
485 * Ensures the specific preconditions of the said instruction.
486 */
487 public void visitALOAD(ALOAD o){
488 //visitLoadInstruction(LoadInstruction) is called before.
489
490 // Nothing else needs to be done here.
491 }
492
493 /**
494 * Ensures the specific preconditions of the said instruction.
495 */
496 public void visitANEWARRAY(ANEWARRAY o){
497 if (!stack().peek().equals(Type.INT)) {
498 constraintViolated(o, "The 'count' at the stack top is not of type '"+Type.INT+"' but of type '"+stack().peek()+"'.");
499 // The runtime constant pool item at that index must be a symbolic reference to a class,
500 // array, or interface type. See Pass 3a.
501 }
502 }
503
504 /**
505 * Ensures the specific preconditions of the said instruction.
506 */
507 public void visitARETURN(ARETURN o){
508 if (! (stack().peek() instanceof ReferenceType) ){
509 constraintViolated(o, "The 'objectref' at the stack top is not of a ReferenceType but of type '"+stack().peek()+"'.");
510 }
511 ReferenceType objectref = (ReferenceType) (stack().peek());
512 referenceTypeIsInitialized(o, objectref);
513
514 // The check below should already done via visitReturnInstruction(ReturnInstruction), see there.
515 // It cannot be done using Staerk-et-al's "set of object types" instead of a
516 // "wider cast object type", anyway.
517 //if (! objectref.isAssignmentCompatibleWith(mg.getReturnType() )){
518 // constraintViolated(o, "The 'objectref' type "+objectref+" at the stack top is not assignment compatible with the return type '"+mg.getReturnType()+"' of the method.");
519 //}
520 }
521
522 /**
523 * Ensures the specific preconditions of the said instruction.
524 */
525 public void visitARRAYLENGTH(ARRAYLENGTH o){
526 Type arrayref = stack().peek(0);
527 arrayrefOfArrayType(o, arrayref);
528 }
529
530 /**
531 * Ensures the specific preconditions of the said instruction.
532 */
533 public void visitASTORE(ASTORE o){
534 if (! ( (stack().peek() instanceof ReferenceType) || (stack().peek() instanceof ReturnaddressType) ) ){
535 constraintViolated(o, "The 'objectref' is not of a ReferenceType or of ReturnaddressType but of "+stack().peek()+".");
536 }
537 //if (stack().peek() instanceof ReferenceType){
538 // referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
539 //}
540 }
541
542 /**
543 * Ensures the specific preconditions of the said instruction.
544 */
545 public void visitATHROW(ATHROW o){
546 try {
547 // It's stated that 'objectref' must be of a ReferenceType --- but since Throwable is
548 // not derived from an ArrayType, it follows that 'objectref' must be of an ObjectType or Type.NULL.
549 if (! ((stack().peek() instanceof ObjectType) || (stack().peek().equals(Type.NULL))) ){
550 constraintViolated(o, "The 'objectref' is not of an (initialized) ObjectType but of type "+stack().peek()+".");
551 }
552
553 // NULL is a subclass of every class, so to speak.
554 if (stack().peek().equals(Type.NULL)) {
555 return;
556 }
557
558 ObjectType exc = (ObjectType) (stack().peek());
559 ObjectType throwable = (ObjectType) (Type.getType("Ljava/lang/Throwable;"));
560 if ( (! (exc.subclassOf(throwable)) ) && (! (exc.equals(throwable))) ){
561 constraintViolated(o, "The 'objectref' is not of class Throwable or of a subclass of Throwable, but of '"+stack().peek()+"'.");
562 }
563 } catch (ClassNotFoundException e) {
564 // FIXME: maybe not the best way to handle this
565 throw new AssertionViolatedException("Missing class: " + e.toString());
566 }
567 }
568
569 /**
570 * Ensures the specific preconditions of the said instruction.
571 */
572 public void visitBALOAD(BALOAD o){
573 Type arrayref = stack().peek(1);
574 Type index = stack().peek(0);
575 indexOfInt(o, index);
576 if (arrayrefOfArrayType(o, arrayref)){
577 if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) ||
578 (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ){
579 constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'.");
580 }
581 }
582 }
583
584 /**
585 * Ensures the specific preconditions of the said instruction.
586 */
587 public void visitBASTORE(BASTORE o){
588 Type arrayref = stack().peek(2);
589 Type index = stack().peek(1);
590 Type value = stack().peek(0);
591
592 indexOfInt(o, index);
593 valueOfInt(o, value);
594 if (arrayrefOfArrayType(o, arrayref)){
595 if (! ( (((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)) ||
596 (((ArrayType) arrayref).getElementType().equals(Type.BYTE)) ) ) {
597 constraintViolated(o, "The 'arrayref' does not refer to an array with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"+((ArrayType) arrayref).getElementType()+"'.");
598 }
599 }
600 }
601
602 /**
603 * Ensures the specific preconditions of the said instruction.
604 */
605 public void visitBIPUSH(BIPUSH o){
606 // Nothing to do...
607 }
608
609 /**
610 * Ensures the specific preconditions of the said instruction.
611 */
612 public void visitBREAKPOINT(BREAKPOINT o){
613 throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as BREAKPOINT.");
614 }
615
616 /**
617 * Ensures the specific preconditions of the said instruction.
618 */
619 public void visitCALOAD(CALOAD o){
620 Type arrayref = stack().peek(1);
621 Type index = stack().peek(0);
622
623 indexOfInt(o, index);
624 arrayrefOfArrayType(o, arrayref);
625 }
626
627 /**
628 * Ensures the specific preconditions of the said instruction.
629 */
630 public void visitCASTORE(CASTORE o){
631 Type arrayref = stack().peek(2);
632 Type index = stack().peek(1);
633 Type value = stack().peek(0);
634
635 indexOfInt(o, index);
636 valueOfInt(o, value);
637 if (arrayrefOfArrayType(o, arrayref)){
638 if (! ((ArrayType) arrayref).getElementType().equals(Type.CHAR) ){
639 constraintViolated(o, "The 'arrayref' does not refer to an array with elements of type char but to an array of type "+((ArrayType) arrayref).getElementType()+".");
640 }
641 }
642 }
643
644 /**
645 * Ensures the specific preconditions of the said instruction.
646 */
647 public void visitCHECKCAST(CHECKCAST o){
648 // The objectref must be of type reference.
649 Type objectref = stack().peek(0);
650 if (!(objectref instanceof ReferenceType)){
651 constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+".");
652 }
653 //else{
654 // referenceTypeIsInitialized(o, (ReferenceType) objectref);
655 //}
656 // The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the
657 // current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant
658 // pool item at the index must be a symbolic reference to a class, array, or interface type.
659 Constant c = cpg.getConstant(o.getIndex());
660 if (! (c instanceof ConstantClass)){
661 constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'.");
662 }
663 }
664
665 /**
666 * Ensures the specific preconditions of the said instruction.
667 */
668 public void visitD2F(D2F o){
669 if (stack().peek() != Type.DOUBLE){
670 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
671 }
672 }
673
674 /**
675 * Ensures the specific preconditions of the said instruction.
676 */
677 public void visitD2I(D2I o){
678 if (stack().peek() != Type.DOUBLE){
679 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
680 }
681 }
682
683 /**
684 * Ensures the specific preconditions of the said instruction.
685 */
686 public void visitD2L(D2L o){
687 if (stack().peek() != Type.DOUBLE){
688 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
689 }
690 }
691
692 /**
693 * Ensures the specific preconditions of the said instruction.
694 */
695 public void visitDADD(DADD o){
696 if (stack().peek() != Type.DOUBLE){
697 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
698 }
699 if (stack().peek(1) != Type.DOUBLE){
700 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
701 }
702 }
703
704 /**
705 * Ensures the specific preconditions of the said instruction.
706 */
707 public void visitDALOAD(DALOAD o){
708 indexOfInt(o, stack().peek());
709 if (stack().peek(1) == Type.NULL){
710 return;
711 }
712 if (! (stack().peek(1) instanceof ArrayType)){
713 constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'.");
714 }
715 Type t = ((ArrayType) (stack().peek(1))).getBasicType();
716 if (t != Type.DOUBLE){
717 constraintViolated(o, "Stack next-to-top must be of type double[] but is '"+stack().peek(1)+"'.");
718 }
719 }
720
721 /**
722 * Ensures the specific preconditions of the said instruction.
723 */
724 public void visitDASTORE(DASTORE o){
725 if (stack().peek() != Type.DOUBLE){
726 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
727 }
728 indexOfInt(o, stack().peek(1));
729 if (stack().peek(2) == Type.NULL){
730 return;
731 }
732 if (! (stack().peek(2) instanceof ArrayType)){
733 constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'.");
734 }
735 Type t = ((ArrayType) (stack().peek(2))).getBasicType();
736 if (t != Type.DOUBLE){
737 constraintViolated(o, "Stack next-to-next-to-top must be of type double[] but is '"+stack().peek(2)+"'.");
738 }
739 }
740
741 /**
742 * Ensures the specific preconditions of the said instruction.
743 */
744 public void visitDCMPG(DCMPG o){
745 if (stack().peek() != Type.DOUBLE){
746 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
747 }
748 if (stack().peek(1) != Type.DOUBLE){
749 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
750 }
751 }
752
753 /**
754 * Ensures the specific preconditions of the said instruction.
755 */
756 public void visitDCMPL(DCMPL o){
757 if (stack().peek() != Type.DOUBLE){
758 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
759 }
760 if (stack().peek(1) != Type.DOUBLE){
761 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
762 }
763 }
764
765 /**
766 * Ensures the specific preconditions of the said instruction.
767 */
768 public void visitDCONST(DCONST o){
769 // There's nothing to be done here.
770 }
771
772 /**
773 * Ensures the specific preconditions of the said instruction.
774 */
775 public void visitDDIV(DDIV o){
776 if (stack().peek() != Type.DOUBLE){
777 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
778 }
779 if (stack().peek(1) != Type.DOUBLE){
780 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
781 }
782 }
783
784 /**
785 * Ensures the specific preconditions of the said instruction.
786 */
787 public void visitDLOAD(DLOAD o){
788 //visitLoadInstruction(LoadInstruction) is called before.
789
790 // Nothing else needs to be done here.
791 }
792
793 /**
794 * Ensures the specific preconditions of the said instruction.
795 */
796 public void visitDMUL(DMUL o){
797 if (stack().peek() != Type.DOUBLE){
798 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
799 }
800 if (stack().peek(1) != Type.DOUBLE){
801 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
802 }
803 }
804
805 /**
806 * Ensures the specific preconditions of the said instruction.
807 */
808 public void visitDNEG(DNEG o){
809 if (stack().peek() != Type.DOUBLE){
810 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
811 }
812 }
813
814 /**
815 * Ensures the specific preconditions of the said instruction.
816 */
817 public void visitDREM(DREM o){
818 if (stack().peek() != Type.DOUBLE){
819 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
820 }
821 if (stack().peek(1) != Type.DOUBLE){
822 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
823 }
824 }
825
826 /**
827 * Ensures the specific preconditions of the said instruction.
828 */
829 public void visitDRETURN(DRETURN o){
830 if (stack().peek() != Type.DOUBLE){
831 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
832 }
833 }
834
835 /**
836 * Ensures the specific preconditions of the said instruction.
837 */
838 public void visitDSTORE(DSTORE o){
839 //visitStoreInstruction(StoreInstruction) is called before.
840
841 // Nothing else needs to be done here.
842 }
843
844 /**
845 * Ensures the specific preconditions of the said instruction.
846 */
847 public void visitDSUB(DSUB o){
848 if (stack().peek() != Type.DOUBLE){
849 constraintViolated(o, "The value at the stack top is not of type 'double', but of type '"+stack().peek()+"'.");
850 }
851 if (stack().peek(1) != Type.DOUBLE){
852 constraintViolated(o, "The value at the stack next-to-top is not of type 'double', but of type '"+stack().peek(1)+"'.");
853 }
854 }
855
856 /**
857 * Ensures the specific preconditions of the said instruction.
858 */
859 public void visitDUP(DUP o){
860 if (stack().peek().getSize() != 1){
861 constraintViolated(o, "Won't DUP type on stack top '"+stack().peek()+"' because it must occupy exactly one slot, not '"+stack().peek().getSize()+"'.");
862 }
863 }
864
865 /**
866 * Ensures the specific preconditions of the said instruction.
867 */
868 public void visitDUP_X1(DUP_X1 o){
869 if (stack().peek().getSize() != 1){
870 constraintViolated(o, "Type on stack top '"+stack().peek()+"' should occupy exactly one slot, not '"+stack().peek().getSize()+"'.");
871 }
872 if (stack().peek(1).getSize() != 1){
873 constraintViolated(o, "Type on stack next-to-top '"+stack().peek(1)+"' should occupy exactly one slot, not '"+stack().peek(1).getSize()+"'.");
874 }
875 }
876
877 /**
878 * Ensures the specific preconditions of the said instruction.
879 */
880 public void visitDUP_X2(DUP_X2 o){
881 if (stack().peek().getSize() != 1){
882 constraintViolated(o, "Stack top type must be of size 1, but is '"+stack().peek()+"' of size '"+stack().peek().getSize()+"'.");
883 }
884 if (stack().peek(1).getSize() == 2){
885 return; // Form 2, okay.
886 }
887 else{ //stack().peek(1).getSize == 1.
888 if (stack().peek(2).getSize() != 1){
889 constraintViolated(o, "If stack top's size is 1 and stack next-to-top's size is 1, stack next-to-next-to-top's size must also be 1, but is: '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'.");
890 }
891 }
892 }
893
894 /**
895 * Ensures the specific preconditions of the said instruction.
896 */
897 public void visitDUP2(DUP2 o){
898 if (stack().peek().getSize() == 2){
899 return; // Form 2, okay.
900 }
901 else{ //stack().peek().getSize() == 1.
902 if (stack().peek(1).getSize() != 1){
903 constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'.");
904 }
905 }
906 }
907
908 /**
909 * Ensures the specific preconditions of the said instruction.
910 */
911 public void visitDUP2_X1(DUP2_X1 o){
912 if (stack().peek().getSize() == 2){
913 if (stack().peek(1).getSize() != 1){
914 constraintViolated(o, "If stack top's size is 2, then stack next-to-top's size must be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'.");
915 }
916 else{
917 return; // Form 2
918 }
919 }
920 else{ // stack top is of size 1
921 if ( stack().peek(1).getSize() != 1 ){
922 constraintViolated(o, "If stack top's size is 1, then stack next-to-top's size must also be 1. But it is '"+stack().peek(1)+"' of size '"+stack().peek(1).getSize()+"'.");
923 }
924 if ( stack().peek(2).getSize() != 1 ){
925 constraintViolated(o, "If stack top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'.");
926 }
927 }
928 }
929
930 /**
931 * Ensures the specific preconditions of the said instruction.
932 */
933 public void visitDUP2_X2(DUP2_X2 o){
934
935 if (stack().peek(0).getSize() == 2){
936 if (stack().peek(1).getSize() == 2){
937 return; // Form 4
938 }
939 else{// stack top size is 2, next-to-top's size is 1
940 if ( stack().peek(2).getSize() != 1 ){
941 constraintViolated(o, "If stack top's size is 2 and stack-next-to-top's size is 1, then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+"' of size '"+stack().peek(2).getSize()+"'.");
942 }
943 else{
944 return; // Form 2
945 }
946 }
947 }
948 else{// stack top is of size 1
949 if (stack().peek(1).getSize() == 1){
950 if ( stack().peek(2).getSize() == 2 ){
951 return; // Form 3
952 }
953 else{
954 if ( stack().peek(3).getSize() == 1){
955 return; // Form 1
956 }
957 }
958 }
959 }
960 constraintViolated(o, "The operand sizes on the stack do not match any of the four forms of usage of this instruction.");
961 }
962
963 /**
964 * Ensures the specific preconditions of the said instruction.
965 */
966 public void visitF2D(F2D o){
967 if (stack().peek() != Type.FLOAT){
968 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
969 }
970 }
971
972 /**
973 * Ensures the specific preconditions of the said instruction.
974 */
975 public void visitF2I(F2I o){
976 if (stack().peek() != Type.FLOAT){
977 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
978 }
979 }
980
981 /**
982 * Ensures the specific preconditions of the said instruction.
983 */
984 public void visitF2L(F2L o){
985 if (stack().peek() != Type.FLOAT){
986 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
987 }
988 }
989
990 /**
991 * Ensures the specific preconditions of the said instruction.
992 */
993 public void visitFADD(FADD o){
994 if (stack().peek() != Type.FLOAT){
995 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
996 }
997 if (stack().peek(1) != Type.FLOAT){
998 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
999 }
1000 }
1001
1002 /**
1003 * Ensures the specific preconditions of the said instruction.
1004 */
1005 public void visitFALOAD(FALOAD o){
1006 indexOfInt(o, stack().peek());
1007 if (stack().peek(1) == Type.NULL){
1008 return;
1009 }
1010 if (! (stack().peek(1) instanceof ArrayType)){
1011 constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'.");
1012 }
1013 Type t = ((ArrayType) (stack().peek(1))).getBasicType();
1014 if (t != Type.FLOAT){
1015 constraintViolated(o, "Stack next-to-top must be of type float[] but is '"+stack().peek(1)+"'.");
1016 }
1017 }
1018
1019 /**
1020 * Ensures the specific preconditions of the said instruction.
1021 */
1022 public void visitFASTORE(FASTORE o){
1023 if (stack().peek() != Type.FLOAT){
1024 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1025 }
1026 indexOfInt(o, stack().peek(1));
1027 if (stack().peek(2) == Type.NULL){
1028 return;
1029 }
1030 if (! (stack().peek(2) instanceof ArrayType)){
1031 constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'.");
1032 }
1033 Type t = ((ArrayType) (stack().peek(2))).getBasicType();
1034 if (t != Type.FLOAT){
1035 constraintViolated(o, "Stack next-to-next-to-top must be of type float[] but is '"+stack().peek(2)+"'.");
1036 }
1037 }
1038
1039 /**
1040 * Ensures the specific preconditions of the said instruction.
1041 */
1042 public void visitFCMPG(FCMPG o){
1043 if (stack().peek() != Type.FLOAT){
1044 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1045 }
1046 if (stack().peek(1) != Type.FLOAT){
1047 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1048 }
1049 }
1050
1051 /**
1052 * Ensures the specific preconditions of the said instruction.
1053 */
1054 public void visitFCMPL(FCMPL o){
1055 if (stack().peek() != Type.FLOAT){
1056 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1057 }
1058 if (stack().peek(1) != Type.FLOAT){
1059 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1060 }
1061 }
1062
1063 /**
1064 * Ensures the specific preconditions of the said instruction.
1065 */
1066 public void visitFCONST(FCONST o){
1067 // nothing to do here.
1068 }
1069
1070 /**
1071 * Ensures the specific preconditions of the said instruction.
1072 */
1073 public void visitFDIV(FDIV o){
1074 if (stack().peek() != Type.FLOAT){
1075 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1076 }
1077 if (stack().peek(1) != Type.FLOAT){
1078 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1079 }
1080 }
1081
1082 /**
1083 * Ensures the specific preconditions of the said instruction.
1084 */
1085 public void visitFLOAD(FLOAD o){
1086 //visitLoadInstruction(LoadInstruction) is called before.
1087
1088 // Nothing else needs to be done here.
1089 }
1090
1091 /**
1092 * Ensures the specific preconditions of the said instruction.
1093 */
1094 public void visitFMUL(FMUL o){
1095 if (stack().peek() != Type.FLOAT){
1096 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1097 }
1098 if (stack().peek(1) != Type.FLOAT){
1099 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1100 }
1101 }
1102
1103 /**
1104 * Ensures the specific preconditions of the said instruction.
1105 */
1106 public void visitFNEG(FNEG o){
1107 if (stack().peek() != Type.FLOAT){
1108 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1109 }
1110 }
1111
1112 /**
1113 * Ensures the specific preconditions of the said instruction.
1114 */
1115 public void visitFREM(FREM o){
1116 if (stack().peek() != Type.FLOAT){
1117 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1118 }
1119 if (stack().peek(1) != Type.FLOAT){
1120 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1121 }
1122 }
1123
1124 /**
1125 * Ensures the specific preconditions of the said instruction.
1126 */
1127 public void visitFRETURN(FRETURN o){
1128 if (stack().peek() != Type.FLOAT){
1129 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1130 }
1131 }
1132
1133 /**
1134 * Ensures the specific preconditions of the said instruction.
1135 */
1136 public void visitFSTORE(FSTORE o){
1137 //visitStoreInstruction(StoreInstruction) is called before.
1138
1139 // Nothing else needs to be done here.
1140 }
1141
1142 /**
1143 * Ensures the specific preconditions of the said instruction.
1144 */
1145 public void visitFSUB(FSUB o){
1146 if (stack().peek() != Type.FLOAT){
1147 constraintViolated(o, "The value at the stack top is not of type 'float', but of type '"+stack().peek()+"'.");
1148 }
1149 if (stack().peek(1) != Type.FLOAT){
1150 constraintViolated(o, "The value at the stack next-to-top is not of type 'float', but of type '"+stack().peek(1)+"'.");
1151 }
1152 }
1153
1154 /**
1155 * Ensures the specific preconditions of the said instruction.
1156 */
1157 public void visitGETFIELD(GETFIELD o){
1158 try {
1159 Type objectref = stack().peek();
1160 if (! ( (objectref instanceof ObjectType) || (objectref == Type.NULL) ) ){
1161 constraintViolated(o, "Stack top should be an object reference that's not an array reference, but is '"+objectref+"'.");
1162 }
1163
1164 String field_name = o.getFieldName(cpg);
1165
1166 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
1167 Field[] fields = jc.getFields();
1168 Field f = null;
1169 for (int i=0; i<fields.length; i++){
1170 if (fields[i].getName().equals(field_name)){
1171 Type f_type = Type.getType(fields[i].getSignature());
1172 Type o_type = o.getType(cpg);
1173 /* TODO: Check if assignment compatibility is sufficient.
1174 * What does Sun do?
1175 */
1176 if (f_type.equals(o_type)){
1177 f = fields[i];
1178 break;
1179 }
1180 }
1181 }
1182
1183 if (f == null){
1184 JavaClass[] superclasses = jc.getSuperClasses();
1185 outer:
1186 for (int j=0; j<superclasses.length; j++){
1187 fields = superclasses[j].getFields();
1188 for (int i=0; i<fields.length; i++){
1189 if (fields[i].getName().equals(field_name)){
1190 Type f_type = Type.getType(fields[i].getSignature());
1191 Type o_type = o.getType(cpg);
1192 if (f_type.equals(o_type)){
1193 f = fields[i];
1194 if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0) {
1195 f = null;
1196 }
1197 break outer;
1198 }
1199 }
1200 }
1201 }
1202 if (f == null) {
1203 throw new AssertionViolatedException("Field '"+field_name+"' not found?!?");
1204 }
1205 }
1206
1207 if (f.isProtected()){
1208 ObjectType classtype = o.getClassType(cpg);
1209 ObjectType curr = ObjectType.getInstance(mg.getClassName());
1210
1211 if ( classtype.equals(curr) ||
1212 curr.subclassOf(classtype) ){
1213 Type t = stack().peek();
1214 if (t == Type.NULL){
1215 return;
1216 }
1217 if (! (t instanceof ObjectType) ){
1218 constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+t+"'.");
1219 }
1220 ObjectType objreftype = (ObjectType) t;
1221 if (! ( objreftype.equals(curr) ||
1222 objreftype.subclassOf(curr) ) ){
1223 //TODO: One day move to Staerk-et-al's "Set of object types" instead of "wider" object types
1224 // created during the verification.
1225 // "Wider" object types don't allow us to check for things like that below.
1226 //constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
1227 }
1228 }
1229 }
1230
1231 // TODO: Could go into Pass 3a.
1232 if (f.isStatic()){
1233 constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
1234 }
1235
1236 } catch (ClassNotFoundException e) {
1237 // FIXME: maybe not the best way to handle this
1238 throw new AssertionViolatedException("Missing class: " + e.toString());
1239 }
1240 }
1241
1242 /**
1243 * Ensures the specific preconditions of the said instruction.
1244 */
1245 public void visitGETSTATIC(GETSTATIC o){
1246 // Field must be static: see Pass 3a.
1247 }
1248
1249 /**
1250 * Ensures the specific preconditions of the said instruction.
1251 */
1252 public void visitGOTO(GOTO o){
1253 // nothing to do here.
1254 }
1255
1256 /**
1257 * Ensures the specific preconditions of the said instruction.
1258 */
1259 public void visitGOTO_W(GOTO_W o){
1260 // nothing to do here.
1261 }
1262
1263 /**
1264 * Ensures the specific preconditions of the said instruction.
1265 */
1266 public void visitI2B(I2B o){
1267 if (stack().peek() != Type.INT){
1268 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1269 }
1270 }
1271
1272 /**
1273 * Ensures the specific preconditions of the said instruction.
1274 */
1275 public void visitI2C(I2C o){
1276 if (stack().peek() != Type.INT){
1277 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1278 }
1279 }
1280
1281 /**
1282 * Ensures the specific preconditions of the said instruction.
1283 */
1284 public void visitI2D(I2D o){
1285 if (stack().peek() != Type.INT){
1286 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1287 }
1288 }
1289
1290 /**
1291 * Ensures the specific preconditions of the said instruction.
1292 */
1293 public void visitI2F(I2F o){
1294 if (stack().peek() != Type.INT){
1295 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1296 }
1297 }
1298
1299 /**
1300 * Ensures the specific preconditions of the said instruction.
1301 */
1302 public void visitI2L(I2L o){
1303 if (stack().peek() != Type.INT){
1304 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1305 }
1306 }
1307
1308 /**
1309 * Ensures the specific preconditions of the said instruction.
1310 */
1311 public void visitI2S(I2S o){
1312 if (stack().peek() != Type.INT){
1313 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1314 }
1315 }
1316
1317 /**
1318 * Ensures the specific preconditions of the said instruction.
1319 */
1320 public void visitIADD(IADD o){
1321 if (stack().peek() != Type.INT){
1322 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1323 }
1324 if (stack().peek(1) != Type.INT){
1325 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1326 }
1327 }
1328
1329 /**
1330 * Ensures the specific preconditions of the said instruction.
1331 */
1332 public void visitIALOAD(IALOAD o){
1333 indexOfInt(o, stack().peek());
1334 if (stack().peek(1) == Type.NULL){
1335 return;
1336 }
1337 if (! (stack().peek(1) instanceof ArrayType)){
1338 constraintViolated(o, "Stack next-to-top must be of type int[] but is '"+stack().peek(1)+"'.");
1339 }
1340 Type t = ((ArrayType) (stack().peek(1))).getBasicType();
1341 if (t != Type.INT){
1342 constraintViolated(o, "Stack next-to-top must be of type int[] but is '"+stack().peek(1)+"'.");
1343 }
1344 }
1345
1346 /**
1347 * Ensures the specific preconditions of the said instruction.
1348 */
1349 public void visitIAND(IAND o){
1350 if (stack().peek() != Type.INT){
1351 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1352 }
1353 if (stack().peek(1) != Type.INT){
1354 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1355 }
1356 }
1357
1358 /**
1359 * Ensures the specific preconditions of the said instruction.
1360 */
1361 public void visitIASTORE(IASTORE o){
1362 if (stack().peek() != Type.INT){
1363 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1364 }
1365 indexOfInt(o, stack().peek(1));
1366 if (stack().peek(2) == Type.NULL){
1367 return;
1368 }
1369 if (! (stack().peek(2) instanceof ArrayType)){
1370 constraintViolated(o, "Stack next-to-next-to-top must be of type int[] but is '"+stack().peek(2)+"'.");
1371 }
1372 Type t = ((ArrayType) (stack().peek(2))).getBasicType();
1373 if (t != Type.INT){
1374 constraintViolated(o, "Stack next-to-next-to-top must be of type int[] but is '"+stack().peek(2)+"'.");
1375 }
1376 }
1377
1378 /**
1379 * Ensures the specific preconditions of the said instruction.
1380 */
1381 public void visitICONST(ICONST o){
1382 //nothing to do here.
1383 }
1384
1385 /**
1386 * Ensures the specific preconditions of the said instruction.
1387 */
1388 public void visitIDIV(IDIV o){
1389 if (stack().peek() != Type.INT){
1390 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1391 }
1392 if (stack().peek(1) != Type.INT){
1393 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1394 }
1395 }
1396
1397 /**
1398 * Ensures the specific preconditions of the said instruction.
1399 */
1400 public void visitIF_ACMPEQ(IF_ACMPEQ o){
1401 if (!(stack().peek() instanceof ReferenceType)){
1402 constraintViolated(o, "The value at the stack top is not of a ReferenceType, but of type '"+stack().peek()+"'.");
1403 }
1404 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
1405
1406 if (!(stack().peek(1) instanceof ReferenceType)){
1407 constraintViolated(o, "The value at the stack next-to-top is not of a ReferenceType, but of type '"+stack().peek(1)+"'.");
1408 }
1409 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek(1)) );
1410
1411 }
1412
1413 /**
1414 * Ensures the specific preconditions of the said instruction.
1415 */
1416 public void visitIF_ACMPNE(IF_ACMPNE o){
1417 if (!(stack().peek() instanceof ReferenceType)){
1418 constraintViolated(o, "The value at the stack top is not of a ReferenceType, but of type '"+stack().peek()+"'.");
1419 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
1420 }
1421 if (!(stack().peek(1) instanceof ReferenceType)){
1422 constraintViolated(o, "The value at the stack next-to-top is not of a ReferenceType, but of type '"+stack().peek(1)+"'.");
1423 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek(1)) );
1424 }
1425 }
1426
1427 /**
1428 * Ensures the specific preconditions of the said instruction.
1429 */
1430 public void visitIF_ICMPEQ(IF_ICMPEQ o){
1431 if (stack().peek() != Type.INT){
1432 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1433 }
1434 if (stack().peek(1) != Type.INT){
1435 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1436 }
1437 }
1438
1439 /**
1440 * Ensures the specific preconditions of the said instruction.
1441 */
1442 public void visitIF_ICMPGE(IF_ICMPGE o){
1443 if (stack().peek() != Type.INT){
1444 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1445 }
1446 if (stack().peek(1) != Type.INT){
1447 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1448 }
1449 }
1450
1451 /**
1452 * Ensures the specific preconditions of the said instruction.
1453 */
1454 public void visitIF_ICMPGT(IF_ICMPGT o){
1455 if (stack().peek() != Type.INT){
1456 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1457 }
1458 if (stack().peek(1) != Type.INT){
1459 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1460 }
1461 }
1462
1463 /**
1464 * Ensures the specific preconditions of the said instruction.
1465 */
1466 public void visitIF_ICMPLE(IF_ICMPLE o){
1467 if (stack().peek() != Type.INT){
1468 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1469 }
1470 if (stack().peek(1) != Type.INT){
1471 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1472 }
1473 }
1474
1475 /**
1476 * Ensures the specific preconditions of the said instruction.
1477 */
1478 public void visitIF_ICMPLT(IF_ICMPLT o){
1479 if (stack().peek() != Type.INT){
1480 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1481 }
1482 if (stack().peek(1) != Type.INT){
1483 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1484 }
1485 }
1486
1487 /**
1488 * Ensures the specific preconditions of the said instruction.
1489 */
1490 public void visitIF_ICMPNE(IF_ICMPNE o){
1491 if (stack().peek() != Type.INT){
1492 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1493 }
1494 if (stack().peek(1) != Type.INT){
1495 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1496 }
1497 }
1498
1499 /**
1500 * Ensures the specific preconditions of the said instruction.
1501 */
1502 public void visitIFEQ(IFEQ o){
1503 if (stack().peek() != Type.INT){
1504 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1505 }
1506 }
1507
1508 /**
1509 * Ensures the specific preconditions of the said instruction.
1510 */
1511 public void visitIFGE(IFGE o){
1512 if (stack().peek() != Type.INT){
1513 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1514 }
1515 }
1516
1517 /**
1518 * Ensures the specific preconditions of the said instruction.
1519 */
1520 public void visitIFGT(IFGT o){
1521 if (stack().peek() != Type.INT){
1522 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1523 }
1524 }
1525
1526 /**
1527 * Ensures the specific preconditions of the said instruction.
1528 */
1529 public void visitIFLE(IFLE o){
1530 if (stack().peek() != Type.INT){
1531 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1532 }
1533 }
1534
1535 /**
1536 * Ensures the specific preconditions of the said instruction.
1537 */
1538 public void visitIFLT(IFLT o){
1539 if (stack().peek() != Type.INT){
1540 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1541 }
1542 }
1543
1544 /**
1545 * Ensures the specific preconditions of the said instruction.
1546 */
1547 public void visitIFNE(IFNE o){
1548 if (stack().peek() != Type.INT){
1549 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1550 }
1551 }
1552
1553 /**
1554 * Ensures the specific preconditions of the said instruction.
1555 */
1556 public void visitIFNONNULL(IFNONNULL o){
1557 if (!(stack().peek() instanceof ReferenceType)){
1558 constraintViolated(o, "The value at the stack top is not of a ReferenceType, but of type '"+stack().peek()+"'.");
1559 }
1560 referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
1561 }
1562
1563 /**
1564 * Ensures the specific preconditions of the said instruction.
1565 */
1566 public void visitIFNULL(IFNULL o){
1567 if (!(stack().peek() instanceof ReferenceType)){
1568 constraintViolated(o, "The value at the stack top is not of a ReferenceType, but of type '"+stack().peek()+"'.");
1569 }
1570 referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
1571 }
1572
1573 /**
1574 * Ensures the specific preconditions of the said instruction.
1575 */
1576 public void visitIINC(IINC o){
1577 // Mhhh. In BCEL, at this time "IINC" is not a LocalVariableInstruction.
1578 if (locals().maxLocals() <= (o.getType(cpg).getSize()==1? o.getIndex() : o.getIndex()+1) ){
1579 constraintViolated(o, "The 'index' is not a valid index into the local variable array.");
1580 }
1581
1582 indexOfInt(o, locals().get(o.getIndex()));
1583 }
1584
1585 /**
1586 * Ensures the specific preconditions of the said instruction.
1587 */
1588 public void visitILOAD(ILOAD o){
1589 // All done by visitLocalVariableInstruction(), visitLoadInstruction()
1590 }
1591
1592 /**
1593 * Ensures the specific preconditions of the said instruction.
1594 */
1595 public void visitIMPDEP1(IMPDEP1 o){
1596 throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as IMPDEP1.");
1597 }
1598
1599 /**
1600 * Ensures the specific preconditions of the said instruction.
1601 */
1602 public void visitIMPDEP2(IMPDEP2 o){
1603 throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as IMPDEP2.");
1604 }
1605
1606 /**
1607 * Ensures the specific preconditions of the said instruction.
1608 */
1609 public void visitIMUL(IMUL o){
1610 if (stack().peek() != Type.INT){
1611 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1612 }
1613 if (stack().peek(1) != Type.INT){
1614 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1615 }
1616 }
1617
1618 /**
1619 * Ensures the specific preconditions of the said instruction.
1620 */
1621 public void visitINEG(INEG o){
1622 if (stack().peek() != Type.INT){
1623 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1624 }
1625 }
1626
1627 /**
1628 * Ensures the specific preconditions of the said instruction.
1629 */
1630 public void visitINSTANCEOF(INSTANCEOF o){
1631 // The objectref must be of type reference.
1632 Type objectref = stack().peek(0);
1633 if (!(objectref instanceof ReferenceType)){
1634 constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+".");
1635 }
1636 //else{
1637 // referenceTypeIsInitialized(o, (ReferenceType) objectref);
1638 //}
1639 // The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the
1640 // current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant
1641 // pool item at the index must be a symbolic reference to a class, array, or interface type.
1642 Constant c = cpg.getConstant(o.getIndex());
1643 if (! (c instanceof ConstantClass)){
1644 constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'.");
1645 }
1646 }
1647
1648 /**
1649 * Ensures the specific preconditions of the said instruction.
1650 */
1651 public void visitINVOKEINTERFACE(INVOKEINTERFACE o){
1652 // Method is not native, otherwise pass 3 would not happen.
1653
1654 int count = o.getCount();
1655 if (count == 0){
1656 constraintViolated(o, "The 'count' argument must not be 0.");
1657 }
1658 // It is a ConstantInterfaceMethodref, Pass 3a made it sure.
1659 // TODO: Do we want to do anything with it?
1660 //ConstantInterfaceMethodref cimr = (ConstantInterfaceMethodref) (cpg.getConstant(o.getIndex()));
1661
1662 // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
1663
1664 Type t = o.getType(cpg);
1665 if (t instanceof ObjectType){
1666 String name = ((ObjectType)t).getClassName();
1667 Verifier v = VerifierFactory.getVerifier( name );
1668 VerificationResult vr = v.doPass2();
1669 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
1670 constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
1671 }
1672 }
1673
1674
1675 Type[] argtypes = o.getArgumentTypes(cpg);
1676 int nargs = argtypes.length;
1677
1678 for (int i=nargs-1; i>=0; i--){
1679 Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1
1680 Type fromDesc = argtypes[i];
1681 if (fromDesc == Type.BOOLEAN ||
1682 fromDesc == Type.BYTE ||
1683 fromDesc == Type.CHAR ||
1684 fromDesc == Type.SHORT){
1685 fromDesc = Type.INT;
1686 }
1687 if (! fromStack.equals(fromDesc)){
1688 if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
1689 ReferenceType rFromStack = (ReferenceType) fromStack;
1690 //ReferenceType rFromDesc = (ReferenceType) fromDesc;
1691 // TODO: This can only be checked when using Staerk-et-al's "set of object types"
1692 // instead of a "wider cast object type" created during verification.
1693 //if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
1694 // constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
1695 //}
1696 referenceTypeIsInitialized(o, rFromStack);
1697 }
1698 else{
1699 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
1700 }
1701 }
1702 }
1703
1704 Type objref = stack().peek(nargs);
1705 if (objref == Type.NULL){
1706 return;
1707 }
1708 if (! (objref instanceof ReferenceType) ){
1709 constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
1710 }
1711 referenceTypeIsInitialized(o, (ReferenceType) objref);
1712 if (!(objref instanceof ObjectType)){
1713 if (!(objref instanceof ArrayType)){
1714 constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
1715 }
1716 else{
1717 objref = GENERIC_ARRAY;
1718 }
1719 }
1720
1721 // String objref_classname = ((ObjectType) objref).getClassName();
1722 // String theInterface = o.getClassName(cpg);
1723 // TODO: This can only be checked if we're using Staerk-et-al's "set of object types"
1724 // instead of "wider cast object types" generated during verification.
1725 //if ( ! Repository.implementationOf(objref_classname, theInterface) ){
1726 // constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theInterface+"' as expected.");
1727 //}
1728
1729 int counted_count = 1; // 1 for the objectref
1730 for (int i=0; i<nargs; i++){
1731 counted_count += argtypes[i].getSize();
1732 }
1733 if (count != counted_count){
1734 constraintViolated(o, "The 'count' argument should probably read '"+counted_count+"' but is '"+count+"'.");
1735 }
1736 }
1737
1738 /**
1739 * Ensures the specific preconditions of the said instruction.
1740 */
1741 public void visitINVOKESPECIAL(INVOKESPECIAL o){
1742 try {
1743 // Don't init an object twice.
1744 if ( (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)) && (!(stack().peek(o.getArgumentTypes(cpg).length) instanceof UninitializedObjectType)) ){
1745 constraintViolated(o, "Possibly initializing object twice. A valid instruction sequence must not have an uninitialized object on the operand stack or in a local variable during a backwards branch, or in a local variable in code protected by an exception handler. Please see The Java Virtual Machine Specification, Second Edition, 4.9.4 (pages 147 and 148) for details.");
1746 }
1747
1748 // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
1749
1750 Type t = o.getType(cpg);
1751 if (t instanceof ObjectType){
1752 String name = ((ObjectType)t).getClassName();
1753 Verifier v = VerifierFactory.getVerifier( name );
1754 VerificationResult vr = v.doPass2();
1755 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
1756 constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
1757 }
1758 }
1759
1760
1761 Type[] argtypes = o.getArgumentTypes(cpg);
1762 int nargs = argtypes.length;
1763
1764 for (int i=nargs-1; i>=0; i--){
1765 Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1
1766 Type fromDesc = argtypes[i];
1767 if (fromDesc == Type.BOOLEAN ||
1768 fromDesc == Type.BYTE ||
1769 fromDesc == Type.CHAR ||
1770 fromDesc == Type.SHORT){
1771 fromDesc = Type.INT;
1772 }
1773 if (! fromStack.equals(fromDesc)){
1774 if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
1775 ReferenceType rFromStack = (ReferenceType) fromStack;
1776 ReferenceType rFromDesc = (ReferenceType) fromDesc;
1777 // TODO: This can only be checked using Staerk-et-al's "set of object types", not
1778 // using a "wider cast object type".
1779 if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
1780 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
1781 }
1782 referenceTypeIsInitialized(o, rFromStack);
1783 }
1784 else{
1785 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
1786 }
1787 }
1788 }
1789
1790 Type objref = stack().peek(nargs);
1791 if (objref == Type.NULL){
1792 return;
1793 }
1794 if (! (objref instanceof ReferenceType) ){
1795 constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
1796 }
1797 String objref_classname = null;
1798 if ( !(o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME))){
1799 referenceTypeIsInitialized(o, (ReferenceType) objref);
1800 if (!(objref instanceof ObjectType)){
1801 if (!(objref instanceof ArrayType)){
1802 constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
1803 }
1804 else{
1805 objref = GENERIC_ARRAY;
1806 }
1807 }
1808
1809 objref_classname = ((ObjectType) objref).getClassName();
1810 }
1811 else{
1812 if (!(objref instanceof UninitializedObjectType)){
1813 constraintViolated(o, "Expecting an UninitializedObjectType as 'objectref' on the stack, not a '"+objref+"'. Otherwise, you couldn't invoke a method since an array has no methods (not to speak of a return address).");
1814 }
1815 objref_classname = ((UninitializedObjectType) objref).getInitialized().getClassName();
1816 }
1817
1818
1819 String theClass = o.getClassName(cpg);
1820 if ( ! Repository.instanceOf(objref_classname, theClass) ){
1821 constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected.");
1822 }
1823
1824 } catch (ClassNotFoundException e) {
1825 // FIXME: maybe not the best way to handle this
1826 throw new AssertionViolatedException("Missing class: " + e.toString());
1827 }
1828 }
1829
1830 /**
1831 * Ensures the specific preconditions of the said instruction.
1832 */
1833 public void visitINVOKESTATIC(INVOKESTATIC o){
1834 try {
1835 // Method is not native, otherwise pass 3 would not happen.
1836
1837 Type t = o.getType(cpg);
1838 if (t instanceof ObjectType){
1839 String name = ((ObjectType)t).getClassName();
1840 Verifier v = VerifierFactory.getVerifier( name );
1841 VerificationResult vr = v.doPass2();
1842 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
1843 constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
1844 }
1845 }
1846
1847 Type[] argtypes = o.getArgumentTypes(cpg);
1848 int nargs = argtypes.length;
1849
1850 for (int i=nargs-1; i>=0; i--){
1851 Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1
1852 Type fromDesc = argtypes[i];
1853 if (fromDesc == Type.BOOLEAN ||
1854 fromDesc == Type.BYTE ||
1855 fromDesc == Type.CHAR ||
1856 fromDesc == Type.SHORT){
1857 fromDesc = Type.INT;
1858 }
1859 if (! fromStack.equals(fromDesc)){
1860 if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
1861 ReferenceType rFromStack = (ReferenceType) fromStack;
1862 ReferenceType rFromDesc = (ReferenceType) fromDesc;
1863 // TODO: This check can possibly only be done using Staerk-et-al's "set of object types"
1864 // instead of a "wider cast object type" created during verification.
1865 if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
1866 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
1867 }
1868 referenceTypeIsInitialized(o, rFromStack);
1869 }
1870 else{
1871 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
1872 }
1873 }
1874 }
1875 } catch (ClassNotFoundException e) {
1876 // FIXME: maybe not the best way to handle this
1877 throw new AssertionViolatedException("Missing class: " + e.toString());
1878 }
1879 }
1880
1881 /**
1882 * Ensures the specific preconditions of the said instruction.
1883 */
1884 public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
1885 try {
1886 // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
1887
1888 Type t = o.getType(cpg);
1889 if (t instanceof ObjectType){
1890 String name = ((ObjectType)t).getClassName();
1891 Verifier v = VerifierFactory.getVerifier( name );
1892 VerificationResult vr = v.doPass2();
1893 if (vr.getStatus() != VerificationResult.VERIFIED_OK){
1894 constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
1895 }
1896 }
1897
1898
1899 Type[] argtypes = o.getArgumentTypes(cpg);
1900 int nargs = argtypes.length;
1901
1902 for (int i=nargs-1; i>=0; i--){
1903 Type fromStack = stack().peek( (nargs-1) - i ); // 0 to nargs-1
1904 Type fromDesc = argtypes[i];
1905 if (fromDesc == Type.BOOLEAN ||
1906 fromDesc == Type.BYTE ||
1907 fromDesc == Type.CHAR ||
1908 fromDesc == Type.SHORT){
1909 fromDesc = Type.INT;
1910 }
1911 if (! fromStack.equals(fromDesc)){
1912 if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
1913 ReferenceType rFromStack = (ReferenceType) fromStack;
1914 ReferenceType rFromDesc = (ReferenceType) fromDesc;
1915 // TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead
1916 // of a single "wider cast object type" created during verification.
1917 if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
1918 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
1919 }
1920 referenceTypeIsInitialized(o, rFromStack);
1921 }
1922 else{
1923 constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
1924 }
1925 }
1926 }
1927
1928 Type objref = stack().peek(nargs);
1929 if (objref == Type.NULL){
1930 return;
1931 }
1932 if (! (objref instanceof ReferenceType) ){
1933 constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
1934 }
1935 referenceTypeIsInitialized(o, (ReferenceType) objref);
1936 if (!(objref instanceof ObjectType)){
1937 if (!(objref instanceof ArrayType)){
1938 constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
1939 }
1940 else{
1941 objref = GENERIC_ARRAY;
1942 }
1943 }
1944
1945 String objref_classname = ((ObjectType) objref).getClassName();
1946
1947 String theClass = o.getClassName(cpg);
1948
1949 if ( ! Repository.instanceOf(objref_classname, theClass) ){
1950 constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected.");
1951 }
1952 } catch (ClassNotFoundException e) {
1953 // FIXME: maybe not the best way to handle this
1954 throw new AssertionViolatedException("Missing class: " + e.toString());
1955 }
1956 }
1957
1958 /**
1959 * Ensures the specific preconditions of the said instruction.
1960 */
1961 public void visitIOR(IOR o){
1962 if (stack().peek() != Type.INT){
1963 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1964 }
1965 if (stack().peek(1) != Type.INT){
1966 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1967 }
1968 }
1969
1970 /**
1971 * Ensures the specific preconditions of the said instruction.
1972 */
1973 public void visitIREM(IREM o){
1974 if (stack().peek() != Type.INT){
1975 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1976 }
1977 if (stack().peek(1) != Type.INT){
1978 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
1979 }
1980 }
1981
1982 /**
1983 * Ensures the specific preconditions of the said instruction.
1984 */
1985 public void visitIRETURN(IRETURN o){
1986 if (stack().peek() != Type.INT){
1987 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1988 }
1989 }
1990
1991 /**
1992 * Ensures the specific preconditions of the said instruction.
1993 */
1994 public void visitISHL(ISHL o){
1995 if (stack().peek() != Type.INT){
1996 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
1997 }
1998 if (stack().peek(1) != Type.INT){
1999 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
2000 }
2001 }
2002
2003 /**
2004 * Ensures the specific preconditions of the said instruction.
2005 */
2006 public void visitISHR(ISHR o){
2007 if (stack().peek() != Type.INT){
2008 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2009 }
2010 if (stack().peek(1) != Type.INT){
2011 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
2012 }
2013 }
2014
2015 /**
2016 * Ensures the specific preconditions of the said instruction.
2017 */
2018 public void visitISTORE(ISTORE o){
2019 //visitStoreInstruction(StoreInstruction) is called before.
2020
2021 // Nothing else needs to be done here.
2022 }
2023
2024 /**
2025 * Ensures the specific preconditions of the said instruction.
2026 */
2027 public void visitISUB(ISUB o){
2028 if (stack().peek() != Type.INT){
2029 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2030 }
2031 if (stack().peek(1) != Type.INT){
2032 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
2033 }
2034 }
2035
2036 /**
2037 * Ensures the specific preconditions of the said instruction.
2038 */
2039 public void visitIUSHR(IUSHR o){
2040 if (stack().peek() != Type.INT){
2041 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2042 }
2043 if (stack().peek(1) != Type.INT){
2044 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
2045 }
2046 }
2047
2048 /**
2049 * Ensures the specific preconditions of the said instruction.
2050 */
2051 public void visitIXOR(IXOR o){
2052 if (stack().peek() != Type.INT){
2053 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2054 }
2055 if (stack().peek(1) != Type.INT){
2056 constraintViolated(o, "The value at the stack next-to-top is not of type 'int', but of type '"+stack().peek(1)+"'.");
2057 }
2058 }
2059
2060 /**
2061 * Ensures the specific preconditions of the said instruction.
2062 */
2063 public void visitJSR(JSR o){
2064 // nothing to do here.
2065 }
2066
2067 /**
2068 * Ensures the specific preconditions of the said instruction.
2069 */
2070 public void visitJSR_W(JSR_W o){
2071 // nothing to do here.
2072 }
2073
2074 /**
2075 * Ensures the specific preconditions of the said instruction.
2076 */
2077 public void visitL2D(L2D o){
2078 if (stack().peek() != Type.LONG){
2079 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2080 }
2081 }
2082
2083 /**
2084 * Ensures the specific preconditions of the said instruction.
2085 */
2086 public void visitL2F(L2F o){
2087 if (stack().peek() != Type.LONG){
2088 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2089 }
2090 }
2091
2092 /**
2093 * Ensures the specific preconditions of the said instruction.
2094 */
2095 public void visitL2I(L2I o){
2096 if (stack().peek() != Type.LONG){
2097 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2098 }
2099 }
2100
2101 /**
2102 * Ensures the specific preconditions of the said instruction.
2103 */
2104 public void visitLADD(LADD o){
2105 if (stack().peek() != Type.LONG){
2106 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2107 }
2108 if (stack().peek(1) != Type.LONG){
2109 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2110 }
2111 }
2112
2113 /**
2114 * Ensures the specific preconditions of the said instruction.
2115 */
2116 public void visitLALOAD(LALOAD o){
2117 indexOfInt(o, stack().peek());
2118 if (stack().peek(1) == Type.NULL){
2119 return;
2120 }
2121 if (! (stack().peek(1) instanceof ArrayType)){
2122 constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'.");
2123 }
2124 Type t = ((ArrayType) (stack().peek(1))).getBasicType();
2125 if (t != Type.LONG){
2126 constraintViolated(o, "Stack next-to-top must be of type long[] but is '"+stack().peek(1)+"'.");
2127 }
2128 }
2129
2130 /**
2131 * Ensures the specific preconditions of the said instruction.
2132 */
2133 public void visitLAND(LAND o){
2134 if (stack().peek() != Type.LONG){
2135 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2136 }
2137 if (stack().peek(1) != Type.LONG){
2138 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2139 }
2140 }
2141
2142 /**
2143 * Ensures the specific preconditions of the said instruction.
2144 */
2145 public void visitLASTORE(LASTORE o){
2146 if (stack().peek() != Type.LONG){
2147 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2148 }
2149 indexOfInt(o, stack().peek(1));
2150 if (stack().peek(2) == Type.NULL){
2151 return;
2152 }
2153 if (! (stack().peek(2) instanceof ArrayType)){
2154 constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'.");
2155 }
2156 Type t = ((ArrayType) (stack().peek(2))).getBasicType();
2157 if (t != Type.LONG){
2158 constraintViolated(o, "Stack next-to-next-to-top must be of type long[] but is '"+stack().peek(2)+"'.");
2159 }
2160 }
2161
2162 /**
2163 * Ensures the specific preconditions of the said instruction.
2164 */
2165 public void visitLCMP(LCMP o){
2166 if (stack().peek() != Type.LONG){
2167 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2168 }
2169 if (stack().peek(1) != Type.LONG){
2170 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2171 }
2172 }
2173
2174 /**
2175 * Ensures the specific preconditions of the said instruction.
2176 */
2177 public void visitLCONST(LCONST o){
2178 // Nothing to do here.
2179 }
2180
2181 /**
2182 * Ensures the specific preconditions of the said instruction.
2183 */
2184 public void visitLDC(LDC o){
2185 // visitCPInstruction is called first.
2186
2187 Constant c = cpg.getConstant(o.getIndex());
2188 if (! ( ( c instanceof ConstantInteger) ||
2189 ( c instanceof ConstantFloat ) ||
2190 ( c instanceof ConstantString ) ) ){
2191 constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
2192 }
2193 }
2194
2195 /**
2196 * Ensures the specific preconditions of the said instruction.
2197 */
2198 public void visitLDC_W(LDC_W o){
2199 // visitCPInstruction is called first.
2200
2201 Constant c = cpg.getConstant(o.getIndex());
2202 if (! ( ( c instanceof ConstantInteger) ||
2203 ( c instanceof ConstantFloat ) ||
2204 ( c instanceof ConstantString ) ) ){
2205 constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
2206 }
2207 }
2208
2209 /**
2210 * Ensures the specific preconditions of the said instruction.
2211 */
2212 public void visitLDC2_W(LDC2_W o){
2213 // visitCPInstruction is called first.
2214
2215 Constant c = cpg.getConstant(o.getIndex());
2216 if (! ( ( c instanceof ConstantLong) ||
2217 ( c instanceof ConstantDouble ) ) ){
2218 constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
2219 }
2220 }
2221
2222 /**
2223 * Ensures the specific preconditions of the said instruction.
2224 */
2225 public void visitLDIV(LDIV o){
2226 if (stack().peek() != Type.LONG){
2227 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2228 }
2229 if (stack().peek(1) != Type.LONG){
2230 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2231 }
2232 }
2233
2234 /**
2235 * Ensures the specific preconditions of the said instruction.
2236 */
2237 public void visitLLOAD(LLOAD o){
2238 //visitLoadInstruction(LoadInstruction) is called before.
2239
2240 // Nothing else needs to be done here.
2241 }
2242
2243 /**
2244 * Ensures the specific preconditions of the said instruction.
2245 */
2246 public void visitLMUL(LMUL o){
2247 if (stack().peek() != Type.LONG){
2248 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2249 }
2250 if (stack().peek(1) != Type.LONG){
2251 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2252 }
2253 }
2254
2255 /**
2256 * Ensures the specific preconditions of the said instruction.
2257 */
2258 public void visitLNEG(LNEG o){
2259 if (stack().peek() != Type.LONG){
2260 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2261 }
2262 }
2263
2264 /**
2265 * Ensures the specific preconditions of the said instruction.
2266 */
2267 public void visitLOOKUPSWITCH(LOOKUPSWITCH o){
2268 if (stack().peek() != Type.INT){
2269 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2270 }
2271 // See also pass 3a.
2272 }
2273
2274 /**
2275 * Ensures the specific preconditions of the said instruction.
2276 */
2277 public void visitLOR(LOR o){
2278 if (stack().peek() != Type.LONG){
2279 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2280 }
2281 if (stack().peek(1) != Type.LONG){
2282 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2283 }
2284 }
2285
2286 /**
2287 * Ensures the specific preconditions of the said instruction.
2288 */
2289 public void visitLREM(LREM o){
2290 if (stack().peek() != Type.LONG){
2291 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2292 }
2293 if (stack().peek(1) != Type.LONG){
2294 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2295 }
2296 }
2297
2298 /**
2299 * Ensures the specific preconditions of the said instruction.
2300 */
2301 public void visitLRETURN(LRETURN o){
2302 if (stack().peek() != Type.LONG){
2303 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2304 }
2305 }
2306
2307 /**
2308 * Ensures the specific preconditions of the said instruction.
2309 */
2310 public void visitLSHL(LSHL o){
2311 if (stack().peek() != Type.INT){
2312 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2313 }
2314 if (stack().peek(1) != Type.LONG){
2315 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2316 }
2317 }
2318
2319 /**
2320 * Ensures the specific preconditions of the said instruction.
2321 */
2322 public void visitLSHR(LSHR o){
2323 if (stack().peek() != Type.INT){
2324 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2325 }
2326 if (stack().peek(1) != Type.LONG){
2327 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2328 }
2329 }
2330
2331 /**
2332 * Ensures the specific preconditions of the said instruction.
2333 */
2334 public void visitLSTORE(LSTORE o){
2335 //visitStoreInstruction(StoreInstruction) is called before.
2336
2337 // Nothing else needs to be done here.
2338 }
2339
2340 /**
2341 * Ensures the specific preconditions of the said instruction.
2342 */
2343 public void visitLSUB(LSUB o){
2344 if (stack().peek() != Type.LONG){
2345 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2346 }
2347 if (stack().peek(1) != Type.LONG){
2348 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2349 }
2350 }
2351
2352 /**
2353 * Ensures the specific preconditions of the said instruction.
2354 */
2355 public void visitLUSHR(LUSHR o){
2356 if (stack().peek() != Type.INT){
2357 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2358 }
2359 if (stack().peek(1) != Type.LONG){
2360 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2361 }
2362 }
2363
2364 /**
2365 * Ensures the specific preconditions of the said instruction.
2366 */
2367 public void visitLXOR(LXOR o){
2368 if (stack().peek() != Type.LONG){
2369 constraintViolated(o, "The value at the stack top is not of type 'long', but of type '"+stack().peek()+"'.");
2370 }
2371 if (stack().peek(1) != Type.LONG){
2372 constraintViolated(o, "The value at the stack next-to-top is not of type 'long', but of type '"+stack().peek(1)+"'.");
2373 }
2374 }
2375
2376 /**
2377 * Ensures the specific preconditions of the said instruction.
2378 */
2379 public void visitMONITORENTER(MONITORENTER o){
2380 if (! ((stack().peek()) instanceof ReferenceType)){
2381 constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'.");
2382 }
2383 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
2384 }
2385
2386 /**
2387 * Ensures the specific preconditions of the said instruction.
2388 */
2389 public void visitMONITOREXIT(MONITOREXIT o){
2390 if (! ((stack().peek()) instanceof ReferenceType)){
2391 constraintViolated(o, "The stack top should be of a ReferenceType, but is '"+stack().peek()+"'.");
2392 }
2393 //referenceTypeIsInitialized(o, (ReferenceType) (stack().peek()) );
2394 }
2395
2396 /**
2397 * Ensures the specific preconditions of the said instruction.
2398 */
2399 public void visitMULTIANEWARRAY(MULTIANEWARRAY o){
2400 int dimensions = o.getDimensions();
2401 // Dimensions argument is okay: see Pass 3a.
2402 for (int i=0; i<dimensions; i++){
2403 if (stack().peek(i) != Type.INT){
2404 constraintViolated(o, "The '"+dimensions+"' upper stack types should be 'int' but aren't.");
2405 }
2406 }
2407 // The runtime constant pool item at that index must be a symbolic reference to a class,
2408 // array, or interface type. See Pass 3a.
2409 }
2410
2411 /**
2412 * Ensures the specific preconditions of the said instruction.
2413 */
2414 public void visitNEW(NEW o){
2415 //visitCPInstruction(CPInstruction) has been called before.
2416 //visitLoadClass(LoadClass) has been called before.
2417
2418 Type t = o.getType(cpg);
2419 if (! (t instanceof ReferenceType)){
2420 throw new AssertionViolatedException("NEW.getType() returning a non-reference type?!");
2421 }
2422 if (! (t instanceof ObjectType)){
2423 constraintViolated(o, "Expecting a class type (ObjectType) to work on. Found: '"+t+"'.");
2424 }
2425 ObjectType obj = (ObjectType) t;
2426
2427 //e.g.: Don't instantiate interfaces
2428 if (! obj.referencesClass()){
2429 constraintViolated(o, "Expecting a class type (ObjectType) to work on. Found: '"+obj+"'.");
2430 }
2431 }
2432
2433 /**
2434 * Ensures the specific preconditions of the said instruction.
2435 */
2436 public void visitNEWARRAY(NEWARRAY o){
2437 if (stack().peek() != Type.INT){
2438 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2439 }
2440 }
2441
2442 /**
2443 * Ensures the specific preconditions of the said instruction.
2444 */
2445 public void visitNOP(NOP o){
2446 // nothing is to be done here.
2447 }
2448
2449 /**
2450 * Ensures the specific preconditions of the said instruction.
2451 */
2452 public void visitPOP(POP o){
2453 if (stack().peek().getSize() != 1){
2454 constraintViolated(o, "Stack top size should be 1 but stack top is '"+stack().peek()+"' of size '"+stack().peek().getSize()+"'.");
2455 }
2456 }
2457
2458 /**
2459 * Ensures the specific preconditions of the said instruction.
2460 */
2461 public void visitPOP2(POP2 o){
2462 if (stack().peek().getSize() != 2){
2463 constraintViolated(o, "Stack top size should be 2 but stack top is '"+stack().peek()+"' of size '"+stack().peek().getSize()+"'.");
2464 }
2465 }
2466
2467 /**
2468 * Ensures the specific preconditions of the said instruction.
2469 */
2470 public void visitPUTFIELD(PUTFIELD o){
2471 try {
2472
2473 Type objectref = stack().peek(1);
2474 if (! ( (objectref instanceof ObjectType) || (objectref == Type.NULL) ) ){
2475 constraintViolated(o, "Stack next-to-top should be an object reference that's not an array reference, but is '"+objectref+"'.");
2476 }
2477
2478 String field_name = o.getFieldName(cpg);
2479
2480 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
2481 Field[] fields = jc.getFields();
2482 Field f = null;
2483 for (int i=0; i<fields.length; i++){
2484 if (fields[i].getName().equals(field_name)){
2485 Type f_type = Type.getType(fields[i].getSignature());
2486 Type o_type = o.getType(cpg);
2487 /* TODO: Check if assignment compatibility is sufficient.
2488 * What does Sun do?
2489 */
2490 if (f_type.equals(o_type)){
2491 f = fields[i];
2492 break;
2493 }
2494 }
2495 }
2496 if (f == null){
2497 throw new AssertionViolatedException("Field not found?!?");
2498 }
2499
2500 Type value = stack().peek();
2501 Type t = Type.getType(f.getSignature());
2502 Type shouldbe = t;
2503 if (shouldbe == Type.BOOLEAN ||
2504 shouldbe == Type.BYTE ||
2505 shouldbe == Type.CHAR ||
2506 shouldbe == Type.SHORT){
2507 shouldbe = Type.INT;
2508 }
2509 if (t instanceof ReferenceType){
2510 ReferenceType rvalue = null;
2511 if (value instanceof ReferenceType){
2512 rvalue = (ReferenceType) value;
2513 referenceTypeIsInitialized(o, rvalue);
2514 }
2515 else{
2516 constraintViolated(o, "The stack top type '"+value+"' is not of a reference type as expected.");
2517 }
2518 // TODO: This can possibly only be checked using Staerk-et-al's "set-of-object types", not
2519 // using "wider cast object types" created during verification.
2520 // Comment it out if you encounter problems. See also the analogon at visitPUTSTATIC.
2521 if (!(rvalue.isAssignmentCompatibleWith(shouldbe))){
2522 constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
2523 }
2524 }
2525 else{
2526 if (shouldbe != value){
2527 constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
2528 }
2529 }
2530
2531 if (f.isProtected()){
2532 ObjectType classtype = o.getClassType(cpg);
2533 ObjectType curr = ObjectType.getInstance(mg.getClassName());
2534
2535 if ( classtype.equals(curr) ||
2536 curr.subclassOf(classtype) ){
2537 Type tp = stack().peek(1);
2538 if (tp == Type.NULL){
2539 return;
2540 }
2541 if (! (tp instanceof ObjectType) ){
2542 constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+tp+"'.");
2543 }
2544 ObjectType objreftype = (ObjectType) tp;
2545 if (! ( objreftype.equals(curr) ||
2546 objreftype.subclassOf(curr) ) ){
2547 constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
2548 }
2549 }
2550 }
2551
2552 // TODO: Could go into Pass 3a.
2553 if (f.isStatic()){
2554 constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
2555 }
2556
2557 } catch (ClassNotFoundException e) {
2558 // FIXME: maybe not the best way to handle this
2559 throw new AssertionViolatedException("Missing class: " + e.toString());
2560 }
2561 }
2562
2563 /**
2564 * Ensures the specific preconditions of the said instruction.
2565 */
2566 public void visitPUTSTATIC(PUTSTATIC o){
2567 try {
2568 String field_name = o.getFieldName(cpg);
2569 JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
2570 Field[] fields = jc.getFields();
2571 Field f = null;
2572 for (int i=0; i<fields.length; i++){
2573 if (fields[i].getName().equals(field_name)){
2574 Type f_type = Type.getType(fields[i].getSignature());
2575 Type o_type = o.getType(cpg);
2576 /* TODO: Check if assignment compatibility is sufficient.
2577 * What does Sun do?
2578 */
2579 if (f_type.equals(o_type)){
2580 f = fields[i];
2581 break;
2582 }
2583 }
2584 }
2585 if (f == null){
2586 throw new AssertionViolatedException("Field not found?!?");
2587 }
2588 Type value = stack().peek();
2589 Type t = Type.getType(f.getSignature());
2590 Type shouldbe = t;
2591 if (shouldbe == Type.BOOLEAN ||
2592 shouldbe == Type.BYTE ||
2593 shouldbe == Type.CHAR ||
2594 shouldbe == Type.SHORT){
2595 shouldbe = Type.INT;
2596 }
2597 if (t instanceof ReferenceType){
2598 ReferenceType rvalue = null;
2599 if (value instanceof ReferenceType){
2600 rvalue = (ReferenceType) value;
2601 referenceTypeIsInitialized(o, rvalue);
2602 }
2603 else{
2604 constraintViolated(o, "The stack top type '"+value+"' is not of a reference type as expected.");
2605 }
2606 // TODO: This can possibly only be checked using Staerk-et-al's "set-of-object types", not
2607 // using "wider cast object types" created during verification.
2608 // Comment it out if you encounter problems. See also the analogon at visitPUTFIELD.
2609 if (!(rvalue.isAssignmentCompatibleWith(shouldbe))){
2610 constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
2611 }
2612 }
2613 else{
2614 if (shouldbe != value){
2615 constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
2616 }
2617 }
2618 // TODO: Interface fields may be assigned to only once. (Hard to implement in
2619 // JustIce's execution model). This may only happen in <clinit>, see Pass 3a.
2620
2621 } catch (ClassNotFoundException e) {
2622 // FIXME: maybe not the best way to handle this
2623 throw new AssertionViolatedException("Missing class: " + e.toString());
2624 }
2625 }
2626
2627 /**
2628 * Ensures the specific preconditions of the said instruction.
2629 */
2630 public void visitRET(RET o){
2631 if (! (locals().get(o.getIndex()) instanceof ReturnaddressType)){
2632 constraintViolated(o, "Expecting a ReturnaddressType in local variable "+o.getIndex()+".");
2633 }
2634 if (locals().get(o.getIndex()) == ReturnaddressType.NO_TARGET){
2635 throw new AssertionViolatedException("Oops: RET expecting a target!");
2636 }
2637 // Other constraints such as non-allowed overlapping subroutines are enforced
2638 // while building the Subroutines data structure.
2639 }
2640
2641 /**
2642 * Ensures the specific preconditions of the said instruction.
2643 */
2644 public void visitRETURN(RETURN o){
2645 if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an <init> method
2646 if ((Frame._this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) {
2647 constraintViolated(o, "Leaving a constructor that itself did not call a constructor.");
2648 }
2649 }
2650 }
2651
2652 /**
2653 * Ensures the specific preconditions of the said instruction.
2654 */
2655 public void visitSALOAD(SALOAD o){
2656 indexOfInt(o, stack().peek());
2657 if (stack().peek(1) == Type.NULL){
2658 return;
2659 }
2660 if (! (stack().peek(1) instanceof ArrayType)){
2661 constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'.");
2662 }
2663 Type t = ((ArrayType) (stack().peek(1))).getBasicType();
2664 if (t != Type.SHORT){
2665 constraintViolated(o, "Stack next-to-top must be of type short[] but is '"+stack().peek(1)+"'.");
2666 }
2667 }
2668
2669 /**
2670 * Ensures the specific preconditions of the said instruction.
2671 */
2672 public void visitSASTORE(SASTORE o){
2673 if (stack().peek() != Type.INT){
2674 constraintViolated(o, "The value at the stack top is not of type 'int', but of type '"+stack().peek()+"'.");
2675 }
2676 indexOfInt(o, stack().peek(1));
2677 if (stack().peek(2) == Type.NULL){
2678 return;
2679 }
2680 if (! (stack().peek(2) instanceof ArrayType)){
2681 constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'.");
2682 }
2683 Type t = ((ArrayType) (stack().peek(2))).getBasicType();
2684 if (t != Type.SHORT){
2685 constraintViolated(o, "Stack next-to-next-to-top must be of type short[] but is '"+stack().peek(2)+"'.");
2686 }
2687 }
2688
2689 /**
2690 * Ensures the specific preconditions of the said instruction.
2691 */
2692 public void visitSIPUSH(SIPUSH o){
2693 // nothing to do here. Generic visitXXX() methods did the trick before.
2694 }
2695
2696 /**
2697 * Ensures the specific preconditions of the said instruction.
2698 */
2699 public void visitSWAP(SWAP o){
2700 if (stack().peek().getSize() != 1){
2701 constraintViolated(o, "The value at the stack top is not of size '1', but of size '"+stack().peek().getSize()+"'.");
2702 }
2703 if (stack().peek(1).getSize() != 1){
2704 constraintViolated(o, "The value at the stack next-to-top is not of size '1', but of size '"+stack().peek(1).getSize()+"'.");
2705 }
2706 }
2707
2708 /**
2709 * Ensures the specific preconditions of the said instruction.
2710 */
2711 public void visitTABLESWITCH(TABLESWITCH o){
2712 indexOfInt(o, stack().peek());
2713 // See Pass 3a.
2714 }
2715
2716 }
2717
+0
-105
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/InstructionContext.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import java.util.ArrayList;
20 import org.apache.bcel.generic.InstructionHandle;
21
22 /**
23 * An InstructionContext offers convenient access
24 * to information like control flow successors and
25 * such.
26 *
27 * @version $Id: InstructionContext.java 382272 2006-03-02 03:31:46Z tcurdt $
28 * @author Enver Haase
29 */
30 public interface InstructionContext{
31
32 /**
33 * The getTag and setTag methods may be used for
34 * temporary flagging, such as graph colouring.
35 * Nothing in the InstructionContext object depends
36 * on the value of the tag. JustIce does not use it.
37 *
38 * @see #setTag(int tag)
39 */
40 public int getTag();
41
42 /**
43 * The getTag and setTag methods may be used for
44 * temporary flagging, such as graph colouring.
45 * Nothing in the InstructionContext object depends
46 * on the value of the tag. JustIce does not use it.
47 *
48 * @see #getTag()
49 */
50 public void setTag(int tag);
51
52 /**
53 * This method symbolically executes the Instruction
54 * held in the InstructionContext.
55 * It "merges in" the incoming execution frame situation
56 * (see The Java Virtual Machine Specification, 2nd
57 * edition, page 146).
58 * By so doing, the outgoing execution frame situation
59 * is calculated.
60 *
61 * This method is JustIce-specific and is usually of
62 * no sense for users of the ControlFlowGraph class.
63 * They should use getInstruction().accept(Visitor),
64 * possibly in conjunction with the ExecutionVisitor.
65 *
66 *
67 * @see ControlFlowGraph
68 * @see ExecutionVisitor
69 * @see #getOutFrame(ArrayList)
70 * @return true - if and only if the "outgoing" frame situation
71 * changed from the one before execute()ing.
72 */
73 boolean execute(Frame inFrame, ArrayList executionPredecessors, InstConstraintVisitor icv, ExecutionVisitor ev);
74
75 Frame getInFrame();
76
77 /**
78 * This method returns the outgoing execution frame situation;
79 * therefore <B>it has to be calculated by execute(Frame, ArrayList)
80 * first.</B>
81 *
82 * @see #execute(Frame, ArrayList, InstConstraintVisitor, ExecutionVisitor)
83 */
84 Frame getOutFrame(ArrayList executionPredecessors);
85
86 /**
87 * Returns the InstructionHandle this InstructionContext is wrapped around.
88 *
89 * @return The InstructionHandle this InstructionContext is wrapped around.
90 */
91 InstructionHandle getInstruction();
92
93 /**
94 * Returns the usual control flow successors.
95 * @see #getExceptionHandlers()
96 */
97 InstructionContext[] getSuccessors();
98
99 /**
100 * Returns the exception handlers that protect this instruction.
101 * They are special control flow successors.
102 */
103 ExceptionHandler[] getExceptionHandlers();
104 }
+0
-209
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/LocalVariables.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.generic.ReferenceType;
20 import org.apache.bcel.generic.Type;
21 import org.apache.bcel.verifier.exc.AssertionViolatedException;
22 import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
23
24 /**
25 * This class implements an array of local variables used for symbolic JVM
26 * simulation.
27 *
28 * @version $Id: LocalVariables.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author Enver Haase
30 */
31 public class LocalVariables{
32 /** The Type[] containing the local variable slots. */
33 private Type[] locals;
34
35 /**
36 * Creates a new LocalVariables object.
37 */
38 public LocalVariables(int maxLocals){
39 locals = new Type[maxLocals];
40 for (int i=0; i<maxLocals; i++){
41 locals[i] = Type.UNKNOWN;
42 }
43 }
44
45 /**
46 * Returns a deep copy of this object; i.e. the clone
47 * operates on a new local variable array.
48 * However, the Type objects in the array are shared.
49 */
50 protected Object clone(){
51 LocalVariables lvs = new LocalVariables(locals.length);
52 for (int i=0; i<locals.length; i++){
53 lvs.locals[i] = this.locals[i];
54 }
55 return lvs;
56 }
57
58 /**
59 * Returns the type of the local variable slot i.
60 */
61 public Type get(int i){
62 return locals[i];
63 }
64
65 /**
66 * Returns a (correctly typed) clone of this object.
67 * This is equivalent to ((LocalVariables) this.clone()).
68 */
69 public LocalVariables getClone(){
70 return (LocalVariables) this.clone();
71 }
72
73 /**
74 * Returns the number of local variable slots this
75 * LocalVariables instance has.
76 */
77 public int maxLocals(){
78 return locals.length;
79 }
80
81 /**
82 * Sets a new Type for the given local variable slot.
83 */
84 public void set(int i, Type type){
85 if (type == Type.BYTE || type == Type.SHORT || type == Type.BOOLEAN || type == Type.CHAR){
86 throw new AssertionViolatedException("LocalVariables do not know about '"+type+"'. Use Type.INT instead.");
87 }
88 locals[i] = type;
89 }
90
91 /** @return a hash code value for the object.
92 */
93 public int hashCode() { return locals.length; }
94
95 /*
96 * Fulfills the general contract of Object.equals().
97 */
98 public boolean equals(Object o){
99 if (!(o instanceof LocalVariables)) {
100 return false;
101 }
102 LocalVariables lv = (LocalVariables) o;
103 if (this.locals.length != lv.locals.length) {
104 return false;
105 }
106 for (int i=0; i<this.locals.length; i++){
107 if (!this.locals[i].equals(lv.locals[i])){
108 //System.out.println(this.locals[i]+" is not "+lv.locals[i]);
109 return false;
110 }
111 }
112 return true;
113 }
114
115 /**
116 * Merges two local variables sets as described in the Java Virtual Machine Specification,
117 * Second Edition, section 4.9.2, page 146.
118 */
119 public void merge(LocalVariables lv){
120
121 if (this.locals.length != lv.locals.length){
122 throw new AssertionViolatedException("Merging LocalVariables of different size?!? From different methods or what?!?");
123 }
124
125 for (int i=0; i<locals.length; i++){
126 merge(lv, i);
127 }
128 }
129
130 /**
131 * Merges a single local variable.
132 *
133 * @see #merge(LocalVariables)
134 */
135 private void merge(LocalVariables lv, int i){
136 try {
137
138 // We won't accept an unitialized object if we know it was initialized;
139 // compare vmspec2, 4.9.4, last paragraph.
140 if ( (!(locals[i] instanceof UninitializedObjectType)) && (lv.locals[i] instanceof UninitializedObjectType) ){
141 throw new StructuralCodeConstraintException("Backwards branch with an uninitialized object in the local variables detected.");
142 }
143 // Even harder, what about _different_ uninitialized object types?!
144 if ( (!(locals[i].equals(lv.locals[i]))) && (locals[i] instanceof UninitializedObjectType) && (lv.locals[i] instanceof UninitializedObjectType) ){
145 throw new StructuralCodeConstraintException("Backwards branch with an uninitialized object in the local variables detected.");
146 }
147 // If we just didn't know that it was initialized, we have now learned.
148 if (locals[i] instanceof UninitializedObjectType){
149 if (! (lv.locals[i] instanceof UninitializedObjectType)){
150 locals[i] = ((UninitializedObjectType) locals[i]).getInitialized();
151 }
152 }
153 if ((locals[i] instanceof ReferenceType) && (lv.locals[i] instanceof ReferenceType)){
154 if (! locals[i].equals(lv.locals[i])){ // needed in case of two UninitializedObjectType instances
155 Type sup = ((ReferenceType) locals[i]).getFirstCommonSuperclass((ReferenceType) (lv.locals[i]));
156
157 if (sup != null){
158 locals[i] = sup;
159 }
160 else{
161 // We should have checked this in Pass2!
162 throw new AssertionViolatedException("Could not load all the super classes of '"+locals[i]+"' and '"+lv.locals[i]+"'.");
163 }
164 }
165 }
166 else{
167 if (! (locals[i].equals(lv.locals[i])) ){
168 /*TODO
169 if ((locals[i] instanceof org.apache.bcel.generic.ReturnaddressType) && (lv.locals[i] instanceof org.apache.bcel.generic.ReturnaddressType)){
170 //System.err.println("merging "+locals[i]+" and "+lv.locals[i]);
171 throw new AssertionViolatedException("Merging different ReturnAddresses: '"+locals[i]+"' and '"+lv.locals[i]+"'.");
172 }
173 */
174 locals[i] = Type.UNKNOWN;
175 }
176 }
177 } catch (ClassNotFoundException e) {
178 // FIXME: maybe not the best way to handle this
179 throw new AssertionViolatedException("Missing class: " + e.toString());
180 }
181 }
182
183 /**
184 * Returns a String representation of this object.
185 */
186 public String toString(){
187 StringBuffer sb = new StringBuffer();
188 for (int i=0; i<locals.length; i++){
189 sb.append(Integer.toString(i));
190 sb.append(": ");
191 sb.append(locals[i]);
192 sb.append("\n");
193 }
194 return sb.toString();
195 }
196
197 /**
198 * Replaces all occurences of u in this local variables set
199 * with an "initialized" ObjectType.
200 */
201 public void initializeObject(UninitializedObjectType u){
202 for (int i=0; i<locals.length; i++){
203 if (locals[i] == u){
204 locals[i] = u.getInitialized();
205 }
206 }
207 }
208 }
+0
-263
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/OperandStack.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import java.util.ArrayList;
20 import org.apache.bcel.generic.ObjectType;
21 import org.apache.bcel.generic.ReferenceType;
22 import org.apache.bcel.generic.Type;
23 import org.apache.bcel.verifier.exc.AssertionViolatedException;
24 import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
25
26 /**
27 * This class implements a stack used for symbolic JVM stack simulation.
28 * [It's used an an operand stack substitute.]
29 * Elements of this stack are org.apache.bcel.generic.Type objects.
30 *
31 * @version $Id: OperandStack.java 386056 2006-03-15 11:31:56Z tcurdt $
32 * @author Enver Haase
33 */
34 public class OperandStack{
35
36 /** We hold the stack information here. */
37 private ArrayList stack = new ArrayList();
38
39 /** The maximum number of stack slots this OperandStack instance may hold. */
40 private int maxStack;
41
42 /**
43 * Creates an empty stack with a maximum of maxStack slots.
44 */
45 public OperandStack(int maxStack){
46 this.maxStack = maxStack;
47 }
48
49 /**
50 * Creates an otherwise empty stack with a maximum of maxStack slots and
51 * the ObjectType 'obj' at the top.
52 */
53 public OperandStack(int maxStack, ObjectType obj){
54 this.maxStack = maxStack;
55 this.push(obj);
56 }
57 /**
58 * Returns a deep copy of this object; that means, the clone operates
59 * on a new stack. However, the Type objects on the stack are
60 * shared.
61 */
62 protected Object clone(){
63 OperandStack newstack = new OperandStack(this.maxStack);
64 newstack.stack = (ArrayList) this.stack.clone();
65 return newstack;
66 }
67
68 /**
69 * Clears the stack.
70 */
71 public void clear(){
72 stack = new ArrayList();
73 }
74
75 /** @return a hash code value for the object.
76 */
77 public int hashCode() { return stack.hashCode(); }
78
79 /**
80 * Returns true if and only if this OperandStack
81 * equals another, meaning equal lengths and equal
82 * objects on the stacks.
83 */
84 public boolean equals(Object o){
85 if (!(o instanceof OperandStack)) {
86 return false;
87 }
88 OperandStack s = (OperandStack) o;
89 return this.stack.equals(s.stack);
90 }
91
92 /**
93 * Returns a (typed!) clone of this.
94 *
95 * @see #clone()
96 */
97 public OperandStack getClone(){
98 return (OperandStack) this.clone();
99 }
100
101 /**
102 * Returns true IFF this OperandStack is empty.
103 */
104 public boolean isEmpty(){
105 return stack.isEmpty();
106 }
107
108 /**
109 * Returns the number of stack slots this stack can hold.
110 */
111 public int maxStack(){
112 return this.maxStack;
113 }
114
115 /**
116 * Returns the element on top of the stack. The element is not popped off the stack!
117 */
118 public Type peek(){
119 return peek(0);
120 }
121
122 /**
123 * Returns the element that's i elements below the top element; that means,
124 * iff i==0 the top element is returned. The element is not popped off the stack!
125 */
126 public Type peek(int i){
127 return (Type) stack.get(size()-i-1);
128 }
129
130 /**
131 * Returns the element on top of the stack. The element is popped off the stack.
132 */
133 public Type pop(){
134 Type e = (Type) stack.remove(size()-1);
135 return e;
136 }
137
138 /**
139 * Pops i elements off the stack. ALWAYS RETURNS "null"!!!
140 */
141 public Type pop(int i){
142 for (int j=0; j<i; j++){
143 pop();
144 }
145 return null;
146 }
147
148 /**
149 * Pushes a Type object onto the stack.
150 */
151 public void push(Type type){
152 if (type == null) {
153 throw new AssertionViolatedException("Cannot push NULL onto OperandStack.");
154 }
155 if (type == Type.BOOLEAN || type == Type.CHAR || type == Type.BYTE || type == Type.SHORT){
156 throw new AssertionViolatedException("The OperandStack does not know about '"+type+"'; use Type.INT instead.");
157 }
158 if (slotsUsed() >= maxStack){
159 throw new AssertionViolatedException("OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this);
160 }
161 stack.add(type);
162 }
163
164 /**
165 * Returns the size of this OperandStack; that means, how many Type objects there are.
166 */
167 public int size(){
168 return stack.size();
169 }
170
171 /**
172 * Returns the number of stack slots used.
173 * @see #maxStack()
174 */
175 public int slotsUsed(){
176 /* XXX change this to a better implementation using a variable
177 that keeps track of the actual slotsUsed()-value monitoring
178 all push()es and pop()s.
179 */
180 int slots = 0;
181 for (int i=0; i<stack.size(); i++){
182 slots += peek(i).getSize();
183 }
184 return slots;
185 }
186
187 /**
188 * Returns a String representation of this OperandStack instance.
189 */
190 public String toString(){
191 StringBuffer sb = new StringBuffer();
192 sb.append("Slots used: ");
193 sb.append(slotsUsed());
194 sb.append(" MaxStack: ");
195 sb.append(maxStack);
196 sb.append(".\n");
197 for (int i=0; i<size(); i++){
198 sb.append(peek(i));
199 sb.append(" (Size: ");
200 sb.append(String.valueOf(peek(i).getSize()));
201 sb.append(")\n");
202 }
203 return sb.toString();
204 }
205
206 /**
207 * Merges another stack state into this instance's stack state.
208 * See the Java Virtual Machine Specification, Second Edition, page 146: 4.9.2
209 * for details.
210 */
211 public void merge(OperandStack s){
212 try {
213 if ( (slotsUsed() != s.slotsUsed()) || (size() != s.size()) ) {
214 throw new StructuralCodeConstraintException("Cannot merge stacks of different size:\nOperandStack A:\n"+this+"\nOperandStack B:\n"+s);
215 }
216
217 for (int i=0; i<size(); i++){
218 // If the object _was_ initialized and we're supposed to merge
219 // in some uninitialized object, we reject the code (see vmspec2, 4.9.4, last paragraph).
220 if ( (! (stack.get(i) instanceof UninitializedObjectType)) && (s.stack.get(i) instanceof UninitializedObjectType) ){
221 throw new StructuralCodeConstraintException("Backwards branch with an uninitialized object on the stack detected.");
222 }
223 // Even harder, we're not initialized but are supposed to broaden
224 // the known object type
225 if ( (!(stack.get(i).equals(s.stack.get(i)))) && (stack.get(i) instanceof UninitializedObjectType) && (!(s.stack.get(i) instanceof UninitializedObjectType))){
226 throw new StructuralCodeConstraintException("Backwards branch with an uninitialized object on the stack detected.");
227 }
228 // on the other hand...
229 if (stack.get(i) instanceof UninitializedObjectType){ //if we have an uninitialized object here
230 if (! (s.stack.get(i) instanceof UninitializedObjectType)){ //that has been initialized by now
231 stack.set(i, ((UninitializedObjectType) (stack.get(i))).getInitialized() ); //note that.
232 }
233 }
234 if (! stack.get(i).equals(s.stack.get(i))){
235 if ( (stack.get(i) instanceof ReferenceType) &&
236 (s.stack.get(i) instanceof ReferenceType) ){
237 stack.set(i, ((ReferenceType) stack.get(i)).getFirstCommonSuperclass((ReferenceType) (s.stack.get(i))));
238 }
239 else{
240 throw new StructuralCodeConstraintException("Cannot merge stacks of different types:\nStack A:\n"+this+"\nStack B:\n"+s);
241 }
242 }
243 }
244 } catch (ClassNotFoundException e) {
245 // FIXME: maybe not the best way to handle this
246 throw new AssertionViolatedException("Missing class: " + e.toString());
247 }
248 }
249
250 /**
251 * Replaces all occurences of u in this OperandStack instance
252 * with an "initialized" ObjectType.
253 */
254 public void initializeObject(UninitializedObjectType u){
255 for (int i=0; i<stack.size(); i++){
256 if (stack.get(i) == u){
257 stack.set(i, u.getInitialized());
258 }
259 }
260 }
261
262 }
+0
-347
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Random;
24 import java.util.Vector;
25 import org.apache.bcel.Constants;
26 import org.apache.bcel.Repository;
27 import org.apache.bcel.classfile.JavaClass;
28 import org.apache.bcel.classfile.Method;
29 import org.apache.bcel.generic.ConstantPoolGen;
30 import org.apache.bcel.generic.InstructionHandle;
31 import org.apache.bcel.generic.JsrInstruction;
32 import org.apache.bcel.generic.MethodGen;
33 import org.apache.bcel.generic.ObjectType;
34 import org.apache.bcel.generic.RET;
35 import org.apache.bcel.generic.ReturnInstruction;
36 import org.apache.bcel.generic.ReturnaddressType;
37 import org.apache.bcel.generic.Type;
38 import org.apache.bcel.verifier.PassVerifier;
39 import org.apache.bcel.verifier.VerificationResult;
40 import org.apache.bcel.verifier.Verifier;
41 import org.apache.bcel.verifier.exc.AssertionViolatedException;
42 import org.apache.bcel.verifier.exc.VerifierConstraintViolatedException;
43
44 /**
45 * This PassVerifier verifies a method of class file according to pass 3,
46 * so-called structural verification as described in The Java Virtual Machine
47 * Specification, 2nd edition.
48 * More detailed information is to be found at the do_verify() method's
49 * documentation.
50 *
51 * @version $Id: Pass3bVerifier.java 384759 2006-03-10 10:38:59Z tcurdt $
52 * @author Enver Haase
53 * @see #do_verify()
54 */
55
56 public final class Pass3bVerifier extends PassVerifier{
57 /* TODO: Throughout pass 3b, upper halves of LONG and DOUBLE
58 are represented by Type.UNKNOWN. This should be changed
59 in favour of LONG_Upper and DOUBLE_Upper as in pass 2. */
60
61 /**
62 * An InstructionContextQueue is a utility class that holds
63 * (InstructionContext, ArrayList) pairs in a Queue data structure.
64 * This is used to hold information about InstructionContext objects
65 * externally --- i.e. that information is not saved inside the
66 * InstructionContext object itself. This is useful to save the
67 * execution path of the symbolic execution of the
68 * Pass3bVerifier - this is not information
69 * that belongs into the InstructionContext object itself.
70 * Only at "execute()"ing
71 * time, an InstructionContext object will get the current information
72 * we have about its symbolic execution predecessors.
73 */
74 private static final class InstructionContextQueue{
75 private List ics = new Vector(); // Type: InstructionContext
76 private List ecs = new Vector(); // Type: ArrayList (of InstructionContext)
77 public void add(InstructionContext ic, ArrayList executionChain){
78 ics.add(ic);
79 ecs.add(executionChain);
80 }
81 public boolean isEmpty(){
82 return ics.isEmpty();
83 }
84 public void remove(){
85 this.remove(0);
86 }
87 public void remove(int i){
88 ics.remove(i);
89 ecs.remove(i);
90 }
91 public InstructionContext getIC(int i){
92 return (InstructionContext) ics.get(i);
93 }
94 public ArrayList getEC(int i){
95 return (ArrayList) ecs.get(i);
96 }
97 public int size(){
98 return ics.size();
99 }
100 } // end Inner Class InstructionContextQueue
101
102 /** In DEBUG mode, the verification algorithm is not randomized. */
103 private static final boolean DEBUG = true;
104
105 /** The Verifier that created this. */
106 private Verifier myOwner;
107
108 /** The method number to verify. */
109 private int method_no;
110
111 /**
112 * This class should only be instantiated by a Verifier.
113 *
114 * @see org.apache.bcel.verifier.Verifier
115 */
116 public Pass3bVerifier(Verifier owner, int method_no){
117 myOwner = owner;
118 this.method_no = method_no;
119 }
120
121 /**
122 * Whenever the outgoing frame
123 * situation of an InstructionContext changes, all its successors are
124 * put [back] into the queue [as if they were unvisited].
125 * The proof of termination is about the existence of a
126 * fix point of frame merging.
127 */
128 private void circulationPump(ControlFlowGraph cfg, InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){
129 final Random random = new Random();
130 InstructionContextQueue icq = new InstructionContextQueue();
131
132 start.execute(vanillaFrame, new ArrayList(), icv, ev); // new ArrayList() <=> no Instruction was executed before
133 // => Top-Level routine (no jsr call before)
134 icq.add(start, new ArrayList());
135
136 // LOOP!
137 while (!icq.isEmpty()){
138 InstructionContext u;
139 ArrayList ec;
140 if (!DEBUG){
141 int r = random.nextInt(icq.size());
142 u = icq.getIC(r);
143 ec = icq.getEC(r);
144 icq.remove(r);
145 }
146 else{
147 u = icq.getIC(0);
148 ec = icq.getEC(0);
149 icq.remove(0);
150 }
151
152 ArrayList oldchain = (ArrayList) (ec.clone());
153 ArrayList newchain = (ArrayList) (ec.clone());
154 newchain.add(u);
155
156 if ((u.getInstruction().getInstruction()) instanceof RET){
157 //System.err.println(u);
158 // We can only follow _one_ successor, the one after the
159 // JSR that was recently executed.
160 RET ret = (RET) (u.getInstruction().getInstruction());
161 ReturnaddressType t = (ReturnaddressType) u.getOutFrame(oldchain).getLocals().get(ret.getIndex());
162 InstructionContext theSuccessor = cfg.contextOf(t.getTarget());
163
164 // Sanity check
165 InstructionContext lastJSR = null;
166 int skip_jsr = 0;
167 for (int ss=oldchain.size()-1; ss >= 0; ss--){
168 if (skip_jsr < 0){
169 throw new AssertionViolatedException("More RET than JSR in execution chain?!");
170 }
171 //System.err.println("+"+oldchain.get(ss));
172 if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof JsrInstruction){
173 if (skip_jsr == 0){
174 lastJSR = (InstructionContext) oldchain.get(ss);
175 break;
176 }
177 else{
178 skip_jsr--;
179 }
180 }
181 if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof RET){
182 skip_jsr++;
183 }
184 }
185 if (lastJSR == null){
186 throw new AssertionViolatedException("RET without a JSR before in ExecutionChain?! EC: '"+oldchain+"'.");
187 }
188 JsrInstruction jsr = (JsrInstruction) (lastJSR.getInstruction().getInstruction());
189 if ( theSuccessor != (cfg.contextOf(jsr.physicalSuccessor())) ){
190 throw new AssertionViolatedException("RET '"+u.getInstruction()+"' info inconsistent: jump back to '"+theSuccessor+"' or '"+cfg.contextOf(jsr.physicalSuccessor())+"'?");
191 }
192
193 if (theSuccessor.execute(u.getOutFrame(oldchain), newchain, icv, ev)){
194 icq.add(theSuccessor, (ArrayList) newchain.clone());
195 }
196 }
197 else{// "not a ret"
198
199 // Normal successors. Add them to the queue of successors.
200 InstructionContext[] succs = u.getSuccessors();
201 for (int s=0; s<succs.length; s++){
202 InstructionContext v = succs[s];
203 if (v.execute(u.getOutFrame(oldchain), newchain, icv, ev)){
204 icq.add(v, (ArrayList) newchain.clone());
205 }
206 }
207 }// end "not a ret"
208
209 // Exception Handlers. Add them to the queue of successors.
210 // [subroutines are never protected; mandated by JustIce]
211 ExceptionHandler[] exc_hds = u.getExceptionHandlers();
212 for (int s=0; s<exc_hds.length; s++){
213 InstructionContext v = cfg.contextOf(exc_hds[s].getHandlerStart());
214 // TODO: the "oldchain" and "newchain" is used to determine the subroutine
215 // we're in (by searching for the last JSR) by the InstructionContext
216 // implementation. Therefore, we should not use this chain mechanism
217 // when dealing with exception handlers.
218 // Example: a JSR with an exception handler as its successor does not
219 // mean we're in a subroutine if we go to the exception handler.
220 // We should address this problem later; by now we simply "cut" the chain
221 // by using an empty chain for the exception handlers.
222 //if (v.execute(new Frame(u.getOutFrame(oldchain).getLocals(), new OperandStack (u.getOutFrame().getStack().maxStack(), (exc_hds[s].getExceptionType()==null? Type.THROWABLE : exc_hds[s].getExceptionType())) ), newchain), icv, ev){
223 //icq.add(v, (ArrayList) newchain.clone());
224 if (v.execute(new Frame(u.getOutFrame(oldchain).getLocals(), new OperandStack (u.getOutFrame(oldchain).getStack().maxStack(), (exc_hds[s].getExceptionType()==null? Type.THROWABLE : exc_hds[s].getExceptionType())) ), new ArrayList(), icv, ev)){
225 icq.add(v, new ArrayList());
226 }
227 }
228
229 }// while (!icq.isEmpty()) END
230
231 InstructionHandle ih = start.getInstruction();
232 do{
233 if ((ih.getInstruction() instanceof ReturnInstruction) && (!(cfg.isDead(ih)))) {
234 InstructionContext ic = cfg.contextOf(ih);
235 Frame f = ic.getOutFrame(new ArrayList()); // TODO: This is buggy, we check only the top-level return instructions this way. Maybe some maniac returns from a method when in a subroutine?
236 LocalVariables lvs = f.getLocals();
237 for (int i=0; i<lvs.maxLocals(); i++){
238 if (lvs.get(i) instanceof UninitializedObjectType){
239 this.addMessage("Warning: ReturnInstruction '"+ic+"' may leave method with an uninitialized object in the local variables array '"+lvs+"'.");
240 }
241 }
242 OperandStack os = f.getStack();
243 for (int i=0; i<os.size(); i++){
244 if (os.peek(i) instanceof UninitializedObjectType){
245 this.addMessage("Warning: ReturnInstruction '"+ic+"' may leave method with an uninitialized object on the operand stack '"+os+"'.");
246 }
247 }
248 }
249 }while ((ih = ih.getNext()) != null);
250
251 }
252
253 /**
254 * Pass 3b implements the data flow analysis as described in the Java Virtual
255 * Machine Specification, Second Edition.
256 * Later versions will use LocalVariablesInfo objects to verify if the
257 * verifier-inferred types and the class file's debug information (LocalVariables
258 * attributes) match [TODO].
259 *
260 * @see org.apache.bcel.verifier.statics.LocalVariablesInfo
261 * @see org.apache.bcel.verifier.statics.Pass2Verifier#getLocalVariablesInfo(int)
262 */
263 public VerificationResult do_verify(){
264 if (! myOwner.doPass3a(method_no).equals(VerificationResult.VR_OK)){
265 return VerificationResult.VR_NOTYET;
266 }
267
268 // Pass 3a ran before, so it's safe to assume the JavaClass object is
269 // in the BCEL repository.
270 JavaClass jc;
271 try {
272 jc = Repository.lookupClass(myOwner.getClassName());
273 } catch (ClassNotFoundException e) {
274 // FIXME: maybe not the best way to handle this
275 throw new AssertionViolatedException("Missing class: " + e.toString());
276 }
277
278 ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());
279 // Init Visitors
280 InstConstraintVisitor icv = new InstConstraintVisitor();
281 icv.setConstantPoolGen(constantPoolGen);
282
283 ExecutionVisitor ev = new ExecutionVisitor();
284 ev.setConstantPoolGen(constantPoolGen);
285
286 Method[] methods = jc.getMethods(); // Method no "method_no" exists, we ran Pass3a before on it!
287
288 try{
289
290 MethodGen mg = new MethodGen(methods[method_no], myOwner.getClassName(), constantPoolGen);
291
292 icv.setMethodGen(mg);
293
294 ////////////// DFA BEGINS HERE ////////////////
295 if (! (mg.isAbstract() || mg.isNative()) ){ // IF mg HAS CODE (See pass 2)
296
297 ControlFlowGraph cfg = new ControlFlowGraph(mg);
298
299 // Build the initial frame situation for this method.
300 Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack());
301 if ( !mg.isStatic() ){
302 if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){
303 Frame._this = new UninitializedObjectType(ObjectType.getInstance(jc.getClassName()));
304 f.getLocals().set(0, Frame._this);
305 }
306 else{
307 Frame._this = null;
308 f.getLocals().set(0, ObjectType.getInstance(jc.getClassName()));
309 }
310 }
311 Type[] argtypes = mg.getArgumentTypes();
312 int twoslotoffset = 0;
313 for (int j=0; j<argtypes.length; j++){
314 if (argtypes[j] == Type.SHORT || argtypes[j] == Type.BYTE || argtypes[j] == Type.CHAR || argtypes[j] == Type.BOOLEAN){
315 argtypes[j] = Type.INT;
316 }
317 f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), argtypes[j]);
318 if (argtypes[j].getSize() == 2){
319 twoslotoffset++;
320 f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), Type.UNKNOWN);
321 }
322 }
323 circulationPump(cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
324 }
325 }
326 catch (VerifierConstraintViolatedException ce){
327 ce.extendMessage("Constraint violated in method '"+methods[method_no]+"':\n","");
328 return new VerificationResult(VerificationResult.VERIFIED_REJECTED, ce.getMessage());
329 }
330 catch (RuntimeException re){
331 // These are internal errors
332
333 StringWriter sw = new StringWriter();
334 PrintWriter pw = new PrintWriter(sw);
335 re.printStackTrace(pw);
336
337 throw new AssertionViolatedException("Some RuntimeException occured while verify()ing class '"+jc.getClassName()+"', method '"+methods[method_no]+"'. Original RuntimeException's stack trace:\n---\n"+sw+"---\n");
338 }
339 return VerificationResult.VR_OK;
340 }
341
342 /** Returns the method number as supplied when instantiating. */
343 public int getMethodNo(){
344 return method_no;
345 }
346 }
+0
-89
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/Subroutine.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.generic.InstructionHandle;
20
21 /**
22 * This interface defines properties of JVM bytecode subroutines.
23 * Note that it is 'abused' to maintain the top-level code in a
24 * consistent fashion, too.
25 *
26 * @version $Id: Subroutine.java 371539 2006-01-23 14:08:00Z tcurdt $
27 * @author Enver Haase
28 */
29 public interface Subroutine{
30 /**
31 * Returns all the JsrInstructions that have the
32 * first instruction of this subroutine as their target.
33 * <B>Must not be invoked on the 'top-level subroutine'.</B>
34 */
35 public InstructionHandle[] getEnteringJsrInstructions();
36
37 /**
38 * Returns the one and only RET that leaves the subroutine.
39 * Note that JustIce has a pretty rigid notion of a subroutine.
40 * <B>Must not be invoked on the 'top-level subroutine'.</B>
41 *
42 * @see org.apache.bcel.verifier.structurals.Subroutines
43 */
44 public InstructionHandle getLeavingRET();
45
46 /**
47 * Returns all instructions that together form this subroutine.
48 * Note that an instruction is part of exactly one subroutine
49 * (the top-level code is considered to be a special subroutine) -
50 * else it is not reachable at all (dead code).
51 */
52 public InstructionHandle[] getInstructions();
53
54 /**
55 * Returns if the given InstructionHandle refers to an instruction
56 * that is part of this subroutine. This is a convenience method
57 * that saves iteration over the InstructionHandle objects returned
58 * by getInstructions().
59 *
60 * @see #getInstructions()
61 */
62 public boolean contains(InstructionHandle inst);
63
64 /**
65 * Returns an int[] containing the indices of the local variable slots
66 * accessed by this Subroutine (read-accessed, write-accessed or both);
67 * local variables referenced by subroutines of this subroutine are
68 * not included.
69 *
70 * @see #getRecursivelyAccessedLocalsIndices()
71 */
72 public int[] getAccessedLocalsIndices();
73
74 /**
75 * Returns an int[] containing the indices of the local variable slots
76 * accessed by this Subroutine (read-accessed, write-accessed or both);
77 * local variables referenced by subroutines of this subroutine are
78 * included.
79 *
80 * @see #getAccessedLocalsIndices()
81 */
82 public int[] getRecursivelyAccessedLocalsIndices();
83
84 /**
85 * Returns the subroutines that are directly called from this subroutine.
86 */
87 public Subroutine[] subSubs();
88 }
+0
-651
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/Subroutines.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18 import java.util.ArrayList;
19 import java.util.HashSet;
20 import java.util.Hashtable;
21 import java.util.Iterator;
22 import java.util.Set;
23 import org.apache.bcel.generic.ASTORE;
24 import org.apache.bcel.generic.ATHROW;
25 import org.apache.bcel.generic.BranchInstruction;
26 import org.apache.bcel.generic.CodeExceptionGen;
27 import org.apache.bcel.generic.GotoInstruction;
28 import org.apache.bcel.generic.IndexedInstruction;
29 import org.apache.bcel.generic.Instruction;
30 import org.apache.bcel.generic.InstructionHandle;
31 import org.apache.bcel.generic.JsrInstruction;
32 import org.apache.bcel.generic.LocalVariableInstruction;
33 import org.apache.bcel.generic.MethodGen;
34 import org.apache.bcel.generic.RET;
35 import org.apache.bcel.generic.ReturnInstruction;
36 import org.apache.bcel.generic.Select;
37 import org.apache.bcel.verifier.exc.AssertionViolatedException;
38 import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
39
40 /**
41 * Instances of this class contain information about the subroutines
42 * found in a code array of a method.
43 * This implementation considers the top-level (the instructions
44 * reachable without a JSR or JSR_W starting off from the first
45 * instruction in a code array of a method) being a special subroutine;
46 * see getTopLevel() for that.
47 * Please note that the definition of subroutines in the Java Virtual
48 * Machine Specification, Second Edition is somewhat incomplete.
49 * Therefore, JustIce uses an own, more rigid notion.
50 * Basically, a subroutine is a piece of code that starts at the target
51 * of a JSR of JSR_W instruction and ends at a corresponding RET
52 * instruction. Note also that the control flow of a subroutine
53 * may be complex and non-linear; and that subroutines may be nested.
54 * JustIce also mandates subroutines not to be protected by exception
55 * handling code (for the sake of control flow predictability).
56 * To understand JustIce's notion of subroutines, please read
57 *
58 * TODO: refer to the paper.
59 *
60 * @version $Id: Subroutines.java 386056 2006-03-15 11:31:56Z tcurdt $
61 * @author Enver Haase
62 * @see #getTopLevel()
63 */
64 public class Subroutines{
65 /**
66 * This inner class implements the Subroutine interface.
67 */
68 private class SubroutineImpl implements Subroutine{
69 /**
70 * UNSET, a symbol for an uninitialized localVariable
71 * field. This is used for the "top-level" Subroutine;
72 * i.e. no subroutine.
73 */
74 private static final int UNSET = -1;
75
76 /**
77 * The Local Variable slot where the first
78 * instruction of this subroutine (an ASTORE) stores
79 * the JsrInstruction's ReturnAddress in and
80 * the RET of this subroutine operates on.
81 */
82 private int localVariable = UNSET;
83
84 /** The instructions that belong to this subroutine. */
85 private Set instructions = new HashSet(); // Elements: InstructionHandle
86
87 /*
88 * Refer to the Subroutine interface for documentation.
89 */
90 public boolean contains(InstructionHandle inst){
91 return instructions.contains(inst);
92 }
93
94 /**
95 * The JSR or JSR_W instructions that define this
96 * subroutine by targeting it.
97 */
98 private Set theJSRs = new HashSet();
99
100 /**
101 * The RET instruction that leaves this subroutine.
102 */
103 private InstructionHandle theRET;
104
105 /**
106 * Returns a String representation of this object, merely
107 * for debugging purposes.
108 * (Internal) Warning: Verbosity on a problematic subroutine may cause
109 * stack overflow errors due to recursive subSubs() calls.
110 * Don't use this, then.
111 */
112 public String toString(){
113 String ret = "Subroutine: Local variable is '"+localVariable+"', JSRs are '"+theJSRs+"', RET is '"+theRET+"', Instructions: '"+instructions.toString()+"'.";
114
115 ret += " Accessed local variable slots: '";
116 int[] alv = getAccessedLocalsIndices();
117 for (int i=0; i<alv.length; i++){
118 ret += alv[i]+" ";
119 }
120 ret+="'.";
121
122 ret += " Recursively (via subsub...routines) accessed local variable slots: '";
123 alv = getRecursivelyAccessedLocalsIndices();
124 for (int i=0; i<alv.length; i++){
125 ret += alv[i]+" ";
126 }
127 ret+="'.";
128
129 return ret;
130 }
131
132 /**
133 * Sets the leaving RET instruction. Must be invoked after all instructions are added.
134 * Must not be invoked for top-level 'subroutine'.
135 */
136 void setLeavingRET(){
137 if (localVariable == UNSET){
138 throw new AssertionViolatedException("setLeavingRET() called for top-level 'subroutine' or forgot to set local variable first.");
139 }
140 Iterator iter = instructions.iterator();
141 InstructionHandle ret = null;
142 while(iter.hasNext()){
143 InstructionHandle actual = (InstructionHandle) iter.next();
144 if (actual.getInstruction() instanceof RET){
145 if (ret != null){
146 throw new StructuralCodeConstraintException("Subroutine with more then one RET detected: '"+ret+"' and '"+actual+"'.");
147 }
148 else{
149 ret = actual;
150 }
151 }
152 }
153 if (ret == null){
154 throw new StructuralCodeConstraintException("Subroutine without a RET detected.");
155 }
156 if (((RET) ret.getInstruction()).getIndex() != localVariable){
157 throw new StructuralCodeConstraintException("Subroutine uses '"+ret+"' which does not match the correct local variable '"+localVariable+"'.");
158 }
159 theRET = ret;
160 }
161
162 /*
163 * Refer to the Subroutine interface for documentation.
164 */
165 public InstructionHandle[] getEnteringJsrInstructions(){
166 if (this == TOPLEVEL) {
167 throw new AssertionViolatedException("getLeavingRET() called on top level pseudo-subroutine.");
168 }
169 InstructionHandle[] jsrs = new InstructionHandle[theJSRs.size()];
170 return (InstructionHandle[]) (theJSRs.toArray(jsrs));
171 }
172
173 /**
174 * Adds a new JSR or JSR_W that has this subroutine as its target.
175 */
176 public void addEnteringJsrInstruction(InstructionHandle jsrInst){
177 if ( (jsrInst == null) || (! (jsrInst.getInstruction() instanceof JsrInstruction))){
178 throw new AssertionViolatedException("Expecting JsrInstruction InstructionHandle.");
179 }
180 if (localVariable == UNSET){
181 throw new AssertionViolatedException("Set the localVariable first!");
182 }
183 else{
184 // Something is wrong when an ASTORE is targeted that does not operate on the same local variable than the rest of the
185 // JsrInstruction-targets and the RET.
186 // (We don't know out leader here so we cannot check if we're really targeted!)
187 if (localVariable != ((ASTORE) (((JsrInstruction) jsrInst.getInstruction()).getTarget().getInstruction())).getIndex()){
188 throw new AssertionViolatedException("Setting a wrong JsrInstruction.");
189 }
190 }
191 theJSRs.add(jsrInst);
192 }
193
194 /*
195 * Refer to the Subroutine interface for documentation.
196 */
197 public InstructionHandle getLeavingRET(){
198 if (this == TOPLEVEL) {
199 throw new AssertionViolatedException("getLeavingRET() called on top level pseudo-subroutine.");
200 }
201 return theRET;
202 }
203
204 /*
205 * Refer to the Subroutine interface for documentation.
206 */
207 public InstructionHandle[] getInstructions(){
208 InstructionHandle[] ret = new InstructionHandle[instructions.size()];
209 return (InstructionHandle[]) instructions.toArray(ret);
210 }
211
212 /*
213 * Adds an instruction to this subroutine.
214 * All instructions must have been added before invoking setLeavingRET().
215 * @see #setLeavingRET
216 */
217 void addInstruction(InstructionHandle ih){
218 if (theRET != null){
219 throw new AssertionViolatedException("All instructions must have been added before invoking setLeavingRET().");
220 }
221 instructions.add(ih);
222 }
223
224 /* Satisfies Subroutine.getRecursivelyAccessedLocalsIndices(). */
225 public int[] getRecursivelyAccessedLocalsIndices(){
226 Set s = new HashSet();
227 int[] lvs = getAccessedLocalsIndices();
228 for (int j=0; j<lvs.length; j++){
229 s.add(new Integer(lvs[j]));
230 }
231 _getRecursivelyAccessedLocalsIndicesHelper(s, this.subSubs());
232 int[] ret = new int[s.size()];
233 Iterator i = s.iterator();
234 int j=-1;
235 while (i.hasNext()){
236 j++;
237 ret[j] = ((Integer) i.next()).intValue();
238 }
239 return ret;
240 }
241
242 /**
243 * A recursive helper method for getRecursivelyAccessedLocalsIndices().
244 * @see #getRecursivelyAccessedLocalsIndices()
245 */
246 private void _getRecursivelyAccessedLocalsIndicesHelper(Set s, Subroutine[] subs){
247 for (int i=0; i<subs.length; i++){
248 int[] lvs = subs[i].getAccessedLocalsIndices();
249 for (int j=0; j<lvs.length; j++){
250 s.add(new Integer(lvs[j]));
251 }
252 if(subs[i].subSubs().length != 0){
253 _getRecursivelyAccessedLocalsIndicesHelper(s, subs[i].subSubs());
254 }
255 }
256 }
257
258 /*
259 * Satisfies Subroutine.getAccessedLocalIndices().
260 */
261 public int[] getAccessedLocalsIndices(){
262 //TODO: Implement caching.
263 Set acc = new HashSet();
264 if (theRET == null && this != TOPLEVEL){
265 throw new AssertionViolatedException("This subroutine object must be built up completely before calculating accessed locals.");
266 }
267 Iterator i = instructions.iterator();
268 while (i.hasNext()){
269 InstructionHandle ih = (InstructionHandle) i.next();
270 // RET is not a LocalVariableInstruction in the current version of BCEL.
271 if (ih.getInstruction() instanceof LocalVariableInstruction || ih.getInstruction() instanceof RET){
272 int idx = ((IndexedInstruction) (ih.getInstruction())).getIndex();
273 acc.add(new Integer(idx));
274 // LONG? DOUBLE?.
275 try{
276 // LocalVariableInstruction instances are typed without the need to look into
277 // the constant pool.
278 if (ih.getInstruction() instanceof LocalVariableInstruction){
279 int s = ((LocalVariableInstruction) ih.getInstruction()).getType(null).getSize();
280 if (s==2) {
281 acc.add(new Integer(idx+1));
282 }
283 }
284 }
285 catch(RuntimeException re){
286 throw new AssertionViolatedException("Oops. BCEL did not like NULL as a ConstantPoolGen object.");
287 }
288 }
289 }
290
291 int[] ret = new int[acc.size()];
292 i = acc.iterator();
293 int j=-1;
294 while (i.hasNext()){
295 j++;
296 ret[j] = ((Integer) i.next()).intValue();
297 }
298 return ret;
299 }
300
301 /*
302 * Satisfies Subroutine.subSubs().
303 */
304 public Subroutine[] subSubs(){
305 Set h = new HashSet();
306
307 Iterator i = instructions.iterator();
308 while (i.hasNext()){
309 Instruction inst = ((InstructionHandle) i.next()).getInstruction();
310 if (inst instanceof JsrInstruction){
311 InstructionHandle targ = ((JsrInstruction) inst).getTarget();
312 h.add(getSubroutine(targ));
313 }
314 }
315 Subroutine[] ret = new Subroutine[h.size()];
316 return (Subroutine[]) h.toArray(ret);
317 }
318
319 /*
320 * Sets the local variable slot the ASTORE that is targeted
321 * by the JsrInstructions of this subroutine operates on.
322 * This subroutine's RET operates on that same local variable
323 * slot, of course.
324 */
325 void setLocalVariable(int i){
326 if (localVariable != UNSET){
327 throw new AssertionViolatedException("localVariable set twice.");
328 }
329 else{
330 localVariable = i;
331 }
332 }
333
334 /**
335 * The default constructor.
336 */
337 public SubroutineImpl(){
338 }
339
340 }// end Inner Class SubrouteImpl
341
342 //Node coloring constants
343 private static final Integer WHITE = new Integer(0);
344 private static final Integer GRAY = new Integer(1);
345 private static final Integer BLACK = new Integer(2);
346
347 /**
348 * The Hashtable containing the subroutines found.
349 * Key: InstructionHandle of the leader of the subroutine.
350 * Elements: SubroutineImpl objects.
351 */
352 private Hashtable subroutines = new Hashtable();
353
354 /**
355 * This is referring to a special subroutine, namely the
356 * top level. This is not really a subroutine but we use
357 * it to distinguish between top level instructions and
358 * unreachable instructions.
359 */
360 public final Subroutine TOPLEVEL;
361
362 /**
363 * Constructor.
364 * @param mg A MethodGen object representing method to
365 * create the Subroutine objects of.
366 */
367 public Subroutines(MethodGen mg){
368
369 InstructionHandle[] all = mg.getInstructionList().getInstructionHandles();
370 CodeExceptionGen[] handlers = mg.getExceptionHandlers();
371
372 // Define our "Toplevel" fake subroutine.
373 TOPLEVEL = new SubroutineImpl();
374
375 // Calculate "real" subroutines.
376 Set sub_leaders = new HashSet(); // Elements: InstructionHandle
377 for (int i=0; i<all.length; i++){
378 Instruction inst = all[i].getInstruction();
379 if (inst instanceof JsrInstruction){
380 sub_leaders.add(((JsrInstruction) inst).getTarget());
381 }
382 }
383
384 // Build up the database.
385 Iterator iter = sub_leaders.iterator();
386 while (iter.hasNext()){
387 SubroutineImpl sr = new SubroutineImpl();
388 InstructionHandle astore = (InstructionHandle) (iter.next());
389 sr.setLocalVariable( ((ASTORE) (astore.getInstruction())).getIndex() );
390 subroutines.put(astore, sr);
391 }
392
393 // Fake it a bit. We want a virtual "TopLevel" subroutine.
394 subroutines.put(all[0], TOPLEVEL);
395 sub_leaders.add(all[0]);
396
397 // Tell the subroutines about their JsrInstructions.
398 // Note that there cannot be a JSR targeting the top-level
399 // since "Jsr 0" is disallowed in Pass 3a.
400 // Instructions shared by a subroutine and the toplevel are
401 // disallowed and checked below, after the BFS.
402 for (int i=0; i<all.length; i++){
403 Instruction inst = all[i].getInstruction();
404 if (inst instanceof JsrInstruction){
405 InstructionHandle leader = ((JsrInstruction) inst).getTarget();
406 ((SubroutineImpl) getSubroutine(leader)).addEnteringJsrInstruction(all[i]);
407 }
408 }
409
410 // Now do a BFS from every subroutine leader to find all the
411 // instructions that belong to a subroutine.
412 Set instructions_assigned = new HashSet(); // we don't want to assign an instruction to two or more Subroutine objects.
413
414 Hashtable colors = new Hashtable(); //Graph colouring. Key: InstructionHandle, Value: Integer .
415
416 iter = sub_leaders.iterator();
417 while (iter.hasNext()){
418 // Do some BFS with "actual" as the root of the graph.
419 InstructionHandle actual = (InstructionHandle) (iter.next());
420 // Init colors
421 for (int i=0; i<all.length; i++){
422 colors.put(all[i], WHITE);
423 }
424 colors.put(actual, GRAY);
425 // Init Queue
426 ArrayList Q = new ArrayList();
427 Q.add(actual); // add(Obj) adds to the end, remove(0) removes from the start.
428
429 /* BFS ALGORITHM MODIFICATION: Start out with multiple "root" nodes, as exception handlers are starting points of top-level code, too. [why top-level? TODO: Refer to the special JustIce notion of subroutines.]*/
430 if (actual == all[0]){
431 for (int j=0; j<handlers.length; j++){
432 colors.put(handlers[j].getHandlerPC(), GRAY);
433 Q.add(handlers[j].getHandlerPC());
434 }
435 }
436 /* CONTINUE NORMAL BFS ALGORITHM */
437
438 // Loop until Queue is empty
439 while (Q.size() != 0){
440 InstructionHandle u = (InstructionHandle) Q.remove(0);
441 InstructionHandle[] successors = getSuccessors(u);
442 for (int i=0; i<successors.length; i++){
443 if (((Integer) colors.get(successors[i])) == WHITE){
444 colors.put(successors[i], GRAY);
445 Q.add(successors[i]);
446 }
447 }
448 colors.put(u, BLACK);
449 }
450 // BFS ended above.
451 for (int i=0; i<all.length; i++){
452 if (colors.get(all[i]) == BLACK){
453 ((SubroutineImpl) (actual==all[0]?getTopLevel():getSubroutine(actual))).addInstruction(all[i]);
454 if (instructions_assigned.contains(all[i])){
455 throw new StructuralCodeConstraintException("Instruction '"+all[i]+"' is part of more than one subroutine (or of the top level and a subroutine).");
456 }
457 else{
458 instructions_assigned.add(all[i]);
459 }
460 }
461 }
462 if (actual != all[0]){// If we don't deal with the top-level 'subroutine'
463 ((SubroutineImpl) getSubroutine(actual)).setLeavingRET();
464 }
465 }
466
467 // Now make sure no instruction of a Subroutine is protected by exception handling code
468 // as is mandated by JustIces notion of subroutines.
469 for (int i=0; i<handlers.length; i++){
470 InstructionHandle _protected = handlers[i].getStartPC();
471 while (_protected != handlers[i].getEndPC().getNext()){// Note the inclusive/inclusive notation of "generic API" exception handlers!
472 Iterator subs = subroutines.values().iterator();
473 while (subs.hasNext()){
474 Subroutine sub = (Subroutine) subs.next();
475 if (sub != subroutines.get(all[0])){ // We don't want to forbid top-level exception handlers.
476 if (sub.contains(_protected)){
477 throw new StructuralCodeConstraintException("Subroutine instruction '"+_protected+"' is protected by an exception handler, '"+handlers[i]+"'. This is forbidden by the JustIce verifier due to its clear definition of subroutines.");
478 }
479 }
480 }
481 _protected = _protected.getNext();
482 }
483 }
484
485 // Now make sure no subroutine is calling a subroutine
486 // that uses the same local variable for the RET as themselves
487 // (recursively).
488 // This includes that subroutines may not call themselves
489 // recursively, even not through intermediate calls to other
490 // subroutines.
491 noRecursiveCalls(getTopLevel(), new HashSet());
492
493 }
494
495 /**
496 * This (recursive) utility method makes sure that
497 * no subroutine is calling a subroutine
498 * that uses the same local variable for the RET as themselves
499 * (recursively).
500 * This includes that subroutines may not call themselves
501 * recursively, even not through intermediate calls to other
502 * subroutines.
503 *
504 * @throws StructuralCodeConstraintException if the above constraint is not satisfied.
505 */
506 private void noRecursiveCalls(Subroutine sub, Set set){
507 Subroutine[] subs = sub.subSubs();
508
509 for (int i=0; i<subs.length; i++){
510 int index = ((RET) (subs[i].getLeavingRET().getInstruction())).getIndex();
511
512 if (!set.add(new Integer(index))){
513 // Don't use toString() here because of possibly infinite recursive subSubs() calls then.
514 SubroutineImpl si = (SubroutineImpl) subs[i];
515 throw new StructuralCodeConstraintException("Subroutine with local variable '"+si.localVariable+"', JSRs '"+si.theJSRs+"', RET '"+si.theRET+"' is called by a subroutine which uses the same local variable index as itself; maybe even a recursive call? JustIce's clean definition of a subroutine forbids both.");
516 }
517
518 noRecursiveCalls(subs[i], set);
519
520 set.remove(new Integer(index));
521 }
522 }
523
524 /**
525 * Returns the Subroutine object associated with the given
526 * leader (that is, the first instruction of the subroutine).
527 * You must not use this to get the top-level instructions
528 * modeled as a Subroutine object.
529 *
530 * @see #getTopLevel()
531 */
532 public Subroutine getSubroutine(InstructionHandle leader){
533 Subroutine ret = (Subroutine) subroutines.get(leader);
534
535 if (ret == null){
536 throw new AssertionViolatedException("Subroutine requested for an InstructionHandle that is not a leader of a subroutine.");
537 }
538
539 if (ret == TOPLEVEL){
540 throw new AssertionViolatedException("TOPLEVEL special subroutine requested; use getTopLevel().");
541 }
542
543 return ret;
544 }
545
546 /**
547 * Returns the subroutine object associated with the
548 * given instruction. This is a costly operation, you
549 * should consider using getSubroutine(InstructionHandle).
550 * Returns 'null' if the given InstructionHandle lies
551 * in so-called 'dead code', i.e. code that can never
552 * be executed.
553 *
554 * @see #getSubroutine(InstructionHandle)
555 * @see #getTopLevel()
556 */
557 public Subroutine subroutineOf(InstructionHandle any){
558 Iterator i = subroutines.values().iterator();
559 while (i.hasNext()){
560 Subroutine s = (Subroutine) i.next();
561 if (s.contains(any)) {
562 return s;
563 }
564 }
565 System.err.println("DEBUG: Please verify '"+any+"' lies in dead code.");
566 return null;
567 //throw new AssertionViolatedException("No subroutine for InstructionHandle found (DEAD CODE?).");
568 }
569
570 /**
571 * For easy handling, the piece of code that is <B>not</B> a
572 * subroutine, the top-level, is also modeled as a Subroutine
573 * object.
574 * It is a special Subroutine object where <B>you must not invoke
575 * getEnteringJsrInstructions() or getLeavingRET()</B>.
576 *
577 * @see Subroutine#getEnteringJsrInstructions()
578 * @see Subroutine#getLeavingRET()
579 */
580 public Subroutine getTopLevel(){
581 return TOPLEVEL;
582 }
583 /**
584 * A utility method that calculates the successors of a given InstructionHandle
585 * <B>in the same subroutine</B>. That means, a RET does not have any successors
586 * as defined here. A JsrInstruction has its physical successor as its successor
587 * (opposed to its target) as defined here.
588 */
589 private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
590 final InstructionHandle[] empty = new InstructionHandle[0];
591 final InstructionHandle[] single = new InstructionHandle[1];
592 final InstructionHandle[] pair = new InstructionHandle[2];
593
594 Instruction inst = instruction.getInstruction();
595
596 if (inst instanceof RET){
597 return empty;
598 }
599
600 // Terminates method normally.
601 if (inst instanceof ReturnInstruction){
602 return empty;
603 }
604
605 // Terminates method abnormally, because JustIce mandates
606 // subroutines not to be protected by exception handlers.
607 if (inst instanceof ATHROW){
608 return empty;
609 }
610
611 // See method comment.
612 if (inst instanceof JsrInstruction){
613 single[0] = instruction.getNext();
614 return single;
615 }
616
617 if (inst instanceof GotoInstruction){
618 single[0] = ((GotoInstruction) inst).getTarget();
619 return single;
620 }
621
622 if (inst instanceof BranchInstruction){
623 if (inst instanceof Select){
624 // BCEL's getTargets() returns only the non-default targets,
625 // thanks to Eli Tilevich for reporting.
626 InstructionHandle[] matchTargets = ((Select) inst).getTargets();
627 InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
628 ret[0] = ((Select) inst).getTarget();
629 System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
630 return ret;
631 }
632 else{
633 pair[0] = instruction.getNext();
634 pair[1] = ((BranchInstruction) inst).getTarget();
635 return pair;
636 }
637 }
638
639 // default case: Fall through.
640 single[0] = instruction.getNext();
641 return single;
642 }
643
644 /**
645 * Returns a String representation of this object; merely for debugging puposes.
646 */
647 public String toString(){
648 return "---\n"+subroutines.toString()+"\n---\n";
649 }
650 }
+0
-67
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java less more
0 /*
1 * Copyright 2000-2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 package org.apache.bcel.verifier.structurals;
17
18
19 import org.apache.bcel.Constants;
20 import org.apache.bcel.generic.ObjectType;
21 import org.apache.bcel.generic.ReferenceType;
22
23 /**
24 * This class represents an uninitialized object type; see The Java
25 * Virtual Machine Specification, Second Edition, page 147: 4.9.4 for
26 * more details.
27 *
28 * @version $Id: UninitializedObjectType.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author Enver Haase
30 */
31 public class UninitializedObjectType extends ReferenceType implements Constants{
32
33 /** The "initialized" version. */
34 private ObjectType initialized;
35
36 /** Creates a new instance. */
37 public UninitializedObjectType(ObjectType t){
38 super(T_UNKNOWN, "<UNINITIALIZED OBJECT OF TYPE '"+t.getClassName()+"'>");
39 initialized = t;
40 }
41
42 /**
43 * Returns the ObjectType of the same class as the one of the uninitialized object
44 * represented by this UninitializedObjectType instance.
45 */
46 public ObjectType getInitialized(){
47 return initialized;
48 }
49
50 /** @return a hash code value for the object.
51 */
52 public int hashCode() { return initialized.hashCode(); }
53
54 /**
55 * Returns true on equality of this and o.
56 * Equality means the ObjectType instances of "initialized"
57 * equal one another in this and the o instance.
58 *
59 */
60 public boolean equals(Object o){
61 if (! (o instanceof UninitializedObjectType)) {
62 return false;
63 }
64 return initialized.equals(((UninitializedObjectType)o).initialized);
65 }
66 }
+0
-20
build/bcel-5.2-src/bcel-5.2/src/java/org/apache/bcel/verifier/structurals/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1 <html>
2 <head>
3 <!--
4 $Id: package.html 371539 2006-01-23 14:08:00Z tcurdt $
5 -->
6 </head>
7 <body bgcolor="white">
8
9 Provides a PassVerifier class mostly used internally by JustIce, yielding a control flow graph for public use as
10 a nice side effect.
11
12 <h2>Package Specification</h2>
13
14 Contained in this package is a PassVerifier class for use with the JustIce verifier and its utility classes.
15 Only the pass performing what Sun calls "Structural Constraints on Java Virtual Machine Code"
16 has a PassVerifier class here. JustIce calls this pass "Pass 3b".
17
18 </body>
19 </html>
+0
-27
debian/patches/0009-fix-build_xml-clean.patch less more
0 Index: findbugs-2.0.2/build.xml
1 ===================================================================
2 --- findbugs-2.0.2.orig/build.xml 2013-08-30 17:33:07.304100447 +0800
3 +++ findbugs-2.0.2/build.xml 2013-08-30 17:35:25.660786523 +0800
4 @@ -1213,7 +1213,9 @@
5 <!-- Delete generated files. -->
6 <target name="clean">
7 <delete dir="${scripts.dir}"/>
8 - <delete dir="${build.dir}"/>
9 + <delete>
10 + <fileset dir="${build.dir}" excludes="bcel-5.2-src/**"/>
11 + </delete>
12 <delete dir="${doc.dir}"/>
13 <delete dir="${web.dir}"/>
14 <delete dir="${apiDoc.dir}"/>
15 Index: findbugs-2.0.2/build/bcel-5.2-src/bcel-5.2/build.xml
16 ===================================================================
17 --- findbugs-2.0.2.orig/build/bcel-5.2-src/bcel-5.2/build.xml 2013-08-30 17:31:49.047712389 +0800
18 +++ findbugs-2.0.2/build/bcel-5.2-src/bcel-5.2/build.xml 2013-08-30 17:34:55.896638924 +0800
19 @@ -24,6 +24,7 @@
20 source="1.5"
21 target="jsr14"
22 deprecation="on"
23 + encoding="ISO-8859-1"
24 debug="on">
25 </javac>
26 </target>
+0
-29
debian/patches/bcel-package.diff less more
0 Index: findbugs/build.xml
1 ===================================================================
2 --- findbugs.orig/build.xml 2013-08-29 17:12:15.000000000 +0200
3 +++ findbugs/build.xml 2013-08-29 17:26:47.000000000 +0200
4 @@ -143,7 +143,7 @@
5
6 <!-- Compile Java source files, and copy other files (properties,
7 images, html, XSL stylesheets) that need to be part of the codebase. -->
8 - <target name="classes" depends="init">
9 + <target name="classes" depends="init, build-patchbcel">
10
11 <!-- Compile Java source files. -->
12 <echo level="info" message="compiling findbugs"/>
13 @@ -1288,12 +1288,14 @@
14 <target name="patchbcel">
15 <delete dir="${build.dir}/bcel-5.2-src"/>
16 <delete file="${build.dir}/bcel-5.2-src.zip"/>
17 - <get src="http://www.apache.org/dist/jakarta/bcel/source/bcel-5.2-src.zip"
18 + <get src="http://archive.apache.org/dist/jakarta/bcel/source/bcel-5.2-src.zip"
19 dest="${build.dir}/bcel-5.2-src.zip"
20 verbose="on"/>
21 <unzip src="${build.dir}/bcel-5.2-src.zip" dest="${build.dir}/bcel-5.2-src"/>
22 <delete file="${build.dir}/bcel-5.2-src/bcel-5.2/build.xml"/>
23 <patch patchfile="${patch.dir}/bcel.diff" dir="${build.dir}/bcel-5.2-src/bcel-5.2" strip="7"/>
24 + </target>
25 + <target name="build-patchbcel">
26 <ant dir="${build.dir}/bcel-5.2-src/bcel-5.2" inheritAll="false"/>
27 <copy file="${build.dir}/bcel-5.2-src/bcel-5.2/bcel.jar" tofile="${jar.dir}/bcel.jar"/>
28 </target>
55 0006-using-gtk-ui-settings.patch
66 0007-insert-in-script.patch
77 use-system-jar.patch
8 bcel-package.diff
98 0008-new-findbugs-help-options.patch
10 0009-fix-build_xml-clean.patch