[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[imp-commit] r22967 - in trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts: exceptions type

Author: jvinju
Date: 2012-01-21 08:22:09 -0500 (Sat, 21 Jan 2012)
New Revision: 22967

Removed:
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/exceptions/FactMatchException.java
Modified:
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AbstractDataType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AliasType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ConstructorType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ListType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/MapType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ParameterType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/SetType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/TupleType.java
   trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/Type.java
Log:
* changed match API to return a boolean instead of throwing an exception for performance reasons

Deleted: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/exceptions/FactMatchException.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/exceptions/FactMatchException.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/exceptions/FactMatchException.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -1,22 +0,0 @@
-package org.eclipse.imp.pdb.facts.exceptions;
-
-import org.eclipse.imp.pdb.facts.type.Type;
-
-public class FactMatchException extends FactTypeUseException {
-	private static final long serialVersionUID = 3043093533006947077L;
-
-	private Type subject;
-	private Type pattern;
-	
-	public FactMatchException(Type pattern, Type subject) {
-		super(subject + " does not match " + pattern);
-	}
-	
-	public Type getSubject() {
-		return subject;
-	}
-	
-	public Type getPattern() {
-		return pattern;
-	}
-}

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AbstractDataType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AbstractDataType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AbstractDataType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -16,7 +16,6 @@
 
 import org.eclipse.imp.pdb.facts.IValue;
 import org.eclipse.imp.pdb.facts.IValueFactory;
-import org.eclipse.imp.pdb.facts.exceptions.FactMatchException;
 import org.eclipse.imp.pdb.facts.exceptions.FactTypeUseException;
 import org.eclipse.imp.pdb.facts.exceptions.UndeclaredAnnotationException;
 import org.eclipse.imp.pdb.facts.exceptions.UndeclaredConstructorException;
@@ -246,10 +245,10 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		fParameters.match(matched.getTypeParameters(), bindings);
+		return super.match(matched, bindings) 
+				&& fParameters.match(matched.getTypeParameters(), bindings);
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AliasType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AliasType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/AliasType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -297,10 +297,10 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		fAliased.match(matched, bindings);
+		return super.match(matched, bindings)
+				&& fAliased.match(matched, bindings);
 	}
 
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ConstructorType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ConstructorType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ConstructorType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -254,11 +254,11 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		fADT.match(matched.getAbstractDataType(), bindings);
-		getFieldTypes().match(matched.getFieldTypes(), bindings);
+		return super.match(matched, bindings)
+				&& fADT.match(matched.getAbstractDataType(), bindings)
+				&& getFieldTypes().match(matched.getFieldTypes(), bindings);
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ListType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ListType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ListType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -101,10 +101,10 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		getElementType().match(matched.getElementType(), bindings);
+		return super.match(matched, bindings)
+				&& getElementType().match(matched.getElementType(), bindings);
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/MapType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/MapType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/MapType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -230,11 +230,11 @@
     }
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		getKeyType().match(matched.getKeyType(), bindings);
-		getValueType().match(matched.getValueType(), bindings);
+		return super.match(matched, bindings)
+				&& getKeyType().match(matched.getKeyType(), bindings)
+				&&getValueType().match(matched.getValueType(), bindings);
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ParameterType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ParameterType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/ParameterType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -13,7 +13,6 @@
 
 import java.util.Map;
 
-import org.eclipse.imp.pdb.facts.exceptions.FactMatchException;
 import org.eclipse.imp.pdb.facts.exceptions.FactTypeUseException;
 
 
@@ -180,15 +179,17 @@
 	}
 
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
+		if (!super.match(matched, bindings)) {
+			return false;
+		}
 		
 		Type earlier = bindings.get(this);
 		if (earlier != null) {
 			Type lub = earlier.lub(matched);
 			if (!lub.isSubtypeOf(getBound())) {
-				throw new FactMatchException(this, matched);
+				return false;
 			}
 			
 			bindings.put(this, lub);
@@ -196,6 +197,8 @@
 		else {
 			bindings.put(this, matched);
 		}
+		
+		return true;
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/SetType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/SetType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/SetType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -103,10 +103,10 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
-		getElementType().match(matched.getElementType(), bindings);
+		return super.match(matched, bindings)
+				&& getElementType().match(matched.getElementType(), bindings);
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/TupleType.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/TupleType.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/TupleType.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -358,13 +358,19 @@
 	}
 	
 	@Override
-	public void match(Type matched, Map<Type, Type> bindings)
+	public boolean match(Type matched, Map<Type, Type> bindings)
 			throws FactTypeUseException {
-		super.match(matched, bindings);
+		if (!super.match(matched, bindings)) {
+			return false;
+		}
 		
 		for (int i = getArity() - 1; i >= 0; i--) {
-			getFieldType(i).match(matched.getFieldType(i), bindings);
+			if (!getFieldType(i).match(matched.getFieldType(i), bindings)) {
+				return false;
+			}
 		}
+		
+		return true;
 	}
 	
 	@Override

Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/Type.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/Type.java	2012-01-13 10:04:06 UTC (rev 22966)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/type/Type.java	2012-01-21 13:22:09 UTC (rev 22967)
@@ -19,7 +19,6 @@
 import org.eclipse.imp.pdb.facts.IValue;
 import org.eclipse.imp.pdb.facts.IValueFactory;
 import org.eclipse.imp.pdb.facts.IWriter;
-import org.eclipse.imp.pdb.facts.exceptions.FactMatchException;
 import org.eclipse.imp.pdb.facts.exceptions.FactTypeUseException;
 import org.eclipse.imp.pdb.facts.exceptions.IllegalOperationException;
 
@@ -369,10 +368,8 @@
 	 *         or when a pattern simply can not be matched because of 
 	 *         incompatibility.         
 	 */
-	public void match(Type matched, Map<Type, Type> bindings) throws FactTypeUseException {
-		if (!matched.isSubtypeOf(this)) {
-			throw new FactMatchException(this, matched);
-		}
+	public boolean match(Type matched, Map<Type, Type> bindings) throws FactTypeUseException {
+		return matched.isSubtypeOf(this);
 	}
 	
 	public abstract <T> T accept(ITypeVisitor<T> visitor);