[kaffe] CVS kaffe-extras (guilhem): New patch to fix extra generated '<clinit>' methods. This method should
Kaffe CVS
cvs-commits at kaffe.org
Fri Dec 26 10:41:02 PST 2003
PatchSet 24
Date: 2003/12/26 18:40:31
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
New patch to fix extra generated '<clinit>' methods. This method should
not be generated if it is empty. But empty methods should be authorized ;-)
This is the least ugly method to do it I've found so far.
Members:
build.xml:1.13->1.14
patches/kjc-static-init.diff:INITIAL->1.1
Index: kaffe-extras/build.xml
diff -u kaffe-extras/build.xml:1.13 kaffe-extras/build.xml:1.14
--- kaffe-extras/build.xml:1.13 Tue Dec 23 14:57:47 2003
+++ kaffe-extras/build.xml Fri Dec 26 18:40:31 2003
@@ -260,6 +260,9 @@
<patch patchfile="${patches_dir}/kjc-parser-ClassnameDotThis.diff"
strip="1"
dir="${kjcsuite_dir}"/>
+ <patch patchfile="${patches_dir}/kjc-static-init.diff"
+ strip="1"
+ dir="${kjcsuite_dir}"/>
<touch file="${kjcsuite_unpacked_stamp}"/>
</target>
===================================================================
Checking out kaffe-extras/patches/kjc-static-init.diff
RCS: /home/cvs/kaffe/kaffe-extras/patches/kjc-static-init.diff,v
VERS: 1.1
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe-extras/patches/kjc-static-init.diff Fri Dec 26 18:40:33 2003
@@ -0,0 +1,182 @@
+diff -ur -x 'KjcScanner.*' -x 'KjcParser.*' kjc-suite-2.1B.old/src/kjc/CClass.java kjc-suite-2.1B/src/kjc/CClass.java
+--- kjc-suite-2.1B.old/src/kjc/CClass.java 2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B/src/kjc/CClass.java 2003-12-26 18:30:55.000000000 +0100
+@@ -1177,6 +1177,18 @@
+ }
+
+ /**
++ * Remove a method. To use with care.
++ */
++ public void removeMethod(CSourceMethod method) {
++ CMethod[] tmp = new CMethod[methods.length-1];
++ for (int i = 0, j = 0; i < methods.length; i++) {
++ if (methods[i] != method)
++ tmp[j++] = methods[i];
++ }
++ methods = tmp;
++ }
++
++ /**
+ * Adds a inner class.
+ */
+ public void addInnerClass(CReferenceType innerClass) {
+diff -ur -x 'KjcScanner.*' -x 'KjcParser.*' kjc-suite-2.1B.old/src/kjc/CSourceClass.java kjc-suite-2.1B/src/kjc/CSourceClass.java
+--- kjc-suite-2.1B.old/src/kjc/CSourceClass.java 2003-12-26 19:02:55.000000000 +0100
++++ kjc-suite-2.1B/src/kjc/CSourceClass.java 2003-12-26 19:00:38.000000000 +0100
+@@ -503,12 +503,30 @@
+ throws ClassFileFormatException
+ {
+ CMethod[] source = getMethods();
+- MethodInfo[] result;
++ MethodInfo[] tmp_result, result;
++ int real_methods = 0;
+
+- result = new MethodInfo[source.length];
++ tmp_result = new MethodInfo[source.length];
+ for (int i = 0; i < source.length; i++) {
+- result[i] = ((CSourceMethod)source[i]).genMethodInfo(optimizer, factory);
++ try {
++ tmp_result[i] = ((CSourceMethod)source[i]).genMethodInfo(optimizer, factory);
++ real_methods++;
++ }
++ catch (EmptyMethodException e) {
++ removeMethod((CSourceMethod)source[i]);
++ }
+ }
++
++ if (real_methods != source.length) {
++ result = new MethodInfo[real_methods];
++ for (int i = 0, j = 0; i < source.length; i++) {
++ if (tmp_result[i] != null)
++ result[j++] = tmp_result[i];
++ }
++ }
++ else
++ result = tmp_result;
++
+ return result;
+ }
+
+diff -ur -x 'KjcScanner.*' -x 'KjcParser.*' kjc-suite-2.1B.old/src/kjc/CSourceMethod.java kjc-suite-2.1B/src/kjc/CSourceMethod.java
+--- kjc-suite-2.1B.old/src/kjc/CSourceMethod.java 2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B/src/kjc/CSourceMethod.java 2003-12-26 19:06:05.000000000 +0100
+@@ -180,7 +180,9 @@
+ *
+ * @param optimizer the bytecode optimizer to use
+ */
+- public MethodInfo genMethodInfo(BytecodeOptimizer optimizer, TypeFactory factory) throws ClassFileFormatException {
++ public MethodInfo genMethodInfo(BytecodeOptimizer optimizer, TypeFactory factory)
++ throws ClassFileFormatException, EmptyMethodException {
++
+ CReferenceType[] excs = getThrowables();
+ String[] exceptions = new String[excs.length];
+
+@@ -188,12 +190,20 @@
+ exceptions[i] = excs[i].getQualifiedName();
+ }
+
++ CodeInfo code = null;
++ if (body != null) {
++ code = genCode(factory);
++
++ if (code == null)
++ throw new EmptyMethodException();
++ }
++
+ MethodInfo methodInfo = new MethodInfo((short)getModifiers(),
+ getIdent(),
+ getSignature(),
+ getGenericSignature(),
+ exceptions,
+- body != null ? genCode(factory): null,
++ code,
+ isDeprecated(),
+ isSynthetic());
+ methodInfo = optimizer.run(methodInfo);
+@@ -301,6 +311,9 @@
+ GenerationContext context = new GenerationContext(factory, code);
+
+ body.genCode(context);
++ if (code.size() == 0 && getIdent().equals(JAV_STATIC_INIT))
++ return null;
++
+ if (getReturnType().getTypeID() == TID_VOID) {
+ code.plantNoArgInstruction(opc_return);
+ }
+@@ -324,6 +337,8 @@
+
+ // generate byte code
+ info = genByteCode(factory);
++ if (info == null)
++ return null;
+
+ // set necessary additional information
+ for (int i = 0; i < parameters.length; i++) {
+diff -ur -x 'KjcScanner.*' -x 'KjcParser.*' kjc-suite-2.1B.old/src/kjc/JClassDeclaration.java kjc-suite-2.1B/src/kjc/JClassDeclaration.java
+--- kjc-suite-2.1B.old/src/kjc/JClassDeclaration.java 2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B/src/kjc/JClassDeclaration.java 2003-12-26 19:09:38.000000000 +0100
+@@ -674,7 +675,8 @@
+ * Collects all initializers and builds a single method.
+ * @param isStatic class or instance initializers ?
+ */
+- private JInitializerDeclaration constructInitializers(boolean isStatic, boolean always, TypeFactory factory) {
++ private JInitializerDeclaration constructInitializers(boolean isStatic,
++ boolean always, TypeFactory factory) throws PositionedError {
+ ArrayList elems = new ArrayList();
+ boolean needGen = false;
+
+@@ -684,10 +686,13 @@
+ elems.add(body[i]);
+ needGen = true;
+ } else {
+- if ((body[i] instanceof JFieldDeclaration)
+- && (((JFieldDeclaration)body[i]).getVariable().isStatic() == isStatic)) {
+- needGen |= ((JFieldDeclaration)body[i]).needInitialization();
+- elems.add(new JClassFieldDeclarator(getTokenReference(), (JFieldDeclaration)body[i]));
++ if (body[i] instanceof JFieldDeclaration) {
++ JFieldDeclaration fd = (JFieldDeclaration)body[i];
++
++ if (fd.getVariable().isStatic() == isStatic) {
++ needGen |= fd.needInitialization();
++ elems.add(new JClassFieldDeclarator(getTokenReference(), fd));
++ }
+ }
+ }
+ }
+diff -ur -x 'KjcScanner.*' -x 'KjcParser.*' kjc-suite-2.1B.old/src/kjc/Makefile kjc-suite-2.1B/src/kjc/Makefile
+--- kjc-suite-2.1B.old/src/kjc/Makefile 2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B/src/kjc/Makefile 2003-12-26 18:29:13.000000000 +0100
+@@ -33,7 +33,7 @@
+ SCANNER1 = Kjc
+
+ # Compiler classes
+-JAVAFILES += BytecodeOptimizer \
++JAVAFILES += BytecodeOptimizer EmptyMethodException \
+ CArrayType CBadClass \
+ CBinaryClass CBinaryField CBinaryMethod CBlockContext \
+ CBlockError CBodyContext CBooleanType \
+--- /dev/null 1970-01-01 01:00:00.000000000 +0100
++++ kjc-suite-2.1B/src/kjc/EmptyMethodException.java 2003-12-26 18:01:15.000000000 +0100
+@@ -0,0 +1,22 @@
++/*
++ * Copyright (C) 2003 Kaffe.org's developers
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
++ */
++package at.dms.kjc;
++
++public class EmptyMethodException extends Exception
++{
++}
More information about the kaffe
mailing list