[kaffe] CVS kaffe-extras (guilhem): Fix for KJC static initializers. This patch is temporary because it may trigger

Kaffe CVS cvs-commits at kaffe.org
Thu Jan 29 12:33:02 PST 2004


PatchSet 26 
Date: 2004/01/29 20:32:15
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fix for KJC static initializers. This patch is temporary because it may trigger
an infinite loop in the compiler for very special inter-dependent code. For
normal use, it should be safe. Some expressions may still have to be updated.

Members: 
	build.xml:1.15->1.16 
	patches/kjc-initializers.diff:INITIAL->1.1 

Index: kaffe-extras/build.xml
diff -u kaffe-extras/build.xml:1.15 kaffe-extras/build.xml:1.16
--- kaffe-extras/build.xml:1.15	Tue Jan  6 18:21:50 2004
+++ kaffe-extras/build.xml	Thu Jan 29 20:32:15 2004
@@ -260,6 +260,9 @@
 	<patch patchfile="${patches_dir}/kjc-static-init.diff"
 		strip="1"
 		dir="${kjcsuite_dir}"/>
+	<patch patchfile="${patches_dir}/kjc-initializers.diff"
+		strip="1"
+		dir="${kjcsuite_dir}"/>
 	<touch file="${kjcsuite_unpacked_stamp}"/>
   </target>
 
===================================================================
Checking out kaffe-extras/patches/kjc-initializers.diff
RCS:  /home/cvs/kaffe/kaffe-extras/patches/kjc-initializers.diff,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe-extras/patches/kjc-initializers.diff	Thu Jan 29 20:32:16 2004
@@ -0,0 +1,692 @@
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/CBinaryField.java kjc-suite-2.1B.new/src/kjc/CBinaryField.java
+--- kjc-suite-2.1B/src/kjc/CBinaryField.java	2002-07-15 20:53:31.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/CBinaryField.java	2004-01-28 21:26:17.000000000 +0100
+@@ -59,6 +59,7 @@
+ 	setValue(createLiteral(factory, getType(), value));
+       }
+     }
++    setAnalysed(true);
+   }
+ 
+   public void checkTypes(CBinaryTypeContext context) throws UnpositionedError {
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/CBodyContext.java kjc-suite-2.1B.new/src/kjc/CBodyContext.java
+--- kjc-suite-2.1B/src/kjc/CBodyContext.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/CBodyContext.java	2004-01-28 07:50:30.000000000 +0100
+@@ -55,6 +55,7 @@
+     flowState = parent.flowState;
+     variableInfo = new CVariableInfo(parent.getVariableInfo());
+     fieldInfo = new CVariableInfo(parent.getFieldInfo());
++    fieldExtInfo = new CVariableExtInfo(parent.getFieldExtInfo());
+     throwables = parent.throwables;
+   }
+ 
+@@ -71,6 +72,7 @@
+     flowState = 0;
+     variableInfo = new CVariableInfo(null);
+     fieldInfo = new CVariableInfo(parent.getFieldInfo());
++    fieldExtInfo = new CVariableExtInfo(null);
+     throwables = parent.getThrowables();
+   }
+ 
+@@ -86,6 +88,7 @@
+     variableInfo.createInfo();
+     fieldInfo = new CVariableInfo(source.getFieldInfo());
+     fieldInfo.createInfo();
++    fieldExtInfo = new CVariableExtInfo(source.getFieldExtInfo());
+     throwables = parent.throwables;
+   }
+ 
+@@ -436,6 +439,22 @@
+     return fieldInfo;
+   }
+ 
++  public int getFieldExtInfo(JFieldDeclaration field) {
++    return fieldExtInfo.getInfo(field);
++  }
++  
++  public CVariableExtInfo getFieldExtInfo() {
++    return fieldExtInfo;
++  }
++
++  public void setFieldExtInfo(JFieldDeclaration field, int info) {
++    fieldExtInfo.setInfo(field, info);
++  }
++
++  public void putFieldExtInfo(JFieldDeclaration field, int info) {
++    fieldExtInfo.putInfo(field, info);
++  }
++
+   // ----------------------------------------------------------------------
+   // THROWABLES
+   // ----------------------------------------------------------------------
+@@ -547,5 +566,7 @@
+   private int			flowState;
+   private final CVariableInfo	variableInfo;
+   private final CVariableInfo	fieldInfo;
++  private final CVariableExtInfo fieldExtInfo;
++  
+   private Hashtable		throwables;
+ }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/CTryContext.java kjc-suite-2.1B.new/src/kjc/CTryContext.java
+--- kjc-suite-2.1B/src/kjc/CTryContext.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/CTryContext.java	2004-01-28 20:49:14.000000000 +0100
+@@ -59,6 +59,13 @@
+   public void close(TokenReference ref) {
+   }
+ 
++  public void restoreThrowables(Hashtable throwables) {
++    Enumeration elts = throwables.elements();
++    
++    while (elts.hasMoreElements())
++      addThrowable((CThrowableInfo)elts.nextElement());
++  }
++
+   // ----------------------------------------------------------------------
+   // ACCESSORS
+   // ----------------------------------------------------------------------
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/CVariableExtInfo.java kjc-suite-2.1B.new/src/kjc/CVariableExtInfo.java
+--- kjc-suite-2.1B/src/kjc/CVariableExtInfo.java	1970-01-01 01:00:00.000000000 +0100
++++ kjc-suite-2.1B.new/src/kjc/CVariableExtInfo.java	2004-01-29 19:16:12.000000000 +0100
+@@ -0,0 +1,65 @@
++/*
++ * Copyright (C) 2004 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;
++
++import java.util.Hashtable;
++import java.util.Enumeration;
++
++public class CVariableExtInfo
++{
++	public CVariableExtInfo(CVariableExtInfo info)
++	{
++		if (info == null)
++		  infos = new Hashtable();
++		else {
++		  if (info.infos == null)
++		    info.infos = infos = new Hashtable();
++		  else
++		    infos = info.infos;
++		}
++	}
++
++	public final void setInfo(JFieldDeclaration field, int info)
++	{
++		infos.put(field, new Integer(EXIST | info));
++	}
++
++	public final int getInfo(JFieldDeclaration field)
++	{
++		Integer i = (Integer) infos.get(field);
++		
++		if (i == null)
++	          infos.put(field, i = new Integer(0));
++		return i.intValue();
++	}
++
++	public final void putInfo(JFieldDeclaration field, int info)
++	{
++		setInfo(field, getInfo(field) | info | EXIST);
++	}
++
++	public Enumeration enumerateFields()
++	{
++		return (infos != null) ? infos.keys() : null;
++	}
++
++	private Hashtable infos;
++
++	public static final int EXIST = 0x01;
++	public static final int ANALYSED = 0x02;
++}
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JAddExpression.java kjc-suite-2.1B.new/src/kjc/JAddExpression.java
+--- kjc-suite-2.1B/src/kjc/JAddExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JAddExpression.java	2004-01-29 19:02:51.000000000 +0100
+@@ -81,6 +81,8 @@
+ 
+     left = left.analyse(context);
+     right = right.analyse(context);
++    fully_analysed = left.isFullyAnalysed() && right.isFullyAnalysed();
++
+     check(context, left.getType(factory).getTypeID() != TID_VOID && right.getType(factory).getTypeID() != TID_VOID,
+ 	  KjcMessages.ADD_BADTYPE, left.getType(factory), right.getType(factory));
+ 
+@@ -93,13 +95,16 @@
+       throw e.addPosition(getTokenReference());
+     }
+ 
++    if (!fully_analysed)
++      return this;
++
+     CReferenceType  stringType = context.getTypeFactory().createReferenceType(TypeFactory.RFT_STRING);
+ 
+     // programming trick: no conversion for strings here: will be done in code generation
+     if (!type.equals(stringType)) {
+       left = left.convertType(context, type);
+       right = right.convertType(context, type);
+-   }
++    }
+ 
+     if (left.isConstant() && right.isConstant()) {
+       if (type.equals(stringType)) {
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JBinaryExpression.java kjc-suite-2.1B.new/src/kjc/JBinaryExpression.java
+--- kjc-suite-2.1B/src/kjc/JBinaryExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JBinaryExpression.java	2004-01-27 21:11:36.000000000 +0100
+@@ -46,6 +46,7 @@
+     super(where);
+     this.left = left;
+     this.right = right;
++    this.fully_analysed = false;
+   }
+ 
+   // ----------------------------------------------------------------------
+@@ -113,6 +114,11 @@
+     code.plantJumpInstruction(cond ? opc_ifne : opc_ifeq, label);
+   }
+ 
++  public boolean isFullyAnalysed() {
++//    return fully_analysed;
++	return left.isFullyAnalysed() && right.isFullyAnalysed(); 
++  }
++
+   // ----------------------------------------------------------------------
+   // DATA MEMBERS
+   // ----------------------------------------------------------------------
+@@ -120,4 +126,5 @@
+   protected	CType			type;
+   protected	JExpression		left;
+   protected	JExpression		right;
++  protected	boolean			fully_analysed;
+ }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JClassDeclaration.java kjc-suite-2.1B.new/src/kjc/JClassDeclaration.java
+--- kjc-suite-2.1B/src/kjc/JClassDeclaration.java	2004-01-29 19:10:43.000000000 +0100
++++ kjc-suite-2.1B.new/src/kjc/JClassDeclaration.java	2004-01-27 21:41:02.000000000 +0100
+@@ -378,7 +378,7 @@
+    * Check that initializers are correct
+    * @exception	PositionedError	an error with reference to the source file
+    */
+-  public void checkInitializers(CContext context) throws PositionedError {
++  public boolean checkInitializers(CContext context) throws PositionedError {
+     self = new CClassContext(context, context.getEnvironment(), sourceClass, this);
+ 
+     if (assertMethod != null) {
+@@ -386,21 +386,23 @@
+       assertMethod.checkBody1(self);
+     }
+ 
+-    compileStaticInitializer(self);
++    boolean good = true; 
++    good &= compileStaticInitializer(self);
+ 
+     // Check inners
+     for (int i = inners.length - 1; i >= 0 ; i--) {
+-      inners[i].checkInitializers(self);
++      good &= inners[i].checkInitializers(self);
+     }
+ 
+-    super.checkInitializers(context);
++    return good & super.checkInitializers(context);
+   }
+ 
+-  public void compileStaticInitializer(CClassContext context)
++  public boolean compileStaticInitializer(CClassContext context)
+     throws PositionedError
+   {
+     if (statInit != null) {
+-      statInit.checkInitializer(context);
++      if (!statInit.checkInitializer(context))
++	return false;
+ 
+       // check that all final class fields are initialized
+       CField[]	classFields = context.getCClass().getFields();
+@@ -421,6 +423,7 @@
+       // mark all static fields initialized
+       self.markAllFieldToInitialized(true);
+     }
++    return true;
+   }
+ 
+   /**
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JCompilationUnit.java kjc-suite-2.1B.new/src/kjc/JCompilationUnit.java
+--- kjc-suite-2.1B/src/kjc/JCompilationUnit.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JCompilationUnit.java	2004-01-27 21:01:23.000000000 +0100
+@@ -220,12 +220,14 @@
+    * @return	true iff sub tree is correct enought to check code
+    * @exception	PositionedError	an error with reference to the source file
+    */
+-  public void checkInitializers(Compiler compiler, Vector classes) throws PositionedError {
++  public boolean checkInitializers(Compiler compiler, Vector classes) throws PositionedError {
+     CCompilationUnitContext	context = new CCompilationUnitContext(compiler, environment, export, classes);
++    boolean good = true;
+ 
+     for (int i = 0; i < typeDeclarations.length ; i++) {
+-      typeDeclarations[i].checkInitializers(context);
++      good &= typeDeclarations[i].checkInitializers(context);
+     }
++    return good;
+   }
+ 
+   // ----------------------------------------------------------------------
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JDivideExpression.java kjc-suite-2.1B.new/src/kjc/JDivideExpression.java
+--- kjc-suite-2.1B/src/kjc/JDivideExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JDivideExpression.java	2004-01-25 19:43:29.000000000 +0100
+@@ -63,6 +63,7 @@
+ 
+     left = left.analyse(context);
+     right = right.analyse(context);
++    fully_analysed = left.isFullyAnalysed() && right.isFullyAnalysed();
+ 
+     try {
+       type = computeType(context, left.getType(factory), right.getType(factory));
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JExpression.java kjc-suite-2.1B.new/src/kjc/JExpression.java
+--- kjc-suite-2.1B/src/kjc/JExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JExpression.java	2004-01-25 19:39:20.000000000 +0100
+@@ -53,6 +53,14 @@
+   public abstract CType getType(TypeFactory factory);
+ 
+   /**
++   * Tests whether the expression is fully analysed or if they are any pending
++   * expressions to reanalyse.
++   */
++  public boolean isFullyAnalysed() {
++    return true;
++  }
++
++  /**
+    * Tests whether this expression denotes a compile-time constant (JLS 15.28).
+    *
+    * @return	true iff this expression is constant
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JFieldAccessExpression.java kjc-suite-2.1B.new/src/kjc/JFieldAccessExpression.java
+--- kjc-suite-2.1B/src/kjc/JFieldAccessExpression.java	2002-07-15 20:53:33.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JFieldAccessExpression.java	2004-01-29 19:03:06.000000000 +0100
+@@ -119,7 +119,6 @@
+     //   are constant expressions
+     // - Qualified names of the form TypeName . Identifier that refer to
+     //   final variables whose initializers are constant expressions
+-
+     return constantPrefix
+       && field.isFinal()
+       && field.getValue() != null
+@@ -184,6 +183,10 @@
+     return field;
+   }
+ 
++  public boolean isFullyAnalysed() {
++    return (!field.isFinal() || field.isAnalysed());
++  }
++
+   /**
+    * Returns the literal value of this field.
+    */
+@@ -206,6 +209,7 @@
+       buffer.append(field);
+     }
+     buffer.append("]");
++    buffer.append(" cprefix="+constantPrefix + " field.isFinal="+field.isFinal() + " field.value="+field.getValue());
+     return buffer.toString();
+   }
+ 
+@@ -275,6 +279,9 @@
+ 
+     type = field.getType();
+ 
++    if (!field.isAnalysed())
++      return this;
++
+     if (isConstant()) {
+       // FIX Type!!
+       return field.getValue();
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JFieldDeclaration.java kjc-suite-2.1B.new/src/kjc/JFieldDeclaration.java
+--- kjc-suite-2.1B/src/kjc/JFieldDeclaration.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JFieldDeclaration.java	2004-01-28 07:50:58.000000000 +0100
+@@ -178,6 +178,12 @@
+     TypeFactory factory = context.getTypeFactory();
+ 
+     variable.analyse(context);
++    if (!variable.isDefinitionAnalysed())
++    {
++      context.putFieldExtInfo(this, 0);
++      return;
++    }
++
+     // JLS 8.1.2 : Inner classes may inherit static members that 
+     // are not compile-time constants even though they may not declare 
+     // them. Inner classes may not declare static members, unless 
+@@ -211,6 +217,8 @@
+       }
+     }
+ 
++    context.putFieldExtInfo(this, CVariableExtInfo.ANALYSED);
++
+     if (hasInitializer()) {
+       context.setFieldInfo(((CSourceField)getField()).getPosition(), CVariableInfo.INITIALIZED);
+     }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JInitializerDeclaration.java kjc-suite-2.1B.new/src/kjc/JInitializerDeclaration.java
+--- kjc-suite-2.1B/src/kjc/JInitializerDeclaration.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JInitializerDeclaration.java	2004-01-28 17:49:16.000000000 +0100
+@@ -22,6 +22,7 @@
+ 
+ import at.dms.compiler.PositionedError;
+ import at.dms.compiler.TokenReference;
++import java.util.Enumeration;
+ 
+ /**
+  * This class represents a java class in the syntax tree
+@@ -106,7 +107,7 @@
+    * @param	context		the actual context of analyse
+    * @exception	PositionedError		Error catched as soon as possible
+    */
+-  public void checkInitializer(CClassContext context) throws PositionedError {
++  public boolean checkInitializer(CClassContext context) throws PositionedError {
+     if (getMethod().isStatic()) {
+       TokenReference    ref = TokenReference.NO_REF;
+       JBlock            classBlock = null;
+@@ -219,12 +220,23 @@
+       block.addThisVariable();
+     }
+     body.analyse(block);
+-      if (! block.isReachable()) {
+-	throw new CLineError(getTokenReference(), KjcMessages.STATEMENT_UNREACHABLE);
+-      }
++    boolean completelyInitialized = true;
++    Enumeration keys = block.getFieldExtInfo().enumerateFields(); 
++    while (keys.hasMoreElements()) {
++      JFieldDeclaration field = (JFieldDeclaration)keys.nextElement();
++      int info = block.getFieldExtInfo().getInfo(field);
++
++      if ((info & (CVariableExtInfo.EXIST|CVariableExtInfo.ANALYSED)) == CVariableExtInfo.EXIST)
++	completelyInitialized = false;
++    }
++    if (! block.isReachable()) {
++      throw new CLineError(getTokenReference(), KjcMessages.STATEMENT_UNREACHABLE);
++    }
+ 
+     block.close(getTokenReference());
+     self.close(getTokenReference());
++
++    return completelyInitialized;
+   }
+ 
+   // ----------------------------------------------------------------------
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JInterfaceDeclaration.java kjc-suite-2.1B.new/src/kjc/JInterfaceDeclaration.java
+--- kjc-suite-2.1B/src/kjc/JInterfaceDeclaration.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JInterfaceDeclaration.java	2004-01-27 21:11:27.000000000 +0100
+@@ -158,19 +158,20 @@
+    * Check that initializers are correct
+    * @exception	PositionedError	an error with reference to the source file
+    */
+-  public void checkInitializers(CContext context) throws PositionedError {
++  public boolean checkInitializers(CContext context) throws PositionedError {
+     //    CInterfaceContext self = new CInterfaceContext(context, context.getEnvironment(), sourceClass, this);
+     self = new CInterfaceContext(context, context.getEnvironment(), sourceClass, this);
++    boolean good = true; 
+     if (statInit != null) {
+-      statInit.checkInitializer(self);
++      good &= statInit.checkInitializer(self);
+     }
+ 
+     // Check inners
+     for (int i = inners.length - 1; i >= 0 ; i--) {
+-      inners[i].checkInitializers(self);
++      good &= inners[i].checkInitializers(self);
+     }
+ 
+-    super.checkInitializers(context);
++    return good & super.checkInitializers(context);
+   }
+ 
+   /**
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JMinusExpression.java kjc-suite-2.1B.new/src/kjc/JMinusExpression.java
+--- kjc-suite-2.1B/src/kjc/JMinusExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JMinusExpression.java	2004-01-25 19:42:30.000000000 +0100
+@@ -62,6 +62,7 @@
+ 
+     left = left.analyse(context);
+     right = right.analyse(context);
++    fully_analysed = left.isFullyAnalysed() && right.isFullyAnalysed();
+ 
+     try {
+       type = computeType(context, left.getType(factory), right.getType(factory));
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JMultExpression.java kjc-suite-2.1B.new/src/kjc/JMultExpression.java
+--- kjc-suite-2.1B/src/kjc/JMultExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JMultExpression.java	2004-01-25 19:43:00.000000000 +0100
+@@ -63,6 +63,7 @@
+ 
+     left = left.analyse(context);
+     right = right.analyse(context);
++    fully_analysed = left.isFullyAnalysed() && right.isFullyAnalysed();
+ 
+     try {
+       type = computeType(context, left.getType(factory), right.getType(factory));
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JReturnStatement.java kjc-suite-2.1B.new/src/kjc/JReturnStatement.java
+--- kjc-suite-2.1B/src/kjc/JReturnStatement.java	2002-07-15 20:53:33.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JReturnStatement.java	2004-01-27 20:34:05.000000000 +0100
+@@ -88,7 +88,8 @@
+       check(context,
+ 	    expr.isAssignableTo(expressionContext, returnType),
+ 	    KjcMessages.RETURN_BADTYPE, expr.getType(factory), returnType);
+-      expr = expr.convertType(expressionContext, returnType);
++      if (expr.isFullyAnalysed())
++        expr = expr.convertType(expressionContext, returnType);
+     } else {
+       check(context, returnType.getTypeID() == TID_VOID, KjcMessages.RETURN_EMPTY_NONVOID);
+     }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JTryCatchStatement.java kjc-suite-2.1B.new/src/kjc/JTryCatchStatement.java
+--- kjc-suite-2.1B/src/kjc/JTryCatchStatement.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JTryCatchStatement.java	2004-01-28 20:48:05.000000000 +0100
+@@ -21,6 +21,7 @@
+ package at.dms.kjc;
+ 
+ import java.util.Enumeration;
++import java.util.Hashtable;
+ 
+ import at.dms.compiler.PositionedError;
+ import at.dms.compiler.CWarning;
+@@ -84,6 +85,12 @@
+ 
+     tryContext = new CTryContext(context, context.getEnvironment());
+     tryClause.analyse(tryContext);
++    if (!analysed) {
++      saveThrowables = tryContext.getThrowables();
++      analysed = true;
++    } else {
++      tryContext.restoreThrowables(saveThrowables);
++    }
+     if (tryContext.isReachable()) {
+       self.merge(tryContext);
+       context.adopt(tryContext);
+@@ -262,4 +269,6 @@
+ 
+   private JBlock		tryClause;
+   private JCatchClause[]	catchClauses;
++  private Hashtable             saveThrowables;
++  private boolean               analysed;
+ }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JTypeDeclaration.java kjc-suite-2.1B.new/src/kjc/JTypeDeclaration.java
+--- kjc-suite-2.1B/src/kjc/JTypeDeclaration.java	2002-07-15 20:53:33.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JTypeDeclaration.java	2004-01-27 20:58:22.000000000 +0100
+@@ -340,7 +340,7 @@
+    *
+    * @exception	PositionedError	Error catched as soon as possible
+    */
+-  public void checkInitializers(CContext context) throws PositionedError {
++  public boolean checkInitializers(CContext context) throws PositionedError {
+     if (getCClass().getSuperClass() != null) {
+       check(context,
+             !getCClass().getSuperClass().dependsOn(getCClass()),
+@@ -376,6 +376,7 @@
+ 	}
+       }
+     }
++    return true;
+   }
+ 
+   // ----------------------------------------------------------------------
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JUnaryExpression.java kjc-suite-2.1B.new/src/kjc/JUnaryExpression.java
+--- kjc-suite-2.1B/src/kjc/JUnaryExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JUnaryExpression.java	2004-01-25 19:44:49.000000000 +0100
+@@ -53,6 +53,10 @@
+     return type;
+   }
+ 
++  public boolean isFullyAnalysed() {
++    return expr.isFullyAnalysed();
++  }
++
+   // ----------------------------------------------------------------------
+   // DATA MEMBERS
+   // ----------------------------------------------------------------------
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JUnaryMinusExpression.java kjc-suite-2.1B.new/src/kjc/JUnaryMinusExpression.java
+--- kjc-suite-2.1B/src/kjc/JUnaryMinusExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JUnaryMinusExpression.java	2004-01-25 20:10:41.000000000 +0100
+@@ -49,7 +49,8 @@
+   // ----------------------------------------------------------------------
+   // SEMANTIC ANALYSIS
+   // ----------------------------------------------------------------------
+-
++  //
++  
+   /**
+    * Analyses the expression (semantically).
+    * @param	context		the analysis context
+@@ -68,7 +69,8 @@
+       expr = expr.analyse(context);
+       check(context, expr.getType(factory).isNumeric(), KjcMessages.UNARY_BADTYPE_PM, expr.getType(factory));
+       type = CNumericType.unaryPromote(context, expr.getType(factory));
+-      expr = expr.convertType(context, type);
++      if (expr.isFullyAnalysed())
++        expr = expr.convertType(context, type);
+ 
+       if (expr.isConstant()) {
+ 	switch (type.getTypeID()) {
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JUnaryPlusExpression.java kjc-suite-2.1B.new/src/kjc/JUnaryPlusExpression.java
+--- kjc-suite-2.1B/src/kjc/JUnaryPlusExpression.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JUnaryPlusExpression.java	2004-01-25 20:10:35.000000000 +0100
+@@ -61,7 +61,8 @@
+     expr = expr.analyse(context);
+     check(context, expr.getType(factory).isNumeric(), KjcMessages.UNARY_BADTYPE_PM, expr.getType(factory));
+     type = CNumericType.unaryPromote(context, expr.getType(factory));
+-    expr = expr.convertType(context, type);
++    if (expr.isFullyAnalysed())
++      expr = expr.convertType(context, type);
+ 
+     return expr;
+   }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/JVariableDefinition.java kjc-suite-2.1B.new/src/kjc/JVariableDefinition.java
+--- kjc-suite-2.1B/src/kjc/JVariableDefinition.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/JVariableDefinition.java	2004-01-28 17:52:20.000000000 +0100
+@@ -142,8 +142,17 @@
+       check(context,
+ 	    expr.isAssignableTo(context, type),
+ 	    KjcMessages.VAR_INIT_BADTYPE, getIdent(), expr.getType(factory));
+-      expr = expr.convertType(expressionContext, type);
+-    }
++      analysed_definition = expr.isFullyAnalysed();
++
++      if (analysed_definition)
++	expr = expr.convertType(expressionContext, type);
++      
++    } else
++      analysed_definition = true;
++  }
++
++  public boolean isDefinitionAnalysed() {
++    return analysed_definition;
+   }
+ 
+   // ----------------------------------------------------------------------
+@@ -157,4 +166,6 @@
+   public void accept(KjcVisitor p) {
+     p.visitVariableDefinition(this, modifiers, type, getIdent(), expr);
+   }
++
++  protected boolean analysed_definition;
+ }
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/KjcScanner.java kjc-suite-2.1B.new/src/kjc/KjcScanner.java
+--- kjc-suite-2.1B/src/kjc/KjcScanner.java	2004-01-29 19:10:58.000000000 +0100
++++ kjc-suite-2.1B.new/src/kjc/KjcScanner.java	2004-01-28 20:56:26.000000000 +0100
+@@ -1,4 +1,4 @@
+-/* The following code was generated by JFlex 1.3.2 on 29-Jan-04 7:10:57 PM */
++/* The following code was generated by JFlex 1.3.2 on 28-Jan-04 8:56:25 PM */
+ 
+ /*
+  * Copyright (C) 1990-2001 DMS Decision Management Systems Ges.m.b.H.
+@@ -37,7 +37,7 @@
+ /**
+  * This class is a scanner generated by 
+  * <a href="http://www.jflex.de/">JFlex</a> 1.3.2
+- * on 29-Jan-04 7:10:57 PM from the specification file
++ * on 28-Jan-04 8:56:25 PM from the specification file
+  * <tt>file:/mnt/external2/guilhem_ext2/PROJECTS/kaffe-extras/build/kjc-suite-2.1B/src/kjc/Kjc.flex</tt>
+  */
+ public class KjcScanner extends at.dms.compiler.tools.antlr.extra.Scanner implements KjcTokenTypes {
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/Main.java kjc-suite-2.1B.new/src/kjc/Main.java
+--- kjc-suite-2.1B/src/kjc/Main.java	2002-07-15 20:53:32.000000000 +0200
++++ kjc-suite-2.1B.new/src/kjc/Main.java	2004-01-27 21:08:46.000000000 +0100
+@@ -171,13 +171,18 @@
+ 	return false;
+       }
+ 
+-      for (int count = 0; count < tree.length; count++) {
+-	checkInitializers(tree[count]);
+-      }
++      boolean good;
+ 
+-      if (errorFound) {
+-	return false;
+-      }
++      do {
++	good = true;
++        for (int count = 0; count < tree.length; count++) {
++ 	  good &= checkInitializers(tree[count]);
++        }
++
++        if (errorFound) {
++	  return false;
++        }
++      } while (!good);
+ 
+       for (int count = 0; count < tree.length; count++) {
+         checkBody(tree[count]);
+@@ -389,11 +394,12 @@
+    * side effect: increment error number
+    * @param	cunit		the compilation unit
+    */
+-  protected void checkInitializers(JCompilationUnit cunit) {
++  protected boolean checkInitializers(JCompilationUnit cunit) {
+     try {
+-      cunit.checkInitializers(this, classes);
++      return cunit.checkInitializers(this, classes);
+     } catch (PositionedError e) {
+       reportTrouble(e);
++      return false;
+     }
+   }
+ 
+diff -N -x Kjc.java -x '*~' -ur kjc-suite-2.1B/src/kjc/Makefile kjc-suite-2.1B.new/src/kjc/Makefile
+--- kjc-suite-2.1B/src/kjc/Makefile	2004-01-29 19:10:43.000000000 +0100
++++ kjc-suite-2.1B.new/src/kjc/Makefile	2004-01-27 21:03:26.000000000 +0100
+@@ -54,7 +54,8 @@
+ 		CSourceMethod CStdType					\
+ 		CSwitchBodyContext CSwitchGroupContext			\
+ 		CThrowableInfo CTryContext				\
+-		CTryFinallyContext CType CVariableInfo CVoidType	\
++		CTryFinallyContext CType CVariableInfo CVariableExtInfo \
++		CVoidType	\
+ 		CodeLabel CodeSequence Constants			\
+ 		DefaultFilter JCheckedExpression KjcPrettyPrinter	\
+ 		KjcScanner KjcVisitor Main				\




More information about the kaffe mailing list