Skip to content

Commit 4bd4788

Browse files
committed
Cherry-pick select changes from genericsTake2
1 parent 6d8759f commit 4bd4788

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/main/java/com/laytonsmith/abstraction/enums/MCTagType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public enum MCTagType {
6868
return ints;
6969
},
7070
(int[] array) -> {
71-
CArray r = new CArray(Target.UNKNOWN);
71+
CArray r = new CArray(Target.UNKNOWN, null, null);
7272
for(int i : array) {
7373
r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, null);
7474
}
@@ -91,7 +91,7 @@ public enum MCTagType {
9191
return longs;
9292
},
9393
(long[] array) -> {
94-
CArray ret = new CArray(Target.UNKNOWN);
94+
CArray ret = new CArray(Target.UNKNOWN, null, null);
9595
for(long i : array) {
9696
ret.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, null);
9797
}

src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public static String optimize(String script, Environment env,
8787
}
8888

8989
private static String optimize0(ParseTree node, Environment env) {
90-
if(node.getData() instanceof CFunction) {
90+
if(node.getData() instanceof CFunction cFunction) {
9191
StringBuilder b = new StringBuilder();
9292
boolean first = true;
93-
b.append(((CFunction) node.getData()).val()).append("(");
93+
b.append(cFunction.val()).append("(");
9494
for(ParseTree child : node.getChildren()) {
9595
if(!first) {
9696
b.append(",");
@@ -105,26 +105,26 @@ private static String optimize0(ParseTree node, Environment env) {
105105
return new StringBuilder().append("'").append(node.getData().val()
106106
.replace("\\", "\\\\").replace("\t", "\\t").replace("\n", "\\n")
107107
.replace("'", "\\'")).append("'").toString();
108-
} else if(node.getData() instanceof IVariable) {
109-
return ((IVariable) node.getData()).getVariableName();
110-
} else if(node.getData() instanceof Variable) {
111-
return ((Variable) node.getData()).getVariableName();
108+
} else if(node.getData() instanceof IVariable iVariable) {
109+
return iVariable.getVariableName();
110+
} else if(node.getData() instanceof Variable variable) {
111+
return variable.getVariableName();
112112
} else if(node.getData() instanceof CSlice) {
113113
return node.getData().val();
114-
} else if(node.getData().isInstanceOf(CArray.TYPE, null, env)) {
114+
} else if(node.getData() instanceof CArray cArray) {
115115
//It's a hardcoded array. This only happens in the course of optimization, if
116116
//the optimizer adds a new array. We still need to handle it appropriately though.
117117
//The values in the array will be constant, guaranteed.
118118
StringBuilder b = new StringBuilder();
119119
b.append("array(");
120120
boolean first = true;
121-
CArray n = (CArray) node.getData();
121+
CArray n = cArray;
122122
for(String key : n.stringKeySet()) {
123123
if(!first) {
124124
b.append(",");
125125
}
126126
first = false;
127-
b.append(optimize0(new ParseTree(n.get(key, Target.UNKNOWN), node.getFileOptions(), true), env));
127+
b.append(optimize0(new ParseTree(n.get(key, Target.UNKNOWN, null), node.getFileOptions(), true), env));
128128
}
129129
b.append(")");
130130
return b.toString();

src/main/java/com/laytonsmith/core/compiler/ProcedureDefinition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import com.laytonsmith.PureUtilities.Version;
44
import com.laytonsmith.core.ParseTree;
55
import com.laytonsmith.core.constructs.CClassType;
6-
import com.laytonsmith.core.constructs.generics.GenericParameters;
76
import com.laytonsmith.core.constructs.Construct;
87
import com.laytonsmith.core.constructs.DocComment;
98
import com.laytonsmith.core.constructs.Target;
9+
import com.laytonsmith.core.constructs.generics.GenericParameters;
1010
import com.laytonsmith.core.environments.Environment;
1111
import com.laytonsmith.core.natives.interfaces.Mixed;
1212
import com.laytonsmith.core.objects.ObjectType;
@@ -73,4 +73,5 @@ public ObjectType getObjectType() {
7373
public GenericParameters getGenericParameters() {
7474
return null;
7575
}
76+
7677
}

src/main/java/com/laytonsmith/core/compiler/analysis/Scope.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashMap;
77
import java.util.HashSet;
88
import java.util.Map;
9+
import java.util.Objects;
910
import java.util.Set;
1011
import java.util.Stack;
1112

@@ -43,6 +44,10 @@ private Scope(Scope parent) {
4344

4445
private Scope(Set<Scope> parents, Map<Namespace, Set<Scope>> specificParents,
4546
Map<Namespace, Map<String, Declaration>> declarations, Map<Namespace, Set<Reference>> references) {
47+
Objects.requireNonNull(parents);
48+
for(Scope s : parents) {
49+
Objects.requireNonNull(s, "The set of parent scopes may not contain null values.");
50+
}
4651
this.parents = parents;
4752
this.specificParents = specificParents;
4853
this.declarations = declarations;

src/main/java/com/laytonsmith/core/constructs/generics/GenericParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public GenericParameters buildWithoutValidation() {
176176

177177
/**
178178
* Begins construction of a new GenericParameters object, which represents the RHS of the generic declaration.The
179-
* actual GenericDeclaration object is passed in in order to validate the types against the constraints.Each
179+
* actual GenericDeclaration object is passed in in order to validate the types against the constraints. Each
180180
* instance of a class which has a GenericDeclaration will have one of these objects in it, associated with that
181181
* particular instance. This data is not lost after compilation, and types are reified for runtime use.
182182
* <p>

0 commit comments

Comments
 (0)