|
@@ -71,6 +71,7 @@ import org.openzen.zenscript.codemodel.Module;
|
71
|
71
|
import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
|
72
|
72
|
import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
|
73
|
73
|
import org.openzen.zenscript.codemodel.member.IteratorMember;
|
|
74
|
+import org.openzen.zenscript.codemodel.type.StringTypeID;
|
74
|
75
|
import org.openzen.zenscript.codemodel.type.TypeVisitor;
|
75
|
76
|
|
76
|
77
|
/**
|
|
@@ -163,13 +164,36 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
163
|
164
|
case CHAR:
|
164
|
165
|
visitChar();
|
165
|
166
|
break;
|
166
|
|
- case STRING:
|
167
|
|
- visitString();
|
168
|
|
- break;
|
169
|
167
|
}
|
170
|
168
|
|
171
|
169
|
return null;
|
172
|
170
|
}
|
|
171
|
+
|
|
172
|
+ @Override
|
|
173
|
+ public Void visitString(StringTypeID string) {
|
|
174
|
+ ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "string", Modifiers.EXPORT, null);
|
|
175
|
+
|
|
176
|
+ constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
|
|
177
|
+
|
|
178
|
+ add(builtin, STRING_ADD_STRING, StringTypeID.BORROW, StringTypeID.UNIQUE);
|
|
179
|
+ indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
|
|
180
|
+ indexGet(builtin, STRING_RANGEGET, RangeTypeID.USIZE, StringTypeID.UNIQUE);
|
|
181
|
+ compare(builtin, STRING_COMPARE, StringTypeID.BORROW);
|
|
182
|
+
|
|
183
|
+ getter(builtin, STRING_LENGTH, "length", USIZE);
|
|
184
|
+ getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
|
|
185
|
+ getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
|
|
186
|
+
|
|
187
|
+ method(builtin, STRING_REMOVE_DIACRITICS, "removeDiacritics", StringTypeID.BORROW);
|
|
188
|
+ method(builtin, STRING_TRIM, "trim", StringTypeID.BORROW, StringTypeID.UNIQUE);
|
|
189
|
+ method(builtin, STRING_TO_LOWER_CASE, "toLowerCase", StringTypeID.UNIQUE);
|
|
190
|
+ method(builtin, STRING_TO_UPPER_CASE, "toUpperCase", StringTypeID.UNIQUE);
|
|
191
|
+
|
|
192
|
+ iterator(builtin, ITERATOR_STRING_CHARS, CHAR);
|
|
193
|
+
|
|
194
|
+ processType(builtin, string);
|
|
195
|
+ return null;
|
|
196
|
+ }
|
173
|
197
|
|
174
|
198
|
@Override
|
175
|
199
|
public Void visitArray(ArrayTypeID array) {
|
|
@@ -464,7 +488,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
464
|
488
|
}
|
465
|
489
|
|
466
|
490
|
if (definition instanceof EnumDefinition) {
|
467
|
|
- getter(definition, ENUM_NAME, "name", STRING);
|
|
491
|
+ getter(definition, ENUM_NAME, "name", StringTypeID.STATIC);
|
468
|
492
|
getter(definition, ENUM_ORDINAL, "ordinal", USIZE);
|
469
|
493
|
|
470
|
494
|
List<EnumConstantMember> enumConstants = ((EnumDefinition) definition).enumConstants;
|
|
@@ -475,8 +499,8 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
475
|
499
|
constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(type, 1)));
|
476
|
500
|
compare(definition, ENUM_COMPARE, type);
|
477
|
501
|
|
478
|
|
- if (!members.canCast(BasicTypeID.STRING)) {
|
479
|
|
- castImplicit(definition, ENUM_TO_STRING, STRING);
|
|
502
|
+ if (!members.canCast(StringTypeID.STATIC)) {
|
|
503
|
+ castImplicit(definition, ENUM_TO_STRING, StringTypeID.STATIC);
|
480
|
504
|
}
|
481
|
505
|
}
|
482
|
506
|
|
|
@@ -556,8 +580,8 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
556
|
580
|
equals(builtin, BOOL_EQUALS, BOOL);
|
557
|
581
|
notequals(builtin, BOOL_NOTEQUALS, BOOL);
|
558
|
582
|
|
559
|
|
- castExplicit(builtin, BOOL_TO_STRING, STRING);
|
560
|
|
- staticMethod(builtin, BOOL_PARSE, "parse", BOOL, STRING);
|
|
583
|
+ castExplicit(builtin, BOOL_TO_STRING, StringTypeID.STATIC);
|
|
584
|
+ staticMethod(builtin, BOOL_PARSE, "parse", BOOL, StringTypeID.BORROW);
|
561
|
585
|
|
562
|
586
|
processType(builtin, BOOL);
|
563
|
587
|
}
|
|
@@ -591,10 +615,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
591
|
615
|
castImplicit(builtin, BYTE_TO_FLOAT, FLOAT);
|
592
|
616
|
castImplicit(builtin, BYTE_TO_DOUBLE, DOUBLE);
|
593
|
617
|
castExplicit(builtin, BYTE_TO_CHAR, CHAR);
|
594
|
|
- castImplicit(builtin, BYTE_TO_STRING, STRING);
|
|
618
|
+ castImplicit(builtin, BYTE_TO_STRING, StringTypeID.UNIQUE);
|
595
|
619
|
|
596
|
|
- staticMethod(builtin, BYTE_PARSE, "parse", BYTE, STRING);
|
597
|
|
- staticMethod(builtin, BYTE_PARSE_WITH_BASE, "parse", BYTE, STRING, INT);
|
|
620
|
+ staticMethod(builtin, BYTE_PARSE, "parse", BYTE, StringTypeID.BORROW);
|
|
621
|
+ staticMethod(builtin, BYTE_PARSE_WITH_BASE, "parse", BYTE, StringTypeID.BORROW, INT);
|
598
|
622
|
|
599
|
623
|
constant(builtin, BYTE_GET_MIN_VALUE, "MIN_VALUE", new ConstantByteExpression(BUILTIN, 0));
|
600
|
624
|
constant(builtin, BYTE_GET_MAX_VALUE, "MAX_VALUE", new ConstantByteExpression(BUILTIN, 255));
|
|
@@ -633,10 +657,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
633
|
657
|
castImplicit(builtin, SBYTE_TO_FLOAT, FLOAT);
|
634
|
658
|
castImplicit(builtin, SBYTE_TO_DOUBLE, DOUBLE);
|
635
|
659
|
castExplicit(builtin, SBYTE_TO_CHAR, CHAR);
|
636
|
|
- castImplicit(builtin, SBYTE_TO_STRING, STRING);
|
|
660
|
+ castImplicit(builtin, SBYTE_TO_STRING, StringTypeID.UNIQUE);
|
637
|
661
|
|
638
|
|
- staticMethod(builtin, SBYTE_PARSE, "parse", SBYTE, STRING);
|
639
|
|
- staticMethod(builtin, SBYTE_PARSE_WITH_BASE, "parse", SBYTE, STRING, INT);
|
|
662
|
+ staticMethod(builtin, SBYTE_PARSE, "parse", SBYTE, StringTypeID.BORROW);
|
|
663
|
+ staticMethod(builtin, SBYTE_PARSE_WITH_BASE, "parse", SBYTE, StringTypeID.BORROW, INT);
|
640
|
664
|
|
641
|
665
|
constant(builtin, SBYTE_GET_MIN_VALUE, "MIN_VALUE", new ConstantSByteExpression(BUILTIN, Byte.MIN_VALUE));
|
642
|
666
|
constant(builtin, SBYTE_GET_MAX_VALUE, "MAX_VALUE", new ConstantSByteExpression(BUILTIN, Byte.MAX_VALUE));
|
|
@@ -675,10 +699,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
675
|
699
|
castImplicit(builtin, SHORT_TO_FLOAT, FLOAT);
|
676
|
700
|
castImplicit(builtin, SHORT_TO_DOUBLE, DOUBLE);
|
677
|
701
|
castExplicit(builtin, SHORT_TO_CHAR, CHAR);
|
678
|
|
- castImplicit(builtin, SHORT_TO_STRING, STRING);
|
|
702
|
+ castImplicit(builtin, SHORT_TO_STRING, StringTypeID.UNIQUE);
|
679
|
703
|
|
680
|
|
- staticMethod(builtin, SHORT_PARSE, "parse", SHORT, STRING);
|
681
|
|
- staticMethod(builtin, SHORT_PARSE_WITH_BASE, "parse", SHORT, STRING, INT);
|
|
704
|
+ staticMethod(builtin, SHORT_PARSE, "parse", SHORT, StringTypeID.BORROW);
|
|
705
|
+ staticMethod(builtin, SHORT_PARSE_WITH_BASE, "parse", SHORT, StringTypeID.BORROW, INT);
|
682
|
706
|
|
683
|
707
|
constant(builtin, SHORT_GET_MIN_VALUE, "MIN_VALUE", new ConstantShortExpression(BUILTIN, Short.MIN_VALUE));
|
684
|
708
|
constant(builtin, SHORT_GET_MAX_VALUE, "MAX_VALUE", new ConstantShortExpression(BUILTIN, Short.MAX_VALUE));
|
|
@@ -715,10 +739,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
715
|
739
|
castImplicit(builtin, USHORT_TO_FLOAT, FLOAT);
|
716
|
740
|
castImplicit(builtin, USHORT_TO_DOUBLE, DOUBLE);
|
717
|
741
|
castExplicit(builtin, USHORT_TO_CHAR, CHAR);
|
718
|
|
- castImplicit(builtin, USHORT_TO_STRING, STRING);
|
|
742
|
+ castImplicit(builtin, USHORT_TO_STRING, StringTypeID.UNIQUE);
|
719
|
743
|
|
720
|
|
- staticMethod(builtin, USHORT_PARSE, "parse", USHORT, STRING);
|
721
|
|
- staticMethod(builtin, USHORT_PARSE_WITH_BASE, "parse", USHORT, STRING, INT);
|
|
744
|
+ staticMethod(builtin, USHORT_PARSE, "parse", USHORT, StringTypeID.BORROW);
|
|
745
|
+ staticMethod(builtin, USHORT_PARSE_WITH_BASE, "parse", USHORT, StringTypeID.BORROW, INT);
|
722
|
746
|
|
723
|
747
|
constant(builtin, USHORT_GET_MIN_VALUE, "MIN_VALUE", new ConstantUShortExpression(BUILTIN, 0));
|
724
|
748
|
constant(builtin, USHORT_GET_MAX_VALUE, "MAX_VALUE", new ConstantUShortExpression(BUILTIN, 65535));
|
|
@@ -787,10 +811,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
787
|
811
|
castImplicit(builtin, INT_TO_FLOAT, FLOAT);
|
788
|
812
|
castImplicit(builtin, INT_TO_DOUBLE, DOUBLE);
|
789
|
813
|
castExplicit(builtin, INT_TO_CHAR, CHAR);
|
790
|
|
- castImplicit(builtin, INT_TO_STRING, STRING);
|
|
814
|
+ castImplicit(builtin, INT_TO_STRING, StringTypeID.UNIQUE);
|
791
|
815
|
|
792
|
|
- staticMethod(builtin, INT_PARSE, "parse", INT, STRING);
|
793
|
|
- staticMethod(builtin, INT_PARSE_WITH_BASE, "parse", INT, STRING, INT);
|
|
816
|
+ staticMethod(builtin, INT_PARSE, "parse", INT, StringTypeID.BORROW);
|
|
817
|
+ staticMethod(builtin, INT_PARSE_WITH_BASE, "parse", INT, StringTypeID.BORROW, INT);
|
794
|
818
|
|
795
|
819
|
method(builtin, INT_COUNT_LOW_ZEROES, "countLowZeroes", INT);
|
796
|
820
|
method(builtin, INT_COUNT_HIGH_ZEROES, "countHighZeroes", INT);
|
|
@@ -866,10 +890,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
866
|
890
|
castImplicit(builtin, UINT_TO_FLOAT, FLOAT);
|
867
|
891
|
castImplicit(builtin, UINT_TO_DOUBLE, DOUBLE);
|
868
|
892
|
castExplicit(builtin, UINT_TO_CHAR, CHAR);
|
869
|
|
- castImplicit(builtin, UINT_TO_STRING, STRING);
|
|
893
|
+ castImplicit(builtin, UINT_TO_STRING, StringTypeID.UNIQUE);
|
870
|
894
|
|
871
|
|
- staticMethod(builtin, UINT_PARSE, "parse", UINT, STRING);
|
872
|
|
- staticMethod(builtin, UINT_PARSE_WITH_BASE, "parse", UINT, STRING, INT);
|
|
895
|
+ staticMethod(builtin, UINT_PARSE, "parse", UINT, StringTypeID.BORROW);
|
|
896
|
+ staticMethod(builtin, UINT_PARSE_WITH_BASE, "parse", UINT, StringTypeID.BORROW, INT);
|
873
|
897
|
|
874
|
898
|
method(builtin, UINT_COUNT_LOW_ZEROES, "countLowZeroes", UINT);
|
875
|
899
|
method(builtin, UINT_COUNT_HIGH_ZEROES, "countHighZeroes", UINT);
|
|
@@ -939,10 +963,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
939
|
963
|
castImplicit(builtin, LONG_TO_FLOAT, FLOAT);
|
940
|
964
|
castImplicit(builtin, LONG_TO_DOUBLE, DOUBLE);
|
941
|
965
|
castExplicit(builtin, LONG_TO_CHAR, CHAR);
|
942
|
|
- castImplicit(builtin, LONG_TO_STRING, STRING);
|
|
966
|
+ castImplicit(builtin, LONG_TO_STRING, StringTypeID.UNIQUE);
|
943
|
967
|
|
944
|
|
- staticMethod(builtin, LONG_PARSE, "parse", LONG, STRING);
|
945
|
|
- staticMethod(builtin, LONG_PARSE_WITH_BASE, "parse", LONG, STRING, INT);
|
|
968
|
+ staticMethod(builtin, LONG_PARSE, "parse", LONG, StringTypeID.BORROW);
|
|
969
|
+ staticMethod(builtin, LONG_PARSE_WITH_BASE, "parse", LONG, StringTypeID.BORROW, INT);
|
946
|
970
|
|
947
|
971
|
method(builtin, LONG_COUNT_LOW_ZEROES, "countLowZeroes", INT);
|
948
|
972
|
method(builtin, LONG_COUNT_HIGH_ZEROES, "countHighZeroes", INT);
|
|
@@ -1011,10 +1035,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1011
|
1035
|
castImplicit(builtin, ULONG_TO_FLOAT, FLOAT);
|
1012
|
1036
|
castImplicit(builtin, ULONG_TO_DOUBLE, DOUBLE);
|
1013
|
1037
|
castExplicit(builtin, ULONG_TO_CHAR, CHAR);
|
1014
|
|
- castImplicit(builtin, ULONG_TO_STRING, STRING);
|
|
1038
|
+ castImplicit(builtin, ULONG_TO_STRING, StringTypeID.UNIQUE);
|
1015
|
1039
|
|
1016
|
|
- staticMethod(builtin, ULONG_PARSE, "parse", ULONG, STRING);
|
1017
|
|
- staticMethod(builtin, ULONG_PARSE_WITH_BASE, "parse", ULONG, STRING, INT);
|
|
1040
|
+ staticMethod(builtin, ULONG_PARSE, "parse", ULONG, StringTypeID.BORROW);
|
|
1041
|
+ staticMethod(builtin, ULONG_PARSE_WITH_BASE, "parse", ULONG, StringTypeID.BORROW, INT);
|
1018
|
1042
|
|
1019
|
1043
|
method(builtin, ULONG_COUNT_LOW_ZEROES, "countLowZeroes", INT);
|
1020
|
1044
|
method(builtin, ULONG_COUNT_HIGH_ZEROES, "countHighZeroes", INT);
|
|
@@ -1088,10 +1112,10 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1088
|
1112
|
castImplicit(builtin, USIZE_TO_FLOAT, FLOAT);
|
1089
|
1113
|
castImplicit(builtin, USIZE_TO_DOUBLE, DOUBLE);
|
1090
|
1114
|
castExplicit(builtin, USIZE_TO_CHAR, CHAR);
|
1091
|
|
- castImplicit(builtin, USIZE_TO_STRING, STRING);
|
|
1115
|
+ castImplicit(builtin, USIZE_TO_STRING, StringTypeID.UNIQUE);
|
1092
|
1116
|
|
1093
|
|
- staticMethod(builtin, USIZE_PARSE, "parse", USIZE, STRING);
|
1094
|
|
- staticMethod(builtin, USIZE_PARSE_WITH_BASE, "parse", USIZE, STRING, INT);
|
|
1117
|
+ staticMethod(builtin, USIZE_PARSE, "parse", USIZE, StringTypeID.BORROW);
|
|
1118
|
+ staticMethod(builtin, USIZE_PARSE_WITH_BASE, "parse", USIZE, StringTypeID.BORROW, INT);
|
1095
|
1119
|
|
1096
|
1120
|
method(builtin, USIZE_COUNT_LOW_ZEROES, "countLowZeroes", INT);
|
1097
|
1121
|
method(builtin, USIZE_COUNT_HIGH_ZEROES, "countHighZeroes", INT);
|
|
@@ -1143,9 +1167,9 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1143
|
1167
|
castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
|
1144
|
1168
|
castExplicit(builtin, FLOAT_TO_USIZE, USIZE);
|
1145
|
1169
|
castImplicit(builtin, FLOAT_TO_DOUBLE, DOUBLE);
|
1146
|
|
- castImplicit(builtin, FLOAT_TO_STRING, STRING);
|
|
1170
|
+ castImplicit(builtin, FLOAT_TO_STRING, StringTypeID.UNIQUE);
|
1147
|
1171
|
|
1148
|
|
- staticMethod(builtin, FLOAT_PARSE, "parse", FLOAT, STRING);
|
|
1172
|
+ staticMethod(builtin, FLOAT_PARSE, "parse", FLOAT, StringTypeID.BORROW);
|
1149
|
1173
|
staticMethod(builtin, FLOAT_FROM_BITS, "fromBits", FLOAT, UINT);
|
1150
|
1174
|
|
1151
|
1175
|
getter(builtin, FLOAT_BITS, "bits", UINT);
|
|
@@ -1179,9 +1203,9 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1179
|
1203
|
castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
|
1180
|
1204
|
castExplicit(builtin, DOUBLE_TO_USIZE, USIZE);
|
1181
|
1205
|
castImplicit(builtin, DOUBLE_TO_FLOAT, FLOAT);
|
1182
|
|
- castImplicit(builtin, DOUBLE_TO_STRING, STRING);
|
|
1206
|
+ castImplicit(builtin, DOUBLE_TO_STRING, StringTypeID.UNIQUE);
|
1183
|
1207
|
|
1184
|
|
- staticMethod(builtin, DOUBLE_PARSE, "parse", DOUBLE, STRING);
|
|
1208
|
+ staticMethod(builtin, DOUBLE_PARSE, "parse", DOUBLE, StringTypeID.BORROW);
|
1185
|
1209
|
staticMethod(builtin, DOUBLE_FROM_BITS, "fromBits", DOUBLE, ULONG);
|
1186
|
1210
|
|
1187
|
1211
|
getter(builtin, DOUBLE_BITS, "bits", ULONG);
|
|
@@ -1206,7 +1230,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1206
|
1230
|
castImplicit(builtin, CHAR_TO_LONG, LONG);
|
1207
|
1231
|
castImplicit(builtin, CHAR_TO_ULONG, ULONG);
|
1208
|
1232
|
castImplicit(builtin, CHAR_TO_USIZE, USIZE);
|
1209
|
|
- castImplicit(builtin, CHAR_TO_STRING, STRING);
|
|
1233
|
+ castImplicit(builtin, CHAR_TO_STRING, StringTypeID.UNIQUE);
|
1210
|
1234
|
|
1211
|
1235
|
getter(builtin, CHAR_GET_MIN_VALUE, "MIN_VALUE", CHAR);
|
1212
|
1236
|
getter(builtin, CHAR_GET_MAX_VALUE, "MAX_VALUE", CHAR);
|
|
@@ -1217,30 +1241,6 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
|
1217
|
1241
|
|
1218
|
1242
|
processType(builtin, CHAR);
|
1219
|
1243
|
}
|
1220
|
|
-
|
1221
|
|
- private void visitString() {
|
1222
|
|
- ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "string", Modifiers.EXPORT, null);
|
1223
|
|
-
|
1224
|
|
- constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
|
1225
|
|
-
|
1226
|
|
- add(builtin, STRING_ADD_STRING, STRING, STRING);
|
1227
|
|
- indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
|
1228
|
|
- indexGet(builtin, STRING_RANGEGET, RangeTypeID.USIZE, STRING);
|
1229
|
|
- compare(builtin, STRING_COMPARE, STRING);
|
1230
|
|
-
|
1231
|
|
- getter(builtin, STRING_LENGTH, "length", USIZE);
|
1232
|
|
- getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
|
1233
|
|
- getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
|
1234
|
|
-
|
1235
|
|
- method(builtin, STRING_REMOVE_DIACRITICS, "removeDiacritics", STRING);
|
1236
|
|
- method(builtin, STRING_TRIM, "trim", STRING, STRING);
|
1237
|
|
- method(builtin, STRING_TO_LOWER_CASE, "toLowerCase", STRING);
|
1238
|
|
- method(builtin, STRING_TO_UPPER_CASE, "toUpperCase", STRING);
|
1239
|
|
-
|
1240
|
|
- iterator(builtin, ITERATOR_STRING_CHARS, CHAR);
|
1241
|
|
-
|
1242
|
|
- processType(builtin, STRING);
|
1243
|
|
- }
|
1244
|
1244
|
|
1245
|
1245
|
private void castedTargetCall(OperatorMember member, ITypeID toType, BuiltinID casterBuiltin) {
|
1246
|
1246
|
CasterMemberRef caster = castImplicitRef(member.definition, casterBuiltin, toType);
|