Skip to content

Commit 40502fe

Browse files
author
dlsmith
committed
DynamicJava: Completed refactoring from use of multiple fields to pass around source data to using SourceInfo objects. (The class was introduced years ago, but the AST had not been updated.)
git-svn-id: file:///tmp/test-svn/trunk@4799 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent d7e29fa commit 40502fe

File tree

162 files changed

+1039
-2802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1039
-2802
lines changed

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,10 @@ private Node resolveAmbiguousName(AmbiguousName node) {
214214
Expression resultExp = null;
215215

216216
if (context.localVariableExists(first.image(), ts)) {
217-
resultExp = new VariableAccess(first.image(), node.getFilename(), first.beginLine(),
218-
first.beginColumn(), first.endLine(), first.endColumn());
217+
resultExp = new VariableAccess(first.image(), first.getSourceInfo());
219218
}
220219
else if (context.fieldExists(first.image(), ts)) {
221-
resultExp = new SimpleFieldAccess(first.image(), node.getFilename(), first.beginLine(),
222-
first.beginColumn(), first.endLine(), first.endColumn());
220+
resultExp = new SimpleFieldAccess(first.image(), first.getSourceInfo());
223221
}
224222
else {
225223
// Try to match a class
@@ -263,12 +261,8 @@ else if (context.fieldExists(first.image(), ts)) {
263261
while (ids.hasNext() && resultExp == null) {
264262
IdentifierToken memberName = ids.next();
265263
if (ts.containsField(classType, memberName.image())) {
266-
ReferenceTypeName rt = new ReferenceTypeName(classIds, node.getFilename(),
267-
first.beginLine(), first.beginColumn(),
268-
last.endLine(), last.endColumn());
269-
resultExp = new StaticFieldAccess(rt, memberName.image(), rt.getFilename(),
270-
first.beginLine(), first.beginColumn(),
271-
memberName.endLine(), memberName.endColumn());
264+
ReferenceTypeName rt = new ReferenceTypeName(classIds, SourceInfo.span(first, last));
265+
resultExp = new StaticFieldAccess(rt, memberName.image(), SourceInfo.span(first, memberName));
272266
}
273267
else if (ts.containsClass(classType, memberName.image())) {
274268
last = memberName;
@@ -292,18 +286,14 @@ else if (ts.containsClass(classType, memberName.image())) {
292286
}
293287

294288
if (resultExp == null) { // there must be no more tokens; the name is the name of a class
295-
return new ReferenceTypeName(classIds, node.getFilename(),
296-
first.beginLine(), first.beginColumn(),
297-
last.endLine(), last.endColumn());
289+
return new ReferenceTypeName(classIds, SourceInfo.span(first, last));
298290
}
299291
}
300292

301293
// resultExp is now guaranteed to be defined; append any additional identifiers as field accesses
302294
while (ids.hasNext()) {
303295
IdentifierToken field = ids.next();
304-
resultExp = new ObjectFieldAccess(resultExp, field.image(), node.getFilename(),
305-
first.beginLine(), first.beginColumn(),
306-
field.endLine(), field.endColumn());
296+
resultExp = new ObjectFieldAccess(resultExp, field.image(), SourceInfo.span(first, field));
307297
}
308298
return resultExp;
309299
}
@@ -403,9 +393,7 @@ else if (ts.containsClass(classType, memberName.image())) {
403393
if (resolved instanceof ReferenceTypeName) {
404394
// this is actually a StaticFieldAccess
405395
Expression translation =
406-
new StaticFieldAccess((ReferenceTypeName) resolved, node.getFieldName(), node.getFilename(),
407-
node.getBeginLine(), node.getBeginColumn(), node.getEndLine(),
408-
node.getEndColumn());
396+
new StaticFieldAccess((ReferenceTypeName) resolved, node.getFieldName(), node.getSourceInfo());
409397
translation.acceptVisitor(this);
410398
setTranslation(node, translation);
411399
setVariableType(node, getVariableType(translation));
@@ -552,13 +540,11 @@ else if (ts.containsClass(classType, memberName.image())) {
552540
translation =
553541
new PolymorphicStaticMethodCall((ReferenceTypeName) resolved, node.getMethodName(), node.getArguments(),
554542
((PolymorphicObjectMethodCall) node).getTypeArguments(),
555-
node.getFilename(), node.getBeginLine(), node.getBeginColumn(),
556-
node.getEndLine(), node.getEndColumn());
543+
node.getSourceInfo());
557544
}
558545
else {
559546
translation = new StaticMethodCall((ReferenceTypeName) resolved, node.getMethodName(),
560-
node.getArguments(), node.getFilename(), node.getBeginLine(),
561-
node.getBeginColumn(), node.getEndLine(), node.getEndColumn());
547+
node.getArguments(), node.getSourceInfo());
562548
}
563549
translation.acceptVisitor(this);
564550
setTranslation(node, translation);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Interpreter(Options opt, TypeContext typeContext, RuntimeBindings binding
2828
_bindings = bindings;
2929
// Force potentially expensive objects/classes to initialize now:
3030
_opt.typeSystem();
31-
new JavaCCParser(new StringReader(""), "").parseStream();
31+
new JavaCCParser(new StringReader("")).parseStream();
3232
}
3333

3434
public Interpreter(Options opt) {
@@ -60,7 +60,7 @@ public Option<Object> interpret(String code) throws InterpreterException {
6060

6161
private Iterable<Node> parse(String code) throws InterpreterException {
6262
try {
63-
return new JavaCCParser(new StringReader(code), "[string input]").parseStream();
63+
return new JavaCCParser(new StringReader(code)).parseStream();
6464
}
6565
catch (ParseError e) {
6666
throw new ParserException(e);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
import edu.rice.cs.plt.tuple.Option;
8383
import edu.rice.cs.plt.lambda.Lambda;
8484

85-
import koala.dynamicjava.SourceInfo;
8685
import koala.dynamicjava.tree.*;
8786
import koala.dynamicjava.tree.tiger.*;
8887
import koala.dynamicjava.tree.visitor.*;
@@ -748,10 +747,7 @@ else if (ts.isAssignable(TypeSystem.EXCEPTION, thrown)) {
748747
if (ambigName.getIdentifiers().size() == 1) {
749748
String name = ambigName.getRepresentation();
750749
if (!context.variableExists(name, opt.typeSystem())) {
751-
SourceInfo si = node.getSourceInfo();
752-
Node decl = new VariableDeclaration(false, null, name, assign.getRightExpression(),
753-
si.getFilename(), si.getStartLine(), si.getStartColumn(),
754-
si.getEndLine(), si.getEndColumn());
750+
Node decl = new VariableDeclaration(false, null, name, assign.getRightExpression(), node.getSourceInfo());
755751
setStatementTranslation(node, decl);
756752
return decl.acceptVisitor(this);
757753
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,7 @@ public Expression makePrimitive(Expression e) throws UnsupportedConversionExcept
11911191
}
11921192

11931193
private Expression unbox(Expression exp, String methodName) {
1194-
ObjectMethodCall result = new ObjectMethodCall(exp, methodName, null,
1195-
exp.getFilename(), exp.getBeginLine(), exp.getBeginColumn(),
1196-
exp.getEndLine(), exp.getEndColumn());
1194+
ObjectMethodCall result = new ObjectMethodCall(exp, methodName, null, exp.getSourceInfo());
11971195
try {
11981196
ObjectMethodInvocation inv = lookupMethod(exp, methodName, EMPTY_TYPE_ITERABLE, EMPTY_EXPRESSION_ITERABLE,
11991197
NONE_TYPE_OPTION);
@@ -1239,9 +1237,7 @@ private Expression box(Expression exp, ClassType boxedType) {
12391237
NodeProperties.setType(boxedTypeName, boxedType);
12401238
List<Expression> arguments = Collections.singletonList(exp);
12411239
if (JavaVersion.CURRENT.supports(JavaVersion.JAVA_5)) {
1242-
StaticMethodCall m = new StaticMethodCall(boxedTypeName, "valueOf", arguments,
1243-
exp.getFilename(), exp.getBeginLine(), exp.getBeginColumn(),
1244-
exp.getEndLine(), exp.getEndColumn());
1240+
StaticMethodCall m = new StaticMethodCall(boxedTypeName, "valueOf", arguments, exp.getSourceInfo());
12451241
try {
12461242
MethodInvocation inv = lookupStaticMethod(boxedType, "valueOf", EMPTY_TYPE_ITERABLE, arguments,
12471243
NONE_TYPE_OPTION);
@@ -1253,8 +1249,7 @@ private Expression box(Expression exp, ClassType boxedType) {
12531249
catch (TypeSystemException e) { throw new RuntimeException("Boxing method inaccessible", e); }
12541250
}
12551251
else {
1256-
SimpleAllocation k = new SimpleAllocation(boxedTypeName, arguments, exp.getFilename(), exp.getBeginLine(),
1257-
exp.getBeginColumn(), exp.getEndLine(), exp.getEndColumn());
1252+
SimpleAllocation k = new SimpleAllocation(boxedTypeName, arguments, exp.getSourceInfo());
12581253
try {
12591254
ConstructorInvocation inv = lookupConstructor(boxedType, EMPTY_TYPE_ITERABLE, arguments, NONE_TYPE_OPTION);
12601255
k.setArguments(CollectUtil.makeList(inv.args()));
@@ -1616,8 +1611,7 @@ private Expression handleSmallPrimitive(PrimitiveType target) {
16161611
* also be set on {@code e}, as necessary.
16171612
*/
16181613
private Expression makeCast(Type target, Expression e) {
1619-
Expression result = new CastExpression(null, e, e.getFilename(), e.getBeginLine(), e.getBeginColumn(),
1620-
e.getEndLine(), e.getEndColumn());
1614+
Expression result = new CastExpression(null, e, e.getSourceInfo());
16211615
if (isPrimitive(target)) {
16221616
if (!isEqual(target, NodeProperties.getType(e))) {
16231617
NodeProperties.setConvertedType(e, erasedClass(target));
@@ -1642,7 +1636,7 @@ private Expression makeArray(ArrayType arrayType, Iterable<? extends Expression>
16421636
NodeProperties.setType(init, arrayType);
16431637
NodeProperties.setErasedType(init, erasedType);
16441638
Expression result = new ArrayAllocation(tn, new ArrayAllocation.TypeDescriptor(new ArrayList<Expression>(0),
1645-
1, init, 0, 0));
1639+
1, init, SourceInfo.NONE));
16461640
NodeProperties.setType(result, arrayType);
16471641
NodeProperties.setErasedType(result, erasedType);
16481642
return result;

dynamicjava/src/koala/dynamicjava/interpreter/TypeUtil.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import koala.dynamicjava.tree.Node;
44
import koala.dynamicjava.tree.Expression;
5+
import koala.dynamicjava.tree.SourceInfo;
56
import koala.dynamicjava.tree.TypeName;
67
import koala.dynamicjava.tree.visitor.Visitor;
78

@@ -15,7 +16,7 @@ public class TypeUtil {
1516
* but it can have properties set and be used to build other {@code Node}s.
1617
*/
1718
public static Expression makeEmptyExpression() {
18-
return new Expression(null, 0, 0, 0, 0) {
19+
return new Expression(SourceInfo.NONE) {
1920
public <T> T acceptVisitor(Visitor<T> v) {
2021
throw new IllegalArgumentException("Cannot visit an empty expression");
2122
}
@@ -29,8 +30,7 @@ public <T> T acceptVisitor(Visitor<T> v) {
2930
* but it can have properties set and be used to build other {@code Node}s.
3031
*/
3132
public static Expression makeEmptyExpression(Node location) {
32-
return new Expression(location.getFilename(), location.getBeginLine(), location.getBeginColumn(),
33-
location.getEndLine(), location.getEndColumn()) {
33+
return new Expression(location.getSourceInfo()) {
3434
public <T> T acceptVisitor(Visitor<T> v) {
3535
throw new IllegalArgumentException("Cannot visit an empty expression");
3636
}
@@ -42,7 +42,7 @@ public <T> T acceptVisitor(Visitor<T> v) {
4242
* but it can have properties set and be used to build other {@code Node}s.
4343
*/
4444
public static TypeName makeEmptyTypeName() {
45-
return new TypeName(null, 0, 0, 0, 0) {
45+
return new TypeName(SourceInfo.NONE) {
4646
public <T> T acceptVisitor(Visitor<T> v) {
4747
throw new IllegalArgumentException("Cannot visit an empty type name");
4848
}
@@ -55,8 +55,7 @@ public <T> T acceptVisitor(Visitor<T> v) {
5555
* but it can have properties set and be used to build other {@code Node}s.
5656
*/
5757
public static TypeName makeEmptyTypeName(Node location) {
58-
return new TypeName(location.getFilename(), location.getBeginLine(), location.getBeginColumn(),
59-
location.getEndLine(), location.getEndColumn()) {
58+
return new TypeName(location.getSourceInfo()) {
6059
public <T> T acceptVisitor(Visitor<T> v) {
6160
throw new IllegalArgumentException("Cannot visit an empty type name");
6261
}

0 commit comments

Comments
 (0)