Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painless: Clean up PainlessCast #32754

Merged
merged 83 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
1419751
Parially added constructor.
jdconrad Jul 26, 2018
6469598
Add method type to method.
jdconrad Jul 27, 2018
54b8992
Merge branch 'master' into clean18
jdconrad Jul 27, 2018
8581deb
Merge branch 'clean16' into clean19
jdconrad Jul 27, 2018
641c383
Add PainlessConstructor.
jdconrad Jul 27, 2018
5b449d8
Clean up method.
jdconrad Jul 27, 2018
3c5db32
Merge branch 'master' into clean19
jdconrad Jul 27, 2018
c19b95d
Merge branch 'clean19' into clean20
jdconrad Jul 27, 2018
266a92d
Fixes.
jdconrad Jul 27, 2018
2875c48
Clean up fields.
jdconrad Jul 27, 2018
3f17455
Merge branch 'master' into clean19
jdconrad Jul 30, 2018
b9299d6
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
aa833d9
Merge branch 'clean20' into clean21
jdconrad Jul 30, 2018
0c9c174
Reponse to PR comments.
jdconrad Jul 30, 2018
683361a
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
6757987
Merge branch 'clean20' into clean21
jdconrad Jul 30, 2018
ccabb90
Merge branch 'master' into clean19
jdconrad Jul 30, 2018
55004f1
Merge branch 'clean19' into clean20
jdconrad Jul 30, 2018
9ca9381
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
f379f2d
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
98995f2
Start to clean up PainlessLookup.
jdconrad Jul 31, 2018
8bd9a28
Complete method lookup.
jdconrad Jul 31, 2018
6eaca81
Add lookup constructor.
jdconrad Jul 31, 2018
aab122a
Add field lookup.
jdconrad Jul 31, 2018
509e607
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
aff5c3e
Reponse to PR comments.
jdconrad Jul 31, 2018
dbc3e27
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
43d5e49
Merge branch 'clean21' into clean22
jdconrad Jul 31, 2018
dfa6de1
Merge branch 'master' into clean20
jdconrad Jul 31, 2018
36f41af
Merge branch 'clean20' into clean21
jdconrad Jul 31, 2018
2265836
Merge branch 'clean21' into clean22
jdconrad Jul 31, 2018
57e2a46
Add local methods to def bootstrap for consistency in look ups.
jdconrad Aug 1, 2018
bd2d854
Merge branch 'master' into clean21
jdconrad Aug 1, 2018
7187e4f
Merge branch 'master' into clean21
jdconrad Aug 1, 2018
69da907
Merge branch 'clean21' into clean22
jdconrad Aug 1, 2018
eb3bb9f
Merge branch 'clean22' into clean24
jdconrad Aug 1, 2018
4da7113
Add FunctionReference.
jdconrad Aug 1, 2018
1d8b547
Progress.
jdconrad Aug 1, 2018
e51f3df
Progress.
jdconrad Aug 1, 2018
a082624
Progress.
jdconrad Aug 1, 2018
89e936e
Fix.
jdconrad Aug 1, 2018
cf430a9
Progress.
jdconrad Aug 1, 2018
c4e8357
Large clean up of function reference.
jdconrad Aug 1, 2018
bde26b4
A bit more clean up.
jdconrad Aug 1, 2018
b3ed1b7
Merge branch 'master' into clean22
jdconrad Aug 1, 2018
264f6a4
Merge branch 'clean22' into clean24
jdconrad Aug 1, 2018
2cf04ec
Merge branch 'clean24' into clean25
jdconrad Aug 1, 2018
02ab981
Move runtime method lookup to PainlessLookup.
jdconrad Aug 1, 2018
551dc4e
Add getter/setter lookup methods to PainlessLookup.
jdconrad Aug 1, 2018
c1d9d25
Rename.
jdconrad Aug 1, 2018
73bfbdf
Mechanical change to rename variables in PainlessCast.
jdconrad Aug 2, 2018
4255c3c
Merge branch 'master' into clean22
jdconrad Aug 2, 2018
9d5f02f
Remove unnecessary sorted classes list.
jdconrad Aug 2, 2018
a255273
Merge branch 'clean22' into clean24
jdconrad Aug 2, 2018
4dbb100
Merge branch 'clean24' into clean25
jdconrad Aug 2, 2018
9609b45
Merge branch 'clean25' into clean26
jdconrad Aug 2, 2018
f27f954
Merge branch 'clean26' into clean27
jdconrad Aug 2, 2018
64933d1
Merge branch 'master' into clean22
jdconrad Aug 2, 2018
61737be
Merge branch 'clean22' into clean24
jdconrad Aug 2, 2018
67f4140
Merge branch 'clean24' into clean25
jdconrad Aug 2, 2018
8471f6b
Merge branch 'clean25' into clean26
jdconrad Aug 2, 2018
61946df
Merge branch 'clean26' into clean27
jdconrad Aug 2, 2018
d7d0292
Remove extraneous line.
jdconrad Aug 2, 2018
aac6d88
Change Object to Map.
jdconrad Aug 2, 2018
4051638
Fix import.
jdconrad Aug 2, 2018
b65f459
Merge branch 'master' into clean24
jdconrad Aug 6, 2018
f071c78
Merge branch 'clean24' into clean25
jdconrad Aug 6, 2018
8e2a6af
Merge branch 'master' into clean25
jdconrad Aug 6, 2018
9921693
Merge branch 'clean25' into clean26
jdconrad Aug 6, 2018
c42e64e
Merge branch 'clean26' into clean27
jdconrad Aug 6, 2018
af80f8e
Merge branch 'master' into clean25
jdconrad Aug 7, 2018
0b8ebdf
Fix formatting.
jdconrad Aug 7, 2018
b7812d6
Add FunctionRef back.
jdconrad Aug 7, 2018
c7ebe54
Remove extraneous character.
jdconrad Aug 7, 2018
28f6e60
Merge branch 'master' into clean25
jdconrad Aug 7, 2018
b98030a
Merge branch 'clean25' into clean26
jdconrad Aug 7, 2018
fc578ed
Merge branch 'master' into clean26
jdconrad Aug 7, 2018
ab9a805
Merge branch 'clean26' into clean27
jdconrad Aug 7, 2018
1d3d2fc
Merge branch 'master' into clean26
jdconrad Aug 8, 2018
804f529
Return null instead of throwing exceptions for all methods in
jdconrad Aug 8, 2018
973c1b2
Merge branch 'master' into clean26
jdconrad Aug 8, 2018
f05f3d9
Merge branch 'clean26' into clean27
jdconrad Aug 8, 2018
4240f75
Merge branch 'master' into clean27
jdconrad Aug 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -135,52 +135,52 @@ public void writeLoopCounter(int slot, int count, Location location) {

public void writeCast(PainlessCast cast) {
if (cast != null) {
if (cast.from == char.class && cast.to == String.class) {
if (cast.originalType == char.class && cast.targetType == String.class) {
invokeStatic(UTILITY_TYPE, CHAR_TO_STRING);
} else if (cast.from == String.class && cast.to == char.class) {
} else if (cast.originalType == String.class && cast.targetType == char.class) {
invokeStatic(UTILITY_TYPE, STRING_TO_CHAR);
} else if (cast.unboxFrom != null) {
unbox(getType(cast.unboxFrom));
writeCast(cast.from, cast.to);
} else if (cast.unboxTo != null) {
if (cast.from == def.class) {
if (cast.explicit) {
if (cast.to == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_EXPLICIT);
else if (cast.to == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_EXPLICIT);
else if (cast.to == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_EXPLICIT);
else if (cast.to == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_EXPLICIT);
else if (cast.to == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_EXPLICIT);
else if (cast.to == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_EXPLICIT);
else if (cast.to == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_EXPLICIT);
} else if (cast.unboxOriginalType != null) {
unbox(getType(cast.unboxOriginalType));
writeCast(cast.originalType, cast.targetType);
} else if (cast.unboxTargetType != null) {
if (cast.originalType == def.class) {
if (cast.explicitCast) {
if (cast.targetType == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.targetType == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_EXPLICIT);
else if (cast.targetType == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_EXPLICIT);
else if (cast.targetType == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_EXPLICIT);
else if (cast.targetType == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_EXPLICIT);
else if (cast.targetType == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_EXPLICIT);
else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_EXPLICIT);
else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_EXPLICIT);
else {
throw new IllegalStateException("Illegal tree structure.");
}
} else {
if (cast.to == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_IMPLICIT);
else if (cast.to == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_IMPLICIT);
else if (cast.to == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_IMPLICIT);
else if (cast.to == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_IMPLICIT);
else if (cast.to == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_IMPLICIT);
else if (cast.to == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_IMPLICIT);
else if (cast.to == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_IMPLICIT);
if (cast.targetType == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.targetType == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_IMPLICIT);
else if (cast.targetType == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_IMPLICIT);
else if (cast.targetType == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_IMPLICIT);
else if (cast.targetType == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_IMPLICIT);
else if (cast.targetType == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_IMPLICIT);
else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_IMPLICIT);
else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_IMPLICIT);
else {
throw new IllegalStateException("Illegal tree structure.");
}
}
} else {
writeCast(cast.from, cast.to);
unbox(getType(cast.unboxTo));
writeCast(cast.originalType, cast.targetType);
unbox(getType(cast.unboxTargetType));
}
} else if (cast.boxFrom != null) {
box(getType(cast.boxFrom));
writeCast(cast.from, cast.to);
} else if (cast.boxTo != null) {
writeCast(cast.from, cast.to);
box(getType(cast.boxTo));
} else if (cast.boxOriginalType != null) {
box(getType(cast.boxOriginalType));
writeCast(cast.originalType, cast.targetType);
} else if (cast.boxTargetType != null) {
writeCast(cast.originalType, cast.targetType);
box(getType(cast.boxTargetType));
} else {
writeCast(cast.from, cast.to);
writeCast(cast.originalType, cast.targetType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,55 @@
public class PainlessCast {

/** Create a standard cast with no boxing/unboxing. */
public static PainlessCast standard(Class<?> from, Class<?> to, boolean explicit) {
return new PainlessCast(from, to, explicit, null, null, null, null);
public static PainlessCast originalTypetoTargetType(Class<?> originalType, Class<?> targetType, boolean explicitCast) {
return new PainlessCast(originalType, targetType, explicitCast, null, null, null, null);
}

/** Create a cast where the from type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxFrom(Class<?> from, Class<?> to, boolean explicit, Class<?> unboxFrom) {
return new PainlessCast(from, to, explicit, unboxFrom, null, null, null);
/** Create a cast where the original type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxOriginalType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxOriginalType) {

return new PainlessCast(originalType, targetType, explicitCast, unboxOriginalType, null, null, null);
}

/** Create a cast where the to type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxTo(Class<?> from, Class<?> to, boolean explicit, Class<?> unboxTo) {
return new PainlessCast(from, to, explicit, null, unboxTo, null, null);
/** Create a cast where the target type will be unboxed, and then the cast will be performed. */
public static PainlessCast unboxTargetType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> unboxTargetType) {

return new PainlessCast(originalType, targetType, explicitCast, null, unboxTargetType, null, null);
}

/** Create a cast where the from type will be boxed, and then the cast will be performed. */
public static PainlessCast boxFrom(Class<?> from, Class<?> to, boolean explicit, Class<?> boxFrom) {
return new PainlessCast(from, to, explicit, null, null, boxFrom, null);
/** Create a cast where the original type will be boxed, and then the cast will be performed. */
public static PainlessCast boxOriginalType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxOriginalType) {

return new PainlessCast(originalType, targetType, explicitCast, null, null, boxOriginalType, null);
}

/** Create a cast where the to type will be boxed, and then the cast will be performed. */
public static PainlessCast boxTo(Class<?> from, Class<?> to, boolean explicit, Class<?> boxTo) {
return new PainlessCast(from, to, explicit, null, null, null, boxTo);
/** Create a cast where the target type will be boxed, and then the cast will be performed. */
public static PainlessCast boxTargetType(
Class<?> originalType, Class<?> targetType, boolean explicitCast, Class<?> boxTargetType) {

return new PainlessCast(originalType, targetType, explicitCast, null, null, null, boxTargetType);
}

public final Class<?> from;
public final Class<?> to;
public final boolean explicit;
public final Class<?> unboxFrom;
public final Class<?> unboxTo;
public final Class<?> boxFrom;
public final Class<?> boxTo;
public final Class<?> originalType;
public final Class<?> targetType;
public final boolean explicitCast;
public final Class<?> unboxOriginalType;
public final Class<?> unboxTargetType;
public final Class<?> boxOriginalType;
public final Class<?> boxTargetType;

private PainlessCast(Class<?> originalType, Class<?> targetType, boolean explicitCast,
Class<?> unboxOriginalType, Class<?> unboxTargetType, Class<?> boxOriginalType, Class<?> boxTargetType) {

private PainlessCast(Class<?> from, Class<?> to, boolean explicit,
Class<?> unboxFrom, Class<?> unboxTo, Class<?> boxFrom, Class<?> boxTo) {
this.from = from;
this.to = to;
this.explicit = explicit;
this.unboxFrom = unboxFrom;
this.unboxTo = unboxTo;
this.boxFrom = boxFrom;
this.boxTo = boxTo;
this.originalType = originalType;
this.targetType = targetType;
this.explicitCast = explicitCast;
this.unboxOriginalType = unboxOriginalType;
this.unboxTargetType = unboxTargetType;
this.boxOriginalType = boxOriginalType;
this.boxTargetType = boxTargetType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ void write(MethodWriter writer, Globals globals) {

@Override
public String toString() {
return singleLineToString(PainlessLookupUtility.typeToCanonicalTypeName(cast.to), child);
return singleLineToString(PainlessLookupUtility.typeToCanonicalTypeName(cast.targetType), child);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ private static void assertCast(Class<?> actual, Class<?> expected, boolean mustB
}

PainlessCast cast = AnalyzerCaster.getLegalCast(location, actual, expected, true, false);
assertEquals(actual, cast.from);
assertEquals(expected, cast.to);
assertEquals(actual, cast.originalType);
assertEquals(expected, cast.targetType);

if (mustBeExplicit) {
ClassCastException error = expectThrows(ClassCastException.class,
() -> AnalyzerCaster.getLegalCast(location, actual, expected, false, false));
assertTrue(error.getMessage().startsWith("Cannot cast"));
} else {
cast = AnalyzerCaster.getLegalCast(location, actual, expected, false, false);
assertEquals(actual, cast.from);
assertEquals(expected, cast.to);
assertEquals(actual, cast.originalType);
assertEquals(expected, cast.targetType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ public void testECapturingFunctionRef() {
public void testECast() {
Location l = new Location(getTestName(), 0);
AExpression child = new EConstant(l, "test");
PainlessCast cast = PainlessCast.standard(String.class, Integer.class, true);
PainlessCast cast = PainlessCast.originalTypetoTargetType(String.class, Integer.class, true);
assertEquals("(ECast java.lang.Integer (EConstant String 'test'))", new ECast(l, child, cast).toString());

l = new Location(getTestName(), 1);
child = new EBinary(l, Operation.ADD, new EConstant(l, "test"), new EConstant(l, 12));
cast = PainlessCast.standard(Integer.class, Boolean.class, true);
cast = PainlessCast.originalTypetoTargetType(Integer.class, Boolean.class, true);
assertEquals("(ECast java.lang.Boolean (EBinary (EConstant String 'test') + (EConstant Integer 12)))",
new ECast(l, child, cast).toString());
}
Expand Down