Skip to content

Commit 3f4dc22

Browse files
committed
ti/optimization: reuse RSimpleType for some predefined types
1 parent 049bdf2 commit 3f4dc22

File tree

5 files changed

+17
-45
lines changed

5 files changed

+17
-45
lines changed

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ConstantValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public String toString() {
5757
return getClass().getSimpleName() + value.getTypes();
5858
}
5959

60-
public static IValueReference valueOf(IRType type) {
60+
public static IValueReference of(IRType type) {
6161
return type != null ? new ConstantValue(type) : null;
6262
}
6363

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/IValueTypeFactory.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,13 @@ public interface IValueTypeFactory {
1919

2020
IValueReference create(IValueParent parent, IRType type);
2121

22-
IValueReference createObject(IValueParent parent);
23-
24-
@Deprecated
25-
IValueReference createString(IValueParent parent);
26-
2722
@Deprecated
2823
IValueReference createRegExp(IValueParent parent);
2924

30-
@Deprecated
31-
IValueReference createNumber(IValueParent parent);
32-
3325
IValueReference createXML(IValueParent parent);
3426

3527
IValueReference createXMLList(IValueParent parent);
3628

37-
@Deprecated
38-
IValueReference createBoolean(IValueParent parent);
39-
4029
@Deprecated
4130
IValueReference createArray(IValueParent parent);
4231

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,16 @@ public IValueReference visitBinaryOperation(BinaryOperation node) {
269269
|| op == JSParser.LTE || op == JSParser.NSAME
270270
|| op == JSParser.SAME || op == JSParser.NEQ
271271
|| op == JSParser.EQ) {
272-
return context.getFactory().createBoolean(peekContext());
272+
return ConstantValue.of(RTypes.BOOLEAN);
273273
} else if (isNumber(left) && isNumber(right)) {
274-
return context.getFactory().createNumber(peekContext());
274+
return ConstantValue.of(RTypes.NUMBER);
275275
} else if (op == JSParser.ADD) {
276276
if (isString(left) || isString(right)) {
277-
return context.getFactory().createString(peekContext());
277+
return ConstantValue.of(RTypes.STRING);
278278
}
279279
return left;
280280
} else if (JSParser.INSTANCEOF == op) {
281-
return context.getFactory().createBoolean(peekContext());
281+
return ConstantValue.of(RTypes.BOOLEAN);
282282
} else if (JSParser.LOR == op) {
283283
final JSTypeSet typeSet = JSTypeSet.create();
284284
if (left != null) {
@@ -372,7 +372,7 @@ private boolean hasUnknowParentFunctionCall(IValueReference reference) {
372372

373373
@Override
374374
public IValueReference visitBooleanLiteral(BooleanLiteral node) {
375-
return context.getFactory().createBoolean(peekContext());
375+
return ConstantValue.of(RTypes.BOOLEAN);
376376
}
377377

378378
@Override
@@ -400,15 +400,15 @@ public IValueReference visitCallExpression(CallExpression node) {
400400
return new ConstantValue(type);
401401
}
402402
} else {
403-
return ConstantValue.valueOf(method.getType());
403+
return ConstantValue.of(method.getType());
404404
}
405405
} else {
406406
final IRType expressionType = JavaScriptValidations
407407
.typeOf(reference);
408408
if (expressionType != null) {
409409
if (expressionType instanceof IRFunctionType) {
410410
return ConstantValue
411-
.valueOf(((IRFunctionType) expressionType)
411+
.of(((IRFunctionType) expressionType)
412412
.getReturnType());
413413
} else if (expressionType instanceof IRClassType) {
414414
final IRTypeDeclaration target = ((IRClassType) expressionType)
@@ -713,7 +713,7 @@ public IValueReference visitContinueStatement(ContinueStatement node) {
713713

714714
@Override
715715
public IValueReference visitDecimalLiteral(DecimalLiteral node) {
716-
return context.getFactory().createNumber(peekContext());
716+
return ConstantValue.of(RTypes.NUMBER);
717717
}
718718

719719
@Override
@@ -786,7 +786,7 @@ public IValueReference visitForEachInStatement(ForEachInStatement node) {
786786
public IValueReference visitForInStatement(ForInStatement node) {
787787
final IValueReference item = visit(node.getItem());
788788
if (item != null) {
789-
assign(item, context.getFactory().createString(peekContext()));
789+
assign(item, ConstantValue.of(RTypes.STRING));
790790
}
791791
visit(node.getIterator());
792792
visit(node.getBody());
@@ -1166,8 +1166,7 @@ protected VisitNewResult visitNew(NewExpression node) {
11661166
}
11671167
} else {
11681168
result.value = new AnonymousNewValue();
1169-
result.value.setValue(context.getFactory().createObject(
1170-
contextValueCollection));
1169+
result.value.setValue(ConstantValue.of(RTypes.OBJECT));
11711170
}
11721171
}
11731172
return result;
@@ -1314,7 +1313,7 @@ public IValueReference visitStatementBlock(StatementBlock node) {
13141313

13151314
@Override
13161315
public IValueReference visitStringLiteral(StringLiteral node) {
1317-
return context.getFactory().createString(peekContext());
1316+
return ConstantValue.of(RTypes.STRING);
13181317
}
13191318

13201319
@Override
@@ -1368,16 +1367,16 @@ public IValueReference visitTryStatement(TryStatement node) {
13681367
public IValueReference visitUnaryOperation(UnaryOperation node) {
13691368
if (node.getOperation() == JSParser.NOT) {
13701369
visit(node.getExpression());
1371-
return context.getFactory().createBoolean(peekContext());
1370+
return ConstantValue.of(RTypes.BOOLEAN);
13721371
} else if (node.getOperation() == JSParser.DELETE) {
13731372
final IValueReference value = visit(node.getExpression());
13741373
if (value != null) {
13751374
value.delete();
13761375
}
1377-
return context.getFactory().createBoolean(peekContext());
1376+
return ConstantValue.of(RTypes.BOOLEAN);
13781377
} else if (node.getOperation() == JSParser.TYPEOF) {
13791378
visit(node.getExpression());
1380-
return context.getFactory().createString(peekContext());
1379+
return ConstantValue.of(RTypes.STRING);
13811380
} else if (node.getOperation() == JSParser.VOID) {
13821381
visit(node.getExpression());
13831382
return null;

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/ValueTypeFactoryImpl.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,14 @@ public IValueReference create(IValueParent parent, final IRType type) {
3434
return new ConstantValue(type);
3535
}
3636

37-
public IValueReference createObject(IValueParent parent) {
38-
return create(parent, OBJECT);
39-
}
40-
4137
public IValueReference createArray(IValueParent parent) {
4238
return create(parent, ARRAY);
4339
}
4440

45-
public IValueReference createBoolean(IValueParent parent) {
46-
return create(parent, BOOLEAN);
47-
}
48-
49-
public IValueReference createNumber(IValueParent parent) {
50-
return create(parent, NUMBER);
51-
}
52-
5341
public IValueReference createRegExp(IValueParent parent) {
5442
return create(parent, REGEXP);
5543
}
5644

57-
public IValueReference createString(IValueParent parent) {
58-
return create(parent, STRING);
59-
}
60-
6145
public IValueReference createXML(IValueParent parent) {
6246
return create(parent, XML);
6347
}

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public IValueReference visitCallExpression(CallExpression node) {
869869
pushExpressionValidator(new CallExpressionValidator(
870870
peekFunctionScope(), node, reference, arguments,
871871
methods));
872-
return ConstantValue.valueOf(method.getType());
872+
return ConstantValue.of(method.getType());
873873
}
874874
} else {
875875
pushExpressionValidator(new CallExpressionValidator(
@@ -880,7 +880,7 @@ public IValueReference visitCallExpression(CallExpression node) {
880880
if (expressionType != null) {
881881
if (expressionType instanceof IRFunctionType) {
882882
return ConstantValue
883-
.valueOf(((IRFunctionType) expressionType)
883+
.of(((IRFunctionType) expressionType)
884884
.getReturnType());
885885
} else if (expressionType instanceof IRClassType) {
886886
final IRTypeDeclaration target = ((IRClassType) expressionType)

0 commit comments

Comments
 (0)