Skip to content

Commit d29db16

Browse files
author
dlsmith
committed
DynamicJava: Integrated contextual expected types into inference. Refactored ExpressionChecker so that TypeNames are handled by a new TypeNameChecker, and both hide their visitor implementation, forcing invocations to go through a public "check" method. Updated the build script's usage of Retroweaver so that verification is turned on; replaced jlbench.jar with jlbench-base-14.jar to prevent clashes with PLT classes.
git-svn-id: file:///tmp/test-svn/trunk@4630 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 875709e commit d29db16

File tree

11 files changed

+1857
-1600
lines changed

11 files changed

+1857
-1600
lines changed

dynamicjava/build.xml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
<classpath>
190190
<fileset refid="libs" />
191191
<pathelement location="lib/buildlib/junit.jar" />
192-
<pathelement location="lib/buildlib/jlbench.jar" />
192+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
193193
<pathelement location="classes/base" />
194194
</classpath>
195195
<compilerarg value="-Xlint" />
@@ -273,17 +273,14 @@
273273
<pathelement location="classes/lib-14" />
274274
</path>
275275
</pathconvert>
276-
<!-- We must handle ReflectionAdapter15 separately, since it contains 5.0-specific code -->
277-
<retroweaver srcdir="classes/base" destdir="classes/base-14" target="1.4" verify="no" />
278-
<!-- COMMENTED OUT DUE TO A BUG IN RETROWEAVER - IT DOESN'T SEEM TO SUPPORT USING A FILESET
276+
<!-- We must handle Java5Class separately, since it contains 5.0-specific code; but it must be converted
277+
to conform to the modified interface -->
279278
<retroweaver destdir="classes/base-14" target="1.4" verify="yes" classpath="${retroweaver-base-classpath}">
280-
<fileset dir="classes/base" />
281-
<fileset dir="classes/base" excludes="koala/dynamicjava/interpreter/ReflectionAdapter15*.class" />
279+
<fileset dir="classes/base" includes="**/*.class" excludes="edu/rice/cs/dynamicjava/symbol/Java5Class*.class" />
282280
</retroweaver>
283-
<retroweaver destdir="classes/base-14" target="1.4" verify="no">
284-
<fileset dir="classes/base" includes="koala/dynamicjava/interpreter/ReflectionAdapter15*.class" />
281+
<retroweaver destdir="classes/base-14" target="1.4" verify="no" classpath="${retroweaver-base-classpath}">
282+
<fileset dir="classes/base" includes="edu/rice/cs/dynamicjava/symbol/Java5Class*.class" />
285283
</retroweaver>
286-
-->
287284
<copy todir="classes/base-14">
288285
<fileset dir="classes/base" excludes="**/*.class" />
289286
</copy>
@@ -295,7 +292,7 @@
295292
<pathelement location="${java14-runtime}" />
296293
<pathelement location="${clover-jar}" />
297294
<pathelement location="lib/buildlib/junit.jar" />
298-
<pathelement location="lib/buildlib/jlbench.jar" />
295+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
299296
<pathelement location="classes/base-14" />
300297
<pathelement location="classes/lib-14" />
301298
<pathelement location="classes/test-14" />
@@ -374,7 +371,7 @@
374371
<junit haltonfailure="yes" fork="yes" forkmode="perTest" maxmemory="256M" dir="${basedir}">
375372
<classpath>
376373
<pathelement location="lib/buildlib/junit.jar" />
377-
<pathelement location="lib/buildlib/jlbench.jar" />
374+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
378375
<pathelement location="${clover-jar}" />
379376
<pathelement location="classes/test" />
380377
<pathelement location="classes/base" />
@@ -394,7 +391,7 @@
394391
<junit haltonfailure="yes" fork="yes" forkmode="perTest" maxmemory="256M" jvm="${java14-exec}" dir="${basedir}">
395392
<classpath>
396393
<pathelement location="lib/buildlib/junit.jar" />
397-
<pathelement location="lib/buildlib/jlbench.jar" />
394+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
398395
<pathelement location="${clover-jar}" />
399396
<pathelement location="classes/test-14" />
400397
<pathelement location="classes/base-14" />
@@ -414,7 +411,7 @@
414411
<junit haltonfailure="yes" fork="yes" forkmode="perTest" maxmemory="256M" dir="${basedir}">
415412
<classpath>
416413
<pathelement location="lib/buildlib/junit.jar" />
417-
<pathelement location="lib/buildlib/jlbench.jar" />
414+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
418415
<pathelement location="${clover-jar}" />
419416
<pathelement location="classes/test-14" />
420417
<pathelement location="classes/base-14" />
@@ -508,7 +505,7 @@
508505
<classpath>
509506
<fileset refid="libs" />
510507
<pathelement location="lib/buildlib/junit.jar" />
511-
<pathelement location="lib/buildlib/jlbench.jar" />
508+
<pathelement location="lib/buildlib/jlbench-base-14.jar" />
512509
</classpath>
513510
<link href="http://java.sun.com/j2se/1.5/docs/api" />
514511
<link href="http://junit.org/junit/javadoc/3.8.1" />
81.5 KB
Binary file not shown.
-777 KB
Binary file not shown.

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ private void checkBodies(Iterable<Node> nodes) {
4646
for (Node n : nodes) { n.acceptVisitor(bod); }
4747
}
4848

49-
private Type checkType(Expression exp) { return new ExpressionChecker(_context, _opt).value(exp); }
50-
51-
private Type checkType(Expression exp, Type expected) {
52-
return new ExpressionChecker(_context, _opt, expected).value(exp);
53-
}
54-
55-
private Iterable<Type> checkTypes(Iterable<? extends Expression> l) {
56-
return IterUtil.mapSnapshot(l, new ExpressionChecker(_context, _opt));
57-
}
58-
59-
private Type checkTypeName(TypeName t) {
60-
// It would be nice to separate TypeName handling into a different visitor,
61-
// but this works for now.
62-
return t.acceptVisitor(new ExpressionChecker(_context, _opt));
63-
}
6449

6550
private class SignatureVisitor extends AbstractVisitor<Void> {
6651

@@ -85,18 +70,18 @@ private class SignatureVisitor extends AbstractVisitor<Void> {
8570
}
8671

8772
TypeContext sigContext = new FunctionSignatureContext(_context, m);
88-
ExpressionChecker sigChecker = new ExpressionChecker(sigContext, _opt);
73+
TypeNameChecker sigChecker = new TypeNameChecker(sigContext, _opt);
8974
sigChecker.setTypeParameterBounds(tparams);
9075

91-
Type returnT = node.getReturnType().acceptVisitor(sigChecker);
76+
Type returnT = sigChecker.check(node.getReturnType());
9277
setErasedType(node, _opt.typeSystem().erasedClass(returnT));
9378

9479
for (FormalParameter param : node.getParameters()) {
95-
Type t = param.getType().acceptVisitor(sigChecker);
80+
Type t = sigChecker.check(param.getType());
9681
setVariable(param, new LocalVariable(param.getName(), t, param.isFinal()));
9782
}
9883

99-
for (TypeName tn : node.getExceptions()) { tn.acceptVisitor(sigChecker); }
84+
for (TypeName tn : node.getExceptions()) { sigChecker.check(tn); }
10085
return null;
10186
}
10287

@@ -118,20 +103,20 @@ private class SignatureVisitor extends AbstractVisitor<Void> {
118103
}
119104

120105
TypeContext sigContext = new FunctionSignatureContext(_context, k);
121-
ExpressionChecker sigChecker = new ExpressionChecker(sigContext, _opt);
106+
TypeNameChecker sigChecker = new TypeNameChecker(sigContext, _opt);
122107
sigChecker.setTypeParameterBounds(tparams);
123108

124109
for (FormalParameter param : node.getParameters()) {
125-
Type t = param.getType().acceptVisitor(sigChecker);
110+
Type t = sigChecker.check(param.getType());
126111
setVariable(param, new LocalVariable(param.getName(), t, param.isFinal()));
127112
}
128113

129-
for (TypeName tn : node.getExceptions()) { tn.acceptVisitor(sigChecker); }
114+
for (TypeName tn : node.getExceptions()) { sigChecker.check(tn); }
130115
return null;
131116
}
132117

133118
@Override public Void visit(FieldDeclaration node) {
134-
checkTypeName(node.getType());
119+
new TypeNameChecker(_context, _opt).check(node.getType());
135120
return null;
136121
}
137122

@@ -160,7 +145,7 @@ private class BodyVisitor extends AbstractVisitor<Void> {
160145
TypeContext bodyContext = new FunctionContext(sigContext, k);
161146
ConstructorCall call = node.getConstructorCall();
162147
if (call == null) { call = new ConstructorCall(null, null, true); }
163-
call.acceptVisitor(new ExpressionChecker(bodyContext, _opt));
148+
new ExpressionChecker(bodyContext, _opt).check(call);
164149
for (Node n : node.getStatements()) {
165150
bodyContext = n.acceptVisitor(new StatementChecker(bodyContext, _opt));
166151
}
@@ -172,7 +157,7 @@ private class BodyVisitor extends AbstractVisitor<Void> {
172157
Type expectedT = getType(node.getType());
173158
Expression init = node.getInitializer();
174159
if (init != null) {
175-
Type initT = checkType(init, expectedT);
160+
Type initT = new ExpressionChecker(_context, _opt).check(init, expectedT);
176161
TypeSystem ts = _opt.typeSystem();
177162
try {
178163
Expression newInit = ts.assign(expectedT, init);

0 commit comments

Comments
 (0)