From b8546f9c7dcc70a41f9c23fbbe3d0a4635f93d00 Mon Sep 17 00:00:00 2001 From: Stan Hebben Date: Fri, 25 Oct 2024 22:02:47 +0200 Subject: [PATCH] Fixing expansions on recursive generic types --- .../codemodel/compilation/ResolvedType.java | 2 + .../codemodel/generic/TypeParameter.java | 6 +- .../codemodel/type/GenericTypeID.java | 3 +- .../zenscript/codemodel/type/TypeID.java | 2 +- .../zenscript/codemodel/type/TypeMatcher.java | 7 +- .../type/builtin/BasicTypeMembers.java | 513 ------------------ .../type/member/ExpandedResolvedType.java | 6 + .../codemodel/type/member/MemberSet.java | 5 + .../type/member/OptionalResolvedType.java | 5 + .../type/member/SubtypeResolvedType.java | 5 + .../java/module/JavaNativeTypeMembers.java | 5 + .../resources/zencode_tests/arrays/sort_1.zc | 2 +- .../resources/zencode_tests/arrays/sort_2.zc | 1 - .../expansions/expand_generic.zc | 33 ++ .../expansions/expand_generic_2.zc | 35 ++ 15 files changed, 106 insertions(+), 524 deletions(-) create mode 100644 ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic.zc create mode 100644 ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic_2.zc diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java index b5c8d3bba..1de912a8a 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java @@ -87,6 +87,8 @@ default boolean canCastImplicitlyTo(TypeID target) { List getInterfaceMethodsToImplement(); + boolean extendsOrImplements(TypeID type); + interface SwitchMember { SwitchValue toSwitchValue(List bindings); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java index 0bc553f6e..cc0308947 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java @@ -2,6 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zencode.shared.Taggable; +import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.type.TypeID; import java.util.ArrayList; @@ -31,9 +32,10 @@ public boolean isObjectType() { return false; } - public boolean matches(TypeID type) { + public boolean matches(TypeID type, GenericMapper mapper) { for (TypeParameterBound bound : bounds) { - if (!bound.matches(type)) + TypeParameterBound instanced = bound.instance(mapper); + if (!instanced.matches(type)) return false; } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java index 7bd9e38be..f3b7ed928 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java @@ -22,7 +22,8 @@ public GenericTypeID(TypeParameter parameter) { } public boolean matches(TypeID type) { - return parameter.matches(type); + GenericMapper mapper = GenericMapper.single(parameter, type); + return parameter.matches(type, mapper); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java index e8ede6c41..b4371e4a9 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java @@ -164,7 +164,7 @@ default ResolvedType resolveWithoutExpansions() { } default boolean extendsOrImplements(TypeID type) { - return false; + return resolveWithoutExpansions().extendsOrImplements(type); } /** diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java index c2fd6a187..026db71cf 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java @@ -26,15 +26,12 @@ public Boolean visitBasic(Matching context, BasicTypeID basic) { @Override public Boolean visitArray(Matching context, ArrayTypeID array) { - if (context.type instanceof ArrayTypeID) { - ArrayTypeID arrayType = (ArrayTypeID) context.type; + return context.type.asArray().map(arrayType -> { if (arrayType.dimension != array.dimension) return false; return match(context, arrayType.elementType, array.elementType); - } else { - return false; - } + }).orElse(false); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java index 389baa854..ff063412f 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java @@ -36,519 +36,6 @@ public static ResolvingType get(BasicTypeID type) { } } -/* private static MemberSet getBool() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.NOT, new MethodInstance(BuiltinMethodSymbol.BOOL_NOT)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.BOOL_AND)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.BOOL_OR)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.BOOL_XOR)); - builder.operator(OperatorType.EQUALS, new MethodInstance(BuiltinMethodSymbol.BOOL_EQUALS)); - builder.operator(OperatorType.NOTEQUALS, new MethodInstance(BuiltinMethodSymbol.BOOL_NOTEQUALS)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BOOL_TO_STRING)); - builder.staticMethod(new MethodInstance(BuiltinMethodSymbol.BOOL_PARSE)); - return builder.build(); - } - - private static MemberSet getByte() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.BYTE_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.BYTE_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.BYTE_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.BYTE_ADD_BYTE)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.BYTE_SUB_BYTE)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.BYTE_MUL_BYTE)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.BYTE_DIV_BYTE)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.BYTE_MOD_BYTE)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.BYTE_AND_BYTE)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.BYTE_OR_BYTE)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.BYTE_XOR_BYTE)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.BYTE_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.BYTE_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.BYTE_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.BYTE_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.BYTE_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.BYTE_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.BYTE_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.BYTE_MAX_VALUE)); - - comparator(builder, BuiltinMethodSymbol.BYTE_COMPARE, BasicTypeID.BYTE); - - return builder.build(); - } - - private static MemberSet getSByte() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.SBYTE_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.SBYTE_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.SBYTE_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.SBYTE_ADD_SBYTE)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.SBYTE_SUB_SBYTE)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.SBYTE_MUL_SBYTE)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.SBYTE_DIV_SBYTE)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.SBYTE_MOD_SBYTE)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.SBYTE_AND_SBYTE)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.SBYTE_OR_SBYTE)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.SBYTE_XOR_SBYTE)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.SBYTE_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.SBYTE_SHR)); - builder.operator(OperatorType.USHR, new MethodInstance(BuiltinMethodSymbol.SBYTE_USHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.SBYTE_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SBYTE_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.SBYTE_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.SBYTE_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.SBYTE_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.SBYTE_MAX_VALUE)); - - comparator(builder, BuiltinMethodSymbol.SBYTE_COMPARE, BasicTypeID.SBYTE); - - return builder.build(); - } - - private static MemberSet getShort() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.SHORT_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.SHORT_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.SHORT_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.SHORT_ADD_SHORT)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.SHORT_SUB_SHORT)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.SHORT_MUL_SHORT)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.SHORT_DIV_SHORT)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.SHORT_MOD_SHORT)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.SHORT_AND_SHORT)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.SHORT_OR_SHORT)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.SHORT_XOR_SHORT)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.SHORT_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.SHORT_SHR)); - builder.operator(OperatorType.USHR, new MethodInstance(BuiltinMethodSymbol.SHORT_USHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.SHORT_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.SHORT_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.SHORT_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.SHORT_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.SHORT_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.SHORT_MAX_VALUE)); - - comparator(builder, BuiltinMethodSymbol.SHORT_COMPARE, BasicTypeID.SHORT); - - return builder.build(); - } - - private static MemberSet getUShort() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.USHORT_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.USHORT_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.USHORT_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.USHORT_ADD_USHORT)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.USHORT_SUB_USHORT)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.USHORT_MUL_USHORT)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.USHORT_DIV_USHORT)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.USHORT_MOD_USHORT)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.USHORT_AND_USHORT)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.USHORT_OR_USHORT)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.USHORT_XOR_USHORT)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.USHORT_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.USHORT_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.USHORT_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USHORT_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.USHORT_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USHORT_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.USHORT_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.USHORT_MAX_VALUE)); - - comparator(builder, BuiltinMethodSymbol.USHORT_COMPARE, BasicTypeID.USHORT); - - return builder.build(); - } - - private static MemberSet getInt() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.INT_INVERT)); - builder.operator(OperatorType.NEG, new MethodInstance(BuiltinMethodSymbol.INT_NEG)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.INT_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.INT_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.INT_ADD_INT)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.INT_ADD_USIZE)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.INT_SUB_INT)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.INT_MUL_INT)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.INT_DIV_INT)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.INT_MOD_INT)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.INT_AND_INT)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.INT_OR_INT)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.INT_XOR_INT)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.INT_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.INT_SHR)); - builder.operator(OperatorType.USHR, new MethodInstance(BuiltinMethodSymbol.INT_USHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.INT_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.INT_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.INT_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.INT_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.INT_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.INT_MAX_VALUE)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_COUNT_LOW_ZEROES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_COUNT_HIGH_ZEROES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_COUNT_LOW_ONES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_COUNT_HIGH_ONES)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_HIGHEST_ONE_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_LOWEST_ONE_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_HIGHEST_ZERO_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_LOWEST_ZERO_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.INT_BIT_COUNT)); - - comparator(builder, BuiltinMethodSymbol.INT_COMPARE, BasicTypeID.INT); - - return builder.build(); - } - - private static MemberSet getUInt() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.UINT_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.UINT_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.UINT_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.UINT_ADD_UINT)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.UINT_SUB_UINT)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.UINT_MUL_UINT)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.UINT_DIV_UINT)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.UINT_MOD_UINT)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.UINT_AND_UINT)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.UINT_OR_UINT)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.UINT_XOR_UINT)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.UINT_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.UINT_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.UINT_COMPARE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.UINT_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.UINT_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.UINT_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.UINT_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.UINT_MAX_VALUE)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_COUNT_LOW_ZEROES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_COUNT_HIGH_ZEROES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_COUNT_LOW_ONES)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_COUNT_HIGH_ONES)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_HIGHEST_ONE_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_LOWEST_ONE_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_HIGHEST_ZERO_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_LOWEST_ZERO_BIT)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.UINT_BIT_COUNT)); - - comparator(builder, BuiltinMethodSymbol.UINT_COMPARE, BasicTypeID.UINT); - - return builder.build(); - } - - private static MemberSet getLong() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.LONG_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.LONG_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.LONG_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.LONG_ADD_LONG)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.LONG_SUB_LONG)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.LONG_MUL_LONG)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.LONG_DIV_LONG)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.LONG_MOD_LONG)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.LONG_AND_LONG)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.LONG_OR_LONG)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.LONG_XOR_LONG)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.LONG_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.LONG_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.LONG_COMPARE)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.LONG_COMPARE_INT)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.LONG_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.LONG_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.LONG_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.LONG_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.LONG_MAX_VALUE)); - - builder.getter("countLowZeroes", new MethodInstance(BuiltinMethodSymbol.LONG_COUNT_LOW_ZEROES)); - builder.getter("countHighZeroes", new MethodInstance(BuiltinMethodSymbol.LONG_COUNT_HIGH_ZEROES)); - builder.getter("countLowOnes", new MethodInstance(BuiltinMethodSymbol.LONG_COUNT_LOW_ONES)); - builder.getter("countHighOnes", new MethodInstance(BuiltinMethodSymbol.LONG_COUNT_HIGH_ONES)); - - builder.getter("highestOneBit", new MethodInstance(BuiltinMethodSymbol.LONG_HIGHEST_ONE_BIT)); - builder.getter("LowestOneBit", new MethodInstance(BuiltinMethodSymbol.LONG_LOWEST_ONE_BIT)); - builder.getter("highestZeroBit", new MethodInstance(BuiltinMethodSymbol.LONG_HIGHEST_ZERO_BIT)); - builder.getter("lowestZeroBit", new MethodInstance(BuiltinMethodSymbol.LONG_LOWEST_ZERO_BIT)); - builder.getter("bitCount", new MethodInstance(BuiltinMethodSymbol.LONG_BIT_COUNT)); - - comparator(builder, BuiltinMethodSymbol.LONG_COMPARE, BasicTypeID.LONG); - - return builder.build(); - } - - private static MemberSet getULong() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.ULONG_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.ULONG_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.ULONG_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.ULONG_ADD_ULONG)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.ULONG_SUB_ULONG)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.ULONG_MUL_ULONG)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.ULONG_DIV_ULONG)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.ULONG_MOD_ULONG)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.ULONG_AND_ULONG)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.ULONG_OR_ULONG)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.ULONG_XOR_ULONG)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.ULONG_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.ULONG_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.ULONG_COMPARE)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.ULONG_COMPARE_UINT)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.ULONG_COMPARE_USIZE)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_USIZE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.ULONG_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.ULONG_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.ULONG_PARSE_WITH_BASE)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.ULONG_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.ULONG_MAX_VALUE)); - - builder.getter("countLowZeroes", new MethodInstance(BuiltinMethodSymbol.ULONG_COUNT_LOW_ZEROES)); - builder.getter("countHighZeroes", new MethodInstance(BuiltinMethodSymbol.ULONG_COUNT_HIGH_ZEROES)); - builder.getter("countLowOnes", new MethodInstance(BuiltinMethodSymbol.ULONG_COUNT_LOW_ONES)); - builder.getter("countHighOnes", new MethodInstance(BuiltinMethodSymbol.ULONG_COUNT_HIGH_ONES)); - - builder.getter("highestOneBit", new MethodInstance(BuiltinMethodSymbol.ULONG_HIGHEST_ONE_BIT)); - builder.getter("LowestOneBit", new MethodInstance(BuiltinMethodSymbol.ULONG_LOWEST_ONE_BIT)); - builder.getter("highestZeroBit", new MethodInstance(BuiltinMethodSymbol.ULONG_HIGHEST_ZERO_BIT)); - builder.getter("lowestZeroBit", new MethodInstance(BuiltinMethodSymbol.ULONG_LOWEST_ZERO_BIT)); - builder.getter("bitCount", new MethodInstance(BuiltinMethodSymbol.ULONG_BIT_COUNT)); - - comparator(builder, BuiltinMethodSymbol.ULONG_COMPARE, BasicTypeID.ULONG); - - return builder.build(); - } - - private static MemberSet getUSize() { - MemberSet.Builder builder = MemberSet.create(); - builder.operator(OperatorType.INVERT, new MethodInstance(BuiltinMethodSymbol.USIZE_INVERT)); - builder.operator(OperatorType.INCREMENT, new MethodInstance(BuiltinMethodSymbol.USIZE_INC)); - builder.operator(OperatorType.DECREMENT, new MethodInstance(BuiltinMethodSymbol.USIZE_DEC)); - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.USIZE_ADD_USIZE)); - builder.operator(OperatorType.SUB, new MethodInstance(BuiltinMethodSymbol.USIZE_SUB_USIZE)); - builder.operator(OperatorType.MUL, new MethodInstance(BuiltinMethodSymbol.USIZE_MUL_USIZE)); - builder.operator(OperatorType.DIV, new MethodInstance(BuiltinMethodSymbol.USIZE_DIV_USIZE)); - builder.operator(OperatorType.MOD, new MethodInstance(BuiltinMethodSymbol.USIZE_MOD_USIZE)); - builder.operator(OperatorType.AND, new MethodInstance(BuiltinMethodSymbol.USIZE_AND_USIZE)); - builder.operator(OperatorType.OR, new MethodInstance(BuiltinMethodSymbol.USIZE_OR_USIZE)); - builder.operator(OperatorType.XOR, new MethodInstance(BuiltinMethodSymbol.USIZE_XOR_USIZE)); - builder.operator(OperatorType.SHL, new MethodInstance(BuiltinMethodSymbol.USIZE_SHL)); - builder.operator(OperatorType.SHR, new MethodInstance(BuiltinMethodSymbol.USIZE_SHR)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.USIZE_COMPARE)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.USIZE_COMPARE_UINT)); - - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_BYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_SBYTE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_SHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_USHORT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_INT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_UINT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_LONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_ULONG)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_FLOAT)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_DOUBLE)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_CHAR)); - builder.cast(new MethodInstance(BuiltinMethodSymbol.USIZE_TO_STRING)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_PARSE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_PARSE_WITH_BASE)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_COUNT_LOW_ZEROES)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_COUNT_HIGH_ZEROES)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_COUNT_LOW_ONES)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_COUNT_HIGH_ONES)); - - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_HIGHEST_ONE_BIT)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_LOWEST_ONE_BIT)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_HIGHEST_ZERO_BIT)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_LOWEST_ZERO_BIT)); - builder.method(new MethodInstance(BuiltinMethodSymbol.USIZE_BIT_COUNT)); - - builder.field(new FieldInstance(BuiltinFieldSymbol.USIZE_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.USIZE_MAX_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.USIZE_BITS)); - - comparator(builder, BuiltinMethodSymbol.USIZE_COMPARE, BasicTypeID.USIZE); - - return builder.build(); - } - - private static MemberSet getFloat() { - MemberSet.Builder builder = MemberSet.create(); - - setup(builder, BasicTypeID.FLOAT); - - builder.field(new FieldInstance(BuiltinFieldSymbol.FLOAT_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.FLOAT_MAX_VALUE)); - - return builder.build(); - } - - private static MemberSet getDouble() { - MemberSet.Builder builder = MemberSet.create(); - - for (BuiltinMethodSymbol method : BuiltinMethodSymbol.values()) { - if (method.getDefiningType() == BasicTypeID.DOUBLE) - builder.method(new MethodInstance(method)); - } - - builder.field(new FieldInstance(BuiltinFieldSymbol.DOUBLE_MIN_VALUE)); - builder.field(new FieldInstance(BuiltinFieldSymbol.DOUBLE_MAX_VALUE)); - - comparator(builder, BuiltinMethodSymbol.DOUBLE_COMPARE, BasicTypeID.DOUBLE); - - return builder.build(); - } - - private static MemberSet getChar() { - MemberSet.Builder builder = MemberSet.create(); - - for (BuiltinMethodSymbol method : BuiltinMethodSymbol.values()) { - if (method.getDefiningType() == BasicTypeID.CHAR) - builder.method(new MethodInstance(method)); - } - - comparator(builder, BuiltinMethodSymbol.CHAR_COMPARE, BasicTypeID.CHAR); - - return builder.build(); - } - - private static MemberSet getString() { - MemberSet.Builder builder = MemberSet.create(); - builder.constructor(new MethodInstance(BuiltinMethodSymbol.STRING_CONSTRUCTOR_CHARACTERS)); - - builder.operator(OperatorType.ADD, new MethodInstance(BuiltinMethodSymbol.STRING_ADD_STRING)); - builder.operator(OperatorType.COMPARE, new MethodInstance(BuiltinMethodSymbol.STRING_COMPARE)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.STRING_LENGTH)); - builder.indexGet(new MethodInstance(BuiltinMethodSymbol.STRING_INDEXGET)); - builder.indexGet(new MethodInstance(BuiltinMethodSymbol.STRING_RANGEGET)); - - builder.getter(new MethodInstance(BuiltinMethodSymbol.STRING_CHARACTERS)); - builder.getter(new MethodInstance(BuiltinMethodSymbol.STRING_ISEMPTY)); - builder.method(new MethodInstance(BuiltinMethodSymbol.STRING_REMOVE_DIACRITICS)); - builder.method(new MethodInstance(BuiltinMethodSymbol.STRING_TRIM)); - builder.method(new MethodInstance(BuiltinMethodSymbol.STRING_TO_LOWER_CASE)); - builder.method(new MethodInstance(BuiltinMethodSymbol.STRING_TO_UPPER_CASE)); - - builder.operator(OperatorType.CONTAINS, new MethodInstance(BuiltinMethodSymbol.STRING_CONTAINS_CHAR)); - builder.operator(OperatorType.CONTAINS, new MethodInstance(BuiltinMethodSymbol.STRING_CONTAINS_STRING)); - - comparator(builder, BuiltinMethodSymbol.STRING_COMPARE, BasicTypeID.STRING); - - return builder.build(); - }*/ - private static void setup(MemberSet.Builder builder, BasicTypeID type) { for (BuiltinMethodSymbol method : BuiltinMethodSymbol.values()) { if (method.getDefiningType().equals(type) && method.getID().equals(COMPARE)) { diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java index 250faa95e..ec087ba19 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java @@ -181,6 +181,12 @@ public List getInterfaceMethodsToImplement() { return base.getInterfaceMethodsToImplement(); } + @Override + public boolean extendsOrImplements(TypeID type) { + return base.extendsOrImplements(type) + || expansions.stream().anyMatch(expansion -> expansion.extendsOrImplements(type)); + } + @Override public Optional findField(String name) { return base.findField(name); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java index f0245535e..6a69fc5cd 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java @@ -130,6 +130,11 @@ public List getInterfaceMethodsToImplement() { return result; } + @Override + public boolean extendsOrImplements(TypeID type) { + return this.type.equals(type); + } + @Override public Optional findField(String name) { return Optional.ofNullable(fields.get(name)); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java index bcce4e0e4..ca812f51c 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java @@ -141,4 +141,9 @@ public Optional findStaticOperator(OperatorType operator) { public List getInterfaceMethodsToImplement() { return Collections.emptyList(); } + + @Override + public boolean extendsOrImplements(TypeID type) { + return this.type.equals(type); + } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubtypeResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubtypeResolvedType.java index eee98be6e..fcfdbaf84 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubtypeResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubtypeResolvedType.java @@ -174,6 +174,11 @@ public List getInterfaceMethodsToImplement() { .collect(Collectors.toList()); } + @Override + public boolean extendsOrImplements(TypeID type) { + return streamAllTypes().anyMatch(t -> t.extendsOrImplements(type)); + } + private Optional findFirstInLocalOrBaseTypes(Function> mapper) { return streamAllTypes() .map(mapper) diff --git a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java index ae898113f..899e3a406 100644 --- a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java +++ b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java @@ -114,6 +114,11 @@ public List getInterfaceMethodsToImplement() { return template.getInterfaceMethodsToImplement(); } + @Override + public boolean extendsOrImplements(TypeID type) { + return type.equals(this.type); // TODO + } + @Override public Optional findField(String name) { return template.getField(name).map(f -> new RuntimeField(mapper.map(f))); diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_1.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_1.zc index 43ea2415f..2b13e44a4 100644 --- a/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_1.zc +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_1.zc @@ -3,4 +3,4 @@ val a = [5, 1, 2, 4, 3]; a.sort(); -println(a); \ No newline at end of file +println(a); diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_2.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_2.zc index a7ec063ef..59b171f45 100644 --- a/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_2.zc +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/arrays/sort_2.zc @@ -1,4 +1,3 @@ -#disabled: currently broken because ZC cannot infer that the expansion for "> T[]" is applicable to TicketNumber[] #dependency: stdlib #output: T-2 #output: T-3 diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic.zc new file mode 100644 index 000000000..786473e51 --- /dev/null +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic.zc @@ -0,0 +1,33 @@ +#output: T-5 +#output: T-3 +#output: T-3 +#output: T-4 +#output: T-2 + +interface Comparable { + compareTo(other: T): int; +} + +expand > T[] { + sort(): void {} +} + +public class TicketNumber { + private var value as int; + + public implements Comparable { + compareTo(other) => this.value - other.value; + } + + public implicit as string => "T-" + value; +} + +val a = [ + new TicketNumber(5), + new TicketNumber(3), + new TicketNumber(3), + new TicketNumber(4), + new TicketNumber(2), +]; +a.sort(); +for ticket in a println(ticket); diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic_2.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic_2.zc new file mode 100644 index 000000000..d3cc184dc --- /dev/null +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/expansions/expand_generic_2.zc @@ -0,0 +1,35 @@ +#output: T-5 +#output: T-3 +#output: T-3 +#output: T-4 +#output: T-2 + +interface Comparable { + compareTo(other: T): int; +} + +expand > T[] { + sort(): void {} +} + +public class TicketNumber { + private var value as int; + + public implicit as string => "T-" + value; +} + +expand TicketNumber { + public implements Comparable { + compareTo(other) => this.value - other.value; + } +} + +val a = [ + new TicketNumber(5), + new TicketNumber(3), + new TicketNumber(3), + new TicketNumber(4), + new TicketNumber(2), +]; +a.sort(); +for ticket in a println(ticket);