Skip to content

Commit bdbf83f

Browse files
author
dlsmith
committed
DynamicJava: Updated plt.jar, which fixes a bug in recognizing inner class names; improved error messages for unrecognized names
git-svn-id: file:///tmp/test-svn/trunk@4393 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent a0233fe commit bdbf83f

File tree

6 files changed

+93
-58
lines changed

6 files changed

+93
-58
lines changed

dynamicjava/lib/plt.jar

3.81 KB
Binary file not shown.

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/ExpressionChecker.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ else if (context.fieldExists(first.image(), ts)) {
247247
catch (AmbiguousNameException e) { throw new ExecutionError("ambiguous.name", node); }
248248
catch (InvalidTargetException e) { throw new RuntimeException("context produced bad type"); }
249249
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument.arity", node); }
250-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
250+
catch (UnmatchedLookupException e) {
251+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
252+
else { throw new ExecutionError("ambiguous.name", node); }
253+
}
251254

252255
// Append member names until a field is encountered (or until all names are used up)
253256
while (ids.hasNext() && resultExp == null) {
@@ -269,7 +272,10 @@ else if (ts.containsClass(classType, memberName.image())) {
269272
}
270273
catch (InvalidTargetException e) { throw new RuntimeException("ts.containsClass lied"); }
271274
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument.arity", node); }
272-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
275+
catch (UnmatchedLookupException e) {
276+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
277+
else { throw new ExecutionError("ambiguous.name", node); }
278+
}
273279
// TODO: Improve error when memberName is a non-static class
274280
}
275281
else {
@@ -373,7 +379,10 @@ else if (ts.containsClass(classType, memberName.image())) {
373379
}
374380
catch (AmbiguousNameException e) { throw new ExecutionError("ambiguous.name", node); }
375381
catch (InvalidTargetException e) { throw new RuntimeException("context produced bad type"); }
376-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
382+
catch (UnmatchedLookupException e) {
383+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
384+
else { throw new ExecutionError("ambiguous.name", node); }
385+
}
377386
}
378387

379388
/**
@@ -1653,14 +1662,20 @@ private Type handleIncrementExpression(UnaryExpression node) {
16531662
catch (AmbiguousNameException e) { throw new ExecutionError("ambiguous.name", node); }
16541663
catch (InvalidTargetException e) { throw new RuntimeException("context produced bad type"); }
16551664
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument.arity", node); }
1656-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
1665+
catch (UnmatchedLookupException e) {
1666+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
1667+
else { throw new ExecutionError("ambiguous.name", node); }
1668+
}
16571669
}
16581670

16591671
while (ids.hasNext()) {
16601672
try { t = ts.lookupClass(t, ids.next().image(), IterUtil.<Type>empty()); }
16611673
catch (InvalidTargetException e) { throw new RuntimeException("lookup produced bad type"); }
16621674
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument.arity", node); }
1663-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
1675+
catch (UnmatchedLookupException e) {
1676+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
1677+
else { throw new ExecutionError("ambiguous.name", node); }
1678+
}
16641679
}
16651680

16661681
if (t == null) {
@@ -1706,7 +1721,10 @@ private Type handleIncrementExpression(UnaryExpression node) {
17061721
catch (AmbiguousNameException e) { throw new ExecutionError("ambiguous.name", node); }
17071722
catch (InvalidTargetException e) { throw new RuntimeException("context produced bad type"); }
17081723
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument", node); }
1709-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
1724+
catch (UnmatchedLookupException e) {
1725+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
1726+
else { throw new ExecutionError("ambiguous.name", node); }
1727+
}
17101728
}
17111729

17121730
while (ids.hasNext()) {
@@ -1716,7 +1734,10 @@ private Type handleIncrementExpression(UnaryExpression node) {
17161734
}
17171735
catch (InvalidTargetException e) { throw new RuntimeException("lookup produced bad type"); }
17181736
catch (InvalidTypeArgumentException e) { throw new ExecutionError("type.argument", node); }
1719-
catch (UnmatchedLookupException e) { throw new ExecutionError("ambiguous.name", node); }
1737+
catch (UnmatchedLookupException e) {
1738+
if (e.matches() == 0) { throw new ExecutionError("undefined.name.noinfo", node); }
1739+
else { throw new ExecutionError("ambiguous.name", node); }
1740+
}
17201741
}
17211742

17221743
if (t == null) {

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/TreeClassLoader.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import edu.rice.cs.dynamicjava.symbol.TreeClass;
77
import edu.rice.cs.plt.reflect.ShadowingClassLoader;
88
import edu.rice.cs.plt.reflect.ComposedClassLoader;
9+
import edu.rice.cs.plt.iter.IterUtil;
910

1011
/**
1112
* A class loader with the additional ability of loading classes from their (type-checked)
@@ -26,14 +27,18 @@ private static ClassLoader makeParent(ClassLoader p) {
2627
// Classes that must be loaded by the implementation's class loader
2728
// (the compiled tree classes need to be able to refer to these classes
2829
// and be talking about the ones that are loaded in the implementation code):
30+
Iterable<String> includes =
31+
IterUtil.make(Object.class.getName(),
32+
String.class.getName(),
33+
RuntimeBindings.class.getName(),
34+
TreeClassLoader.class.getName(),
35+
TreeCompiler.EvaluationAdapter.class.getName(),
36+
TreeCompiler.BindingsFactory.class.getName());
37+
// For maximum flexibility, we let p load bootstrap classes
38+
// (except those listed above)
2939
ClassLoader implementationLoader =
3040
new ShadowingClassLoader(TreeClassLoader.class.getClassLoader(), false,
31-
Object.class.getName(),
32-
String.class.getName(),
33-
RuntimeBindings.class.getName(),
34-
TreeClassLoader.class.getName(),
35-
TreeCompiler.EvaluationAdapter.class.getName(),
36-
TreeCompiler.BindingsFactory.class.getName());
41+
includes, true);
3742
return new ComposedClassLoader(implementationLoader, p);
3843
}
3944

dynamicjava/src/edu/rice/cs/dynamicjava/symbol/ExtendedTypeSystem.java

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,6 @@ public ConstraintSet defaultCase(Type paramArg) {
19841984
// Note that this might be a capture variable with an inference-variable bound
19851985
if (vars.contains(param)) { return EMPTY_CONSTRAINTS.andLowerBound(param, arg); }
19861986
else {
1987-
debug.log();
19881987
Thunk<ConstraintSet> recurOnLowerBound = new Thunk<ConstraintSet>() {
19891988
public ConstraintSet value() {
19901989
return arg.apply(new TypeAbstractVisitor<ConstraintSet>() {
@@ -2891,9 +2890,9 @@ public ConstructorInvocation value(DJConstructor k, SignatureChecker checker) {
28912890
});
28922891

28932892
// TODO: provide more error-message information
2894-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
2895-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
2896-
else { return results.iterator().next(); }
2893+
int matches = IterUtil.sizeOf(results);
2894+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
2895+
else { return IterUtil.first(results); }
28972896
}
28982897

28992898
public boolean containsMethod(Type t, String name) {
@@ -3049,9 +3048,9 @@ public ObjectMethodInvocation value(DJMethod m, SignatureChecker checker) {
30493048
new LookupMethod(true),
30503049
new LookupMethod(false));
30513050
// TODO: provide more error-message information
3052-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
3053-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
3054-
else { return results.iterator().next(); }
3051+
int matches = IterUtil.sizeOf(results);
3052+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
3053+
else { return IterUtil.first(results); }
30553054
}
30563055

30573056
/**
@@ -3169,9 +3168,9 @@ public StaticMethodInvocation value(DJMethod m, SignatureChecker checker) {
31693168
Iterable<? extends StaticMethodInvocation> results = lookupMember(t, new LookupMethod(true),
31703169
new LookupMethod(false));
31713170
// TODO: provide more error-message information
3172-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
3173-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
3174-
else { return results.iterator().next(); }
3171+
int matches = IterUtil.sizeOf(results);
3172+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
3173+
else { return IterUtil.first(results); }
31753174
}
31763175

31773176

@@ -3276,9 +3275,9 @@ private boolean validField(DJField f) {
32763275
new LookupField(true),
32773276
new LookupField(false));
32783277
// TODO: provide more error-message information
3279-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
3280-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
3281-
else { return results.iterator().next(); }
3278+
int matches = IterUtil.sizeOf(results);
3279+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
3280+
else { return IterUtil.first(results); }
32823281
}
32833282

32843283

@@ -3342,9 +3341,9 @@ private boolean validField(DJField f) {
33423341
Iterable<? extends StaticFieldReference> results = lookupMember(t, new LookupField(true),
33433342
new LookupField(false));
33443343
// TODO: provide more error-message information
3345-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
3346-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
3347-
else { return results.iterator().next(); }
3344+
int matches = IterUtil.sizeOf(results);
3345+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
3346+
else { return IterUtil.first(results); }
33483347
}
33493348

33503349

@@ -3415,20 +3414,23 @@ public ClassType lookupClass(Expression object, String name, Iterable<? extends
34153414
*/
34163415
public ClassType lookupClass(Type t, final String name, Iterable<? extends Type> typeArgs)
34173416
throws InvalidTargetException, InvalidTypeArgumentException, UnmatchedLookupException {
3418-
// System.out.println("\nLooking up class " + name + " in type " + userRepresentation(t));
3419-
Lambda<Boolean, Predicate<DJClass>> makePred = new Lambda<Boolean, Predicate<DJClass>>() {
3420-
public Predicate<DJClass> value(final Boolean includePrivate) {
3421-
return new Predicate<DJClass>() {
3422-
public Boolean value(DJClass c) {
3423-
if (c.declaredName().equals(name)) {
3424-
return includePrivate || !c.accessibility().equals(Access.PRIVATE);
3417+
debug.logStart(new String[]{"t", "name", "typeArgs"}, t, name, typeArgs);
3418+
try {
3419+
Lambda<Boolean, Predicate<DJClass>> makePred = new Lambda<Boolean, Predicate<DJClass>>() {
3420+
public Predicate<DJClass> value(final Boolean includePrivate) {
3421+
return new Predicate<DJClass>() {
3422+
public Boolean value(DJClass c) {
3423+
if (c.declaredName().equals(name)) {
3424+
return includePrivate || !c.accessibility().equals(Access.PRIVATE);
3425+
}
3426+
else { return false; }
34253427
}
3426-
else { return false; }
3427-
}
3428-
};
3429-
}
3430-
};
3431-
return lookupClass(t, makePred, typeArgs, name);
3428+
};
3429+
}
3430+
};
3431+
return lookupClass(t, makePred, typeArgs, name);
3432+
}
3433+
finally { debug.logEnd(); }
34323434
}
34333435

34343436
/**
@@ -3444,20 +3446,24 @@ public Boolean value(DJClass c) {
34443446
*/
34453447
public ClassType lookupStaticClass(Type t, final String name, final Iterable<? extends Type> typeArgs)
34463448
throws InvalidTargetException, InvalidTypeArgumentException, UnmatchedLookupException {
3447-
Lambda<Boolean, Predicate<DJClass>> makePred = new Lambda<Boolean, Predicate<DJClass>>() {
3448-
public Predicate<DJClass> value(final Boolean includePrivate) {
3449-
return new Predicate<DJClass>() {
3450-
public Boolean value(DJClass c) {
3451-
if (c.declaredName().equals(name)) {
3452-
if (includePrivate) { return c.isStatic(); }
3453-
else { return c.isStatic() && !c.accessibility().equals(Access.PRIVATE); }
3449+
debug.logStart(new String[]{"t", "name", "typeArgs"}, t, name, typeArgs);
3450+
try {
3451+
Lambda<Boolean, Predicate<DJClass>> makePred = new Lambda<Boolean, Predicate<DJClass>>() {
3452+
public Predicate<DJClass> value(final Boolean includePrivate) {
3453+
return new Predicate<DJClass>() {
3454+
public Boolean value(DJClass c) {
3455+
if (c.declaredName().equals(name)) {
3456+
if (includePrivate) { return c.isStatic(); }
3457+
else { return c.isStatic() && !c.accessibility().equals(Access.PRIVATE); }
3458+
}
3459+
else { return false; }
34543460
}
3455-
else { return false; }
3456-
}
3457-
};
3458-
}
3459-
};
3460-
return lookupClass(t, makePred, typeArgs, name);
3461+
};
3462+
}
3463+
};
3464+
return lookupClass(t, makePred, typeArgs, name);
3465+
}
3466+
finally { debug.logEnd(); }
34613467
}
34623468

34633469
/** Look up an inner class based on the given predicate. */
@@ -3466,8 +3472,8 @@ private ClassType lookupClass(Type t, Lambda<? super Boolean, ? extends Predicat
34663472
throws InvalidTargetException, InvalidTypeArgumentException, UnmatchedLookupException {
34673473
Iterable<? extends ClassType> results = lookupClasses(t, makePred, typeArgs);
34683474
// TODO: provide more error-message information
3469-
if (IterUtil.isEmpty(results)) { throw new UnmatchedLookupException(); }
3470-
else if (IterUtil.sizeOf(results) > 1) { throw new UnmatchedLookupException(); }
3475+
int matches = IterUtil.sizeOf(results);
3476+
if (matches != 1) { throw new UnmatchedLookupException(matches); }
34713477
else {
34723478
ClassType result = IterUtil.first(results);
34733479
final Iterable<VariableType> params = SymbolUtil.allTypeParameters(result.ofClass());
@@ -3626,7 +3632,6 @@ private boolean inBounds(Iterable<? extends VariableType> params, Iterable<? ext
36263632
if (isEqual(t, checkedT)) { return IterUtil.empty(); }
36273633
}
36283634

3629-
// System.out.println("Searching for member in type " + userRepresentation(t));
36303635
final Iterable<? extends T> baseResult = t.apply(baseCase);
36313636
alreadyChecked.add(t);
36323637
if (!IterUtil.isEmpty(baseResult)) { return baseResult; }

dynamicjava/src/edu/rice/cs/dynamicjava/symbol/TypeSystem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ public static class InvalidTargetException extends TypeSystemException {
563563
}
564564

565565
public static class UnmatchedLookupException extends TypeSystemException {
566+
private final int _matches;
567+
public UnmatchedLookupException(int matches) { _matches = matches; }
568+
public int matches() { return _matches; }
566569
}
567570

568571

dynamicjava/src/koala/dynamicjava/interpreter/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ undefined.class = Undefined class '%0'
193193

194194
# Used by NameVisitor
195195
undefined.name = Undefined name '%0'
196+
undefined.name.noinfo = Undefined name
196197

197198
# Used by TreeCompiler
198199
undefined.or.defined.class = Class '%0' not found or already defined

0 commit comments

Comments
 (0)