Skip to content

Commit 5f445c8

Browse files
committed
Reverse forwarders
1 parent b8e3d07 commit 5f445c8

9 files changed

Lines changed: 79 additions & 82 deletions

File tree

src/main/java/com/laytonsmith/core/constructs/CClassType.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ public CClassType typeof() {
594594
// so we just specifically support enums for now.
595595
@Override
596596
public Mixed get(String index, Target t) throws ConfigRuntimeException {
597+
return get(index, t, null);
598+
}
599+
600+
@Override
601+
public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException {
597602
if(isEnum()) {
598603
try {
599604
return NativeTypeList.getNativeEnumType(fqcn).get(index, t);
@@ -605,12 +610,12 @@ public Mixed get(String index, Target t) throws ConfigRuntimeException {
605610
}
606611

607612
@Override
608-
public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException {
609-
return get(index, t);
613+
public Mixed get(int index, Target t) throws ConfigRuntimeException {
614+
return get(index, t, null);
610615
}
611616

612617
@Override
613-
public Mixed get(int index, Target t) throws ConfigRuntimeException {
618+
public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException {
614619
if(isEnum()) {
615620
try {
616621
return NativeTypeList.getNativeEnumType(fqcn).get(index, t);
@@ -622,12 +627,12 @@ public Mixed get(int index, Target t) throws ConfigRuntimeException {
622627
}
623628

624629
@Override
625-
public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException {
626-
return get(index, t);
630+
public Mixed get(Mixed index, Target t) throws ConfigRuntimeException {
631+
return get(index, t, null);
627632
}
628633

629634
@Override
630-
public Mixed get(Mixed index, Target t) throws ConfigRuntimeException {
635+
public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException {
631636
if(isEnum()) {
632637
try {
633638
return NativeTypeList.getNativeEnumType(fqcn).get(index, t);
@@ -639,12 +644,12 @@ public Mixed get(Mixed index, Target t) throws ConfigRuntimeException {
639644
}
640645

641646
@Override
642-
public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException {
643-
return get(index, t);
647+
public Set<Mixed> keySet() {
648+
return keySet(null);
644649
}
645650

646651
@Override
647-
public Set<Mixed> keySet() {
652+
public Set<Mixed> keySet(Environment env) {
648653
if(isEnum()) {
649654
try {
650655
return NativeTypeList.getNativeEnumType(fqcn).keySet();
@@ -656,12 +661,12 @@ public Set<Mixed> keySet() {
656661
}
657662

658663
@Override
659-
public Set<Mixed> keySet(Environment env) {
660-
return keySet();
664+
public long size() {
665+
return size(null);
661666
}
662667

663668
@Override
664-
public long size() {
669+
public long size(Environment env) {
665670
if(isEnum()) {
666671
try {
667672
return NativeTypeList.getNativeEnumType(fqcn).size();
@@ -672,11 +677,6 @@ public long size() {
672677
return 0;
673678
}
674679

675-
@Override
676-
public long size(Environment env) {
677-
return size();
678-
}
679-
680680
@Override
681681
public boolean isAssociative() {
682682
return true;
@@ -689,12 +689,12 @@ public boolean canBeAssociative() {
689689

690690
@Override
691691
public Mixed slice(int begin, int end, Target t) {
692-
throw new CREUnsupportedOperationException("Unsupported operation", t);
692+
return slice(begin, end, t, null);
693693
}
694694

695695
@Override
696696
public Mixed slice(int begin, int end, Target t, Environment env) {
697-
return slice(begin, end, t);
697+
throw new CREUnsupportedOperationException("Unsupported operation", t);
698698
}
699699

700700
/**
@@ -709,12 +709,12 @@ public Class<? extends Mixed> getNativeType() {
709709

710710
@Override
711711
public boolean getBooleanValue(Target t) {
712-
return true;
712+
return getBooleanValue(null, t);
713713
}
714714

715715
@Override
716716
public boolean getBooleanValue(Environment env, Target t) {
717-
return getBooleanValue(t);
717+
return true;
718718
}
719719

720720
/**

src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,39 +157,44 @@ public boolean isAssociative() {
157157

158158
@Override
159159
public CReal2dMatrixRow get(Mixed index, Target t) throws ConfigRuntimeException {
160-
return get(ArgumentValidation.getInt32(index, t), t);
160+
return (CReal2dMatrixRow) get(index, t, null);
161161
}
162162

163163
@Override
164164
public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException {
165-
return get(index, t);
165+
return get(ArgumentValidation.getInt32(index, t), t, env);
166166
}
167167

168168
@Override
169169
public Mixed get(String index, Target t) throws ConfigRuntimeException {
170-
throw new CREIllegalArgumentException("Matrices cannot be indexed into with non-numeric values.", t);
170+
return get(index, t, null);
171171
}
172172

173173
@Override
174174
public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException {
175-
return get(index, t);
175+
throw new CREIllegalArgumentException("Matrices cannot be indexed into with non-numeric values.", t);
176176
}
177177

178178
@Override
179179
public CReal2dMatrixRow get(int index, Target t) throws ConfigRuntimeException {
180+
return (CReal2dMatrixRow) get(index, t, null);
181+
}
182+
183+
@Override
184+
public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException {
180185
if(index >= getRowCount() || index < 0) {
181186
throw new CRERangeException("Matrix range out of bounds.", t);
182187
}
183188
return new CReal2dMatrixRow(this, index);
184189
}
185190

186191
@Override
187-
public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException {
188-
return get(index, t);
192+
public Set<Mixed> keySet() {
193+
return keySet(null);
189194
}
190195

191196
@Override
192-
public Set<Mixed> keySet() {
197+
public Set<Mixed> keySet(Environment env) {
193198
Set<Mixed> set = new HashSet<>();
194199
for(int i = 0; i < getRowCount(); i++) {
195200
set.add(new CInt(i, Target.UNKNOWN));
@@ -198,22 +203,22 @@ public Set<Mixed> keySet() {
198203
}
199204

200205
@Override
201-
public Set<Mixed> keySet(Environment env) {
202-
return keySet();
206+
public boolean getBooleanValue(Target t) {
207+
return getBooleanValue(null, t);
203208
}
204209

205210
@Override
206-
public boolean getBooleanValue(Target t) {
211+
public boolean getBooleanValue(Environment env, Target t) {
207212
return data.length != 0;
208213
}
209214

210215
@Override
211-
public boolean getBooleanValue(Environment env, Target t) {
212-
return getBooleanValue(t);
216+
public CArray slice(int begin, int end, Target t) {
217+
return (CArray) slice(begin, end, t, null);
213218
}
214219

215220
@Override
216-
public CArray slice(int begin, int end, Target t) {
221+
public Mixed slice(int begin, int end, Target t, Environment env) {
217222
CArray ret = new CArray(t);
218223
int step = (begin <= end) ? 1 : -1;
219224

@@ -230,19 +235,14 @@ public CArray slice(int begin, int end, Target t) {
230235
return ret;
231236
}
232237

233-
@Override
234-
public Mixed slice(int begin, int end, Target t, Environment env) {
235-
return slice(begin, end, t);
236-
}
237-
238238
@Override
239239
public long size() {
240-
return getRowCount();
240+
return size(null);
241241
}
242242

243243
@Override
244244
public long size(Environment env) {
245-
return size();
245+
return getRowCount();
246246
}
247247

248248
public CReal2dMatrix deepClone() {

src/main/java/com/laytonsmith/core/constructs/Construct.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ protected String getQuote() {
501501
*/
502502
@Override
503503
public CClassType typeof() {
504-
return typeof(this);
504+
return typeof((Environment) null);
505505
}
506506

507507
/**
@@ -516,7 +516,7 @@ public static CClassType typeof(Mixed that) {
516516

517517
@Override
518518
public CClassType typeof(Environment env) {
519-
return typeof();
519+
return typeof(this);
520520
}
521521

522522
/**
@@ -615,10 +615,7 @@ public static boolean isInstanceof(Mixed that, Class<? extends Mixed> type) {
615615

616616
@Override
617617
public boolean isInstanceOf(CClassType type) {
618-
if(type.getNativeType() != null) {
619-
return type.getNativeType().isAssignableFrom(this.getClass());
620-
}
621-
return isInstanceof(this, type);
618+
return isInstanceOf(type, null, null);
622619
}
623620

624621
@Override
@@ -628,7 +625,10 @@ public boolean isInstanceOf(Class<? extends Mixed> type) {
628625

629626
@Override
630627
public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) {
631-
return isInstanceOf(type);
628+
if(type.getNativeType() != null) {
629+
return type.getNativeType().isAssignableFrom(this.getClass());
630+
}
631+
return isInstanceof(this, type);
632632
}
633633

634634
@Override

src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public static boolean isInstanceof(Mixed value, FullyQualifiedClassName instance
7171
if(instanceofThis.getFQCN().equals("auto")) {
7272
return true;
7373
}
74-
if(value instanceof CNull) {
75-
return true;
76-
}
7774
if(value instanceof CFunction) {
7875
// TODO: Need to put the return type here, so we can work with this, but for now, just always return false
7976
return false;
@@ -91,7 +88,7 @@ public static boolean isInstanceof(Mixed value, FullyQualifiedClassName instance
9188
*/
9289
public static boolean isInstanceof(CClassType type, FullyQualifiedClassName instanceofThis, Environment env) {
9390
Static.AssertNonNull(instanceofThis, "instanceofThis may not be null");
94-
if(instanceofThis.getFQCN().equals("auto") || type == CNull.TYPE) {
91+
if(instanceofThis.getFQCN().equals("auto")) {
9592
return true;
9693
}
9794
for(CClassType c : getAllCastableClasses(type, env)) {

src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public CClassType[] getSuperclasses() {
323323

324324
@Override
325325
public boolean isInstanceOf(CClassType type) {
326-
return Construct.isInstanceof(this, type);
326+
return isInstanceOf(type, null, null);
327327
}
328328

329329
@Override
@@ -333,17 +333,17 @@ public boolean isInstanceOf(Class<? extends Mixed> type) {
333333

334334
@Override
335335
public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) {
336-
return isInstanceOf(type);
336+
return Construct.isInstanceof(this, type);
337337
}
338338

339339
@Override
340340
public CClassType typeof() {
341-
return Construct.typeof(this);
341+
return typeof((Environment) null);
342342
}
343343

344344
@Override
345345
public CClassType typeof(Environment env) {
346-
return typeof();
346+
return Construct.typeof(this);
347347
}
348348

349349
@Override

src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixed.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public CClassType getContainingClass() {
6565

6666
@Override
6767
public boolean isInstanceOf(CClassType type) {
68-
if(type.getNativeType() != null) {
69-
return type.getNativeType().isAssignableFrom(this.getClass());
70-
}
71-
return Construct.isInstanceof(this, type);
68+
return isInstanceOf(type, null, null);
7269
}
7370

7471
@Override
7572
public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) {
76-
return isInstanceOf(type);
73+
if(type.getNativeType() != null) {
74+
return type.getNativeType().isAssignableFrom(this.getClass());
75+
}
76+
return Construct.isInstanceof(this, type);
7777
}
7878

7979
@Override
@@ -92,12 +92,12 @@ public boolean isInstanceOf(Class<? extends Mixed> type) {
9292
*/
9393
@Override
9494
public CClassType typeof() {
95-
return Construct.typeof(this);
95+
return typeof((Environment) null);
9696
}
9797

9898
@Override
9999
public CClassType typeof(Environment env) {
100-
return typeof();
100+
return Construct.typeof(this);
101101
}
102102

103103
@Override

src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ public CClassType getContainingClass() {
119119
*/
120120
@Override
121121
public final CClassType typeof() {
122-
return Construct.typeof(this);
122+
return typeof((Environment) null);
123123
}
124124

125125
@Override
126126
public CClassType typeof(Environment env) {
127-
return typeof();
127+
return Construct.typeof(this);
128128
}
129129

130130
@Override
131131
public boolean isInstanceOf(CClassType type) {
132-
return Construct.isInstanceof(this, type);
132+
return isInstanceOf(type, null, null);
133133
}
134134

135135
@Override
@@ -139,7 +139,7 @@ public boolean isInstanceOf(Class<? extends Mixed> type) {
139139

140140
@Override
141141
public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) {
142-
return isInstanceOf(type);
142+
return Construct.isInstanceof(this, type);
143143
}
144144

145145
@Override

0 commit comments

Comments
 (0)