Skip to content

Commit 900f063

Browse files
author
dlsmith
committed
DynamicJava: Fixed checking of switch statement constants. Fixed internal error when processing break or continue statements. Fixed stack overflow occuring during well-formedness and subtyping checks.
git-svn-id: file:///tmp/test-svn/trunk@4982 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 46bcadf commit 900f063

File tree

12 files changed

+277
-147
lines changed

12 files changed

+277
-147
lines changed

dynamicjava/lib/plt.jar

1 Byte
Binary file not shown.

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ public ClassChecker(DJClass c, ClassLoader loader, TypeContext context, Options
4040
public void initializeClassSignatures(TypeDeclaration ast) {
4141
TypeContext sigContext = new ClassSignatureContext(_context, _c, _loader);
4242
TypeNameChecker sigChecker = new TypeNameChecker(sigContext, _opt);
43-
sigChecker.checkStructureForTypeParameters(typeParameters(ast));
44-
if (ast instanceof ClassDeclaration) {
45-
sigChecker.checkStructure(((ClassDeclaration) ast).getSuperclass());
46-
}
47-
if (ast.getInterfaces() != null) {
48-
for (TypeName tn : ast.getInterfaces()) { sigChecker.checkStructure(tn); }
43+
debug.logStart("Initializing type parameters", "class", ast.getName());
44+
try { sigChecker.checkStructureForTypeParameters(typeParameters(ast)); }
45+
finally { debug.logEnd(); }
46+
debug.logStart("Initializing supertypes", "class", ast.getName());
47+
try {
48+
if (ast instanceof ClassDeclaration) {
49+
sigChecker.checkStructure(((ClassDeclaration) ast).getSuperclass());
50+
}
51+
if (ast.getInterfaces() != null) {
52+
for (TypeName tn : ast.getInterfaces()) { sigChecker.checkStructure(tn); }
53+
}
4954
}
55+
finally { debug.logEnd(); }
5056
initializeNestedClassSignatures(ast.getMembers(), sigContext);
5157
}
5258

@@ -85,13 +91,19 @@ private void initializeNestedClassSignatures(Iterable<? extends Node> members, T
8591
public void checkSignatures(TypeDeclaration ast) {
8692
TypeContext sigContext = new ClassSignatureContext(_context, _c, _loader);
8793
TypeNameChecker sigChecker = new TypeNameChecker(sigContext, _opt);
88-
sigChecker.ensureWellFormedTypeParameters(typeParameters(ast));
89-
if (ast instanceof ClassDeclaration) {
90-
sigChecker.ensureWellFormed(((ClassDeclaration) ast).getSuperclass());
91-
}
92-
if (ast.getInterfaces() != null) {
93-
for (TypeName tn : ast.getInterfaces()) { sigChecker.ensureWellFormed(tn); }
94+
debug.logStart("Check type parameters");
95+
try { sigChecker.ensureWellFormedTypeParameters(typeParameters(ast)); }
96+
finally { debug.logEnd(); }
97+
debug.logStart("Check supertypes");
98+
try {
99+
if (ast instanceof ClassDeclaration) {
100+
sigChecker.ensureWellFormed(((ClassDeclaration) ast).getSuperclass());
101+
}
102+
if (ast.getInterfaces() != null) {
103+
for (TypeName tn : ast.getInterfaces()) { sigChecker.ensureWellFormed(tn); }
104+
}
94105
}
106+
finally { debug.logEnd(); }
95107

96108
if (ast instanceof InterfaceDeclaration) { checkInterfaceMemberSignatures(ast.getMembers(), sigContext); }
97109
else { checkClassMemberSignatures(ast.getMembers(), sigContext); }
@@ -116,13 +128,21 @@ public void checkSignatures(AnonymousInnerAllocation ast) {
116128
private void checkClassMemberSignatures(Iterable<? extends Node> members, TypeContext sigContext) {
117129
TypeContext bodyContext = new ClassContext(sigContext, _c);
118130
Visitor<Void> v = new ClassMemberSignatureVisitor(bodyContext);
119-
for (Node n : members) { n.acceptVisitor(v); }
131+
for (Node n : members) {
132+
debug.logStart();
133+
try { n.acceptVisitor(v); }
134+
finally { debug.logEnd(); }
135+
}
120136
}
121137

122138
private void checkInterfaceMemberSignatures(Iterable<? extends Node> members, TypeContext sigContext) {
123139
TypeContext bodyContext = new ClassContext(sigContext, _c);
124140
Visitor<Void> v = new InterfaceMemberSignatureVisitor(bodyContext);
125-
for (Node n : members) { n.acceptVisitor(v); }
141+
for (Node n : members) {
142+
debug.logStart();
143+
try { n.acceptVisitor(v); }
144+
finally { debug.logEnd(); }
145+
}
126146
}
127147

128148
/**
@@ -153,7 +173,11 @@ private void checkBodies(Iterable<? extends Node> members) {
153173
TypeContext sigContext = new ClassSignatureContext(_context, _c, _loader);
154174
TypeContext bodyContext = new ClassContext(sigContext, _c);
155175
MemberBodyVisitor bod = new MemberBodyVisitor(bodyContext);
156-
for (Node n : members) { n.acceptVisitor(bod); }
176+
for (Node n : members) {
177+
debug.logStart();
178+
try { n.acceptVisitor(bod); }
179+
finally { debug.logEnd(); }
180+
}
157181
}
158182

159183
private static TypeParameter[] typeParameters(TypeDeclaration ast) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ protected ClassContext duplicate(TypeContext next) {
5252
* if there is no such type.
5353
*/
5454
@Override public ClassType typeContainingMemberClass(String name, TypeSystem ts) throws AmbiguousNameException {
55+
debug.logStart(new String[]{"class","name"}, _c, name); try {
56+
5557
if (hasMemberClass(name, ts)) { return _thisType; }
5658
else { return super.typeContainingMemberClass(name, ts); }
59+
60+
} finally { debug.logEnd(); }
5761
}
5862

5963
private boolean hasMemberClass(String name, TypeSystem ts) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import edu.rice.cs.dynamicjava.symbol.type.ClassType;
55
import edu.rice.cs.dynamicjava.symbol.type.VariableType;
66

7+
import static edu.rice.cs.plt.debug.DebugUtil.debug;
8+
79
/**
810
* The context of a class declaration's signature, which includes its type variables and own name
911
* but excludes its members.
@@ -79,13 +81,17 @@ public boolean memberClassExists(String name, TypeSystem ts) {
7981
* if there is no such type.
8082
*/
8183
public ClassType typeContainingMemberClass(String name, TypeSystem ts) throws AmbiguousNameException {
84+
debug.logStart(new String[]{"class","name"}, _c, name); try {
85+
8286
if (matchesMemberClass(name)) {
8387
return SymbolUtil.thisType(_c.declaringClass());
8488
}
8589
else if (!matchesTopLevelClass(name) && !matchesTypeVariable(name)) {
8690
return super.typeContainingMemberClass(name, ts);
8791
}
8892
else { return null; }
93+
94+
} finally { debug.logEnd(); }
8995
}
9096

9197
/** Test whether {@code name} is an in-scope type variable. */

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ public void printUserMessage(PrintWriter out) {
3636
public SizedIterable<InterpreterException> exceptions() { return _exceptions; }
3737

3838
public static InterpreterException make(Iterable<? extends InterpreterException> errors) {
39-
if (IterUtil.sizeOf(errors, 2) == 1) { return IterUtil.first(errors); }
40-
else {
41-
List<InterpreterException> normalized = new ArrayList<InterpreterException>();
42-
for (InterpreterException e : errors) {
43-
if (e instanceof CompositeException) {
44-
CollectUtil.addAll(normalized, ((CompositeException) e).exceptions());
45-
}
46-
else { normalized.add(e); }
39+
List<InterpreterException> normalized = new ArrayList<InterpreterException>();
40+
for (InterpreterException e : errors) {
41+
if (e instanceof CompositeException) {
42+
CollectUtil.addAll(normalized, ((CompositeException) e).exceptions());
4743
}
48-
return new CompositeException(normalized);
44+
else { normalized.add(e); }
4945
}
46+
return new CompositeException(normalized);
5047
}
5148

5249
}

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,18 @@ else if (ts.isIterable(collType)) {
543543
}
544544

545545
else {
546-
if (!hasValue(bk) || getValue(bk) == null) {
547-
throw new ExecutionError("invalid.constant", bk);
546+
Expression exp = bk.getExpression();
547+
if (!hasValue(exp) || getValue(exp) == null) {
548+
throw new ExecutionError("invalid.constant", exp);
548549
}
549-
if (!ts.isAssignable(t, getType(bk), getValue(bk))) {
550-
setErrorStrings(node, ts.userRepresentation(getType(bk)));
551-
throw new ExecutionError("switch.label.type", bk);
550+
if (!ts.isAssignable(t, getType(exp), getValue(exp))) {
551+
setErrorStrings(node, ts.userRepresentation(getType(exp)));
552+
throw new ExecutionError("switch.label.type", exp);
552553
}
553-
if (values.contains(getValue(bk))) {
554+
if (values.contains(getValue(exp))) {
554555
throw new ExecutionError("duplicate.switch.case", node);
555556
}
556-
values.add(getValue(bk));
557+
values.add(getValue(exp));
557558
}
558559
}
559560

@@ -662,7 +663,7 @@ else if (ts.isAssignable(TypeSystem.EXCEPTION, thrown)) {
662663

663664
return context;
664665
}
665-
666+
666667
/**
667668
* Visits an AssertStatement. JLS 14.10.
668669
*/
@@ -710,6 +711,14 @@ else if (ts.isAssignable(TypeSystem.EXCEPTION, thrown)) {
710711
return context;
711712
}
712713

714+
@Override public TypeContext visit(BreakStatement node) {
715+
return context; // TODO: check control-flow context, labels
716+
}
717+
718+
@Override public TypeContext visit(ContinueStatement node) {
719+
return context; // TODO: check control-flow context, labels
720+
}
721+
713722
@Override public TypeContext visit(ExpressionStatement node) {
714723
if (node.getExpression() instanceof SimpleAssignExpression) {
715724
SimpleAssignExpression assign = (SimpleAssignExpression) node.getExpression();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ private class TypeNameVisitor extends AbstractVisitor<Type> implements Lambda<Ty
285285
else { throw new ExecutionError("ambiguous.name", node); }
286286
}
287287
}
288-
289288
while (ids.hasNext()) {
290289
try { t = ts.lookupClass(t, ids.next().image(), IterUtil.<Type>empty()); }
291290
catch (InvalidTargetException e) { throw new RuntimeException("lookup produced bad type"); }

dynamicjava/src/edu/rice/cs/dynamicjava/sourcechecker/SourceChecker.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void checkBodies(Relation<TypeDeclaration, ClassChecker> decls) throws I
126126
private void startStatus(String description) {
127127
_statusCount = 0;
128128
if (!_quiet) {
129-
String fullDesc = TextUtil.padRight(description + "...", ' ', 35);
129+
String fullDesc = TextUtil.padRight(description + "...", ' ', 36);
130130
System.out.print(fullDesc);
131131
System.out.flush();
132132
}
@@ -152,14 +152,18 @@ private abstract class Phase<T> {
152152

153153
public void run(Iterable<? extends T> args) throws InterpreterException {
154154
List<InterpreterException> errors = new ArrayList<InterpreterException>();
155+
debug.logStart(_description);
155156
startStatus(_description);
156157
for (T arg : args) {
158+
debug.logStart("location", location(arg));
157159
try { step(arg); }
158160
catch (InterpreterException e) { errors.add(e); }
159161
catch (RuntimeException e) { errors.add(new InternalException(e, location(arg))); }
160162
incrementStatus();
163+
debug.logEnd();
161164
}
162165
endStatus();
166+
debug.logEnd(_description);
163167
if (!errors.isEmpty()) { throw CompositeException.make(errors); }
164168
}
165169
}
@@ -176,7 +180,6 @@ protected final SourceInfo location(Pair<TypeDeclaration, ClassChecker> arg) {
176180
protected abstract void step(TypeDeclaration ast, ClassChecker checker);
177181
}
178182

179-
180183
public static void main(String... args) {
181184
ArgumentParser argParser = new ArgumentParser();
182185
argParser.supportOption("classpath", "");

0 commit comments

Comments
 (0)