Skip to content

Commit 7d53211

Browse files
committed
Merge branch 'master' into genericsTake2
2 parents 25610bd + 45e9582 commit 7d53211

41 files changed

Lines changed: 202 additions & 208 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.laytonsmith.core.environments.Environment;
1313
import com.laytonsmith.core.exceptions.CRE.CRECastException;
1414
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
15-
import com.laytonsmith.core.environments.Environment;
1615
import com.laytonsmith.core.natives.interfaces.Mixed;
1716

1817
import java.util.function.BiFunction;

src/main/java/com/laytonsmith/core/ArgumentValidation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public static CByteArray getByteArray(Mixed c, Target t, Environment env) {
558558
public static LeftHandSideType getClassType(Mixed c, Target t) {
559559
return getClassType(c, t, null);
560560
}
561-
561+
562562
/**
563563
* Returns the LeftHandSideType from the given Construct. This accepts either a LeftHandSideType directly, or a
564564
* CClassType, which is converted to a LeftHandSideType.

src/main/java/com/laytonsmith/core/MethodScriptCompiler.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,10 +1265,10 @@ public static List<Script> preprocess(TokenStream tokenStream,
12651265
* Compiles the token stream into a valid ParseTree. This also includes optimization and reduction.
12661266
*
12671267
* @param stream The token stream, as generated by {@link #lex(String, Environment, File, boolean) lex}
1268-
* @param environment If an environment is already set up, it can be passed in here. The code will tolerate a null
1268+
* @param env If an environment is already set up, it can be passed in here. The code will tolerate a null
12691269
* value, but if present, should be passed in. If the value is null, a standalone environment will be generated
12701270
* and used.
1271-
* @param envs The environments that are going to be present at runtime. Even if the {@code environment} parameter
1271+
* @param envs The environments that are going to be present at runtime. Even if the {@code env} parameter
12721272
* is null, this still must be non-null and populated with one or more values.
12731273
* @return A fully compiled, optimized, and reduced parse tree. If {@code stream} is null or empty, null is
12741274
* returned.
@@ -1278,20 +1278,20 @@ public static List<Script> preprocess(TokenStream tokenStream,
12781278
* @throws com.laytonsmith.core.exceptions.ConfigCompileGroupException A ConfigCompileGroupException is just
12791279
* a collection of single {@link ConfigCompileException}s.
12801280
*/
1281-
public static ParseTree compile(TokenStream stream, Environment environment,
1281+
public static ParseTree compile(TokenStream stream, Environment env,
12821282
Set<Class<? extends Environment.EnvironmentImpl>> envs) throws ConfigCompileException,
12831283
ConfigCompileGroupException {
1284-
return compile(stream, environment, envs, new StaticAnalysis(true));
1284+
return compile(stream, env, envs, new StaticAnalysis(true));
12851285
}
12861286

12871287
/**
12881288
* Compiles the token stream into a valid ParseTree. This also includes optimization and reduction.
12891289
*
12901290
* @param stream The token stream, as generated by {@link #lex(String, Environment, File, boolean) lex}
1291-
* @param environment If an environment is already set up, it can be passed in here. The code will tolerate a null
1291+
* @param env If an environment is already set up, it can be passed in here. The code will tolerate a null
12921292
* value, but if present, should be passed in. If the value is null, a standalone environment will be generated
12931293
* and used.
1294-
* @param envs The environments that are going to be present at runtime. Even if the {@code environment} parameter
1294+
* @param envs The environments that are going to be present at runtime. Even if the {@code env} parameter
12951295
* is null, this still must be non-null and populated with one or more values.
12961296
* @param staticAnalysis The static analysis object, or {@code null} to not perform static analysis. This object
12971297
* is used to perform static analysis on the AST that results from parsing, before any AST optimizations.
@@ -1304,22 +1304,22 @@ public static ParseTree compile(TokenStream stream, Environment environment,
13041304
* @throws com.laytonsmith.core.exceptions.ConfigCompileGroupException A ConfigCompileGroupException is just
13051305
* a collection of single {@link ConfigCompileException}s.
13061306
*/
1307-
public static ParseTree compile(TokenStream stream, Environment environment,
1307+
public static ParseTree compile(TokenStream stream, Environment env,
13081308
Set<Class<? extends Environment.EnvironmentImpl>> envs, StaticAnalysis staticAnalysis)
13091309
throws ConfigCompileException, ConfigCompileGroupException {
13101310
Objects.requireNonNull(envs, "envs parameter must not be null");
13111311
Objects.requireNonNull(staticAnalysis, "Static Analysis may be disabled, but cannot be null.");
13121312
try {
1313-
if(environment == null) {
1313+
if(env == null) {
13141314
// We MUST have a CompilerEnvironment. It doesn't need to be used, but we have to create it at
13151315
// this stage.
1316-
environment = Static.GenerateStandaloneEnvironment(false);
1316+
env = Static.GenerateStandaloneEnvironment(false);
13171317
}
1318-
if(!environment.hasEnv(CompilerEnvironment.class)) {
1318+
if(!env.hasEnv(CompilerEnvironment.class)) {
13191319
Environment e = Static.GenerateStandaloneEnvironment(false);
1320-
environment = environment.cloneAndAdd(e.getEnv(CompilerEnvironment.class));
1320+
env = env.cloneAndAdd(e.getEnv(CompilerEnvironment.class));
13211321
}
1322-
environment.getEnv(CompilerEnvironment.class).setStaticAnalysis(staticAnalysis);
1322+
env.getEnv(CompilerEnvironment.class).setStaticAnalysis(staticAnalysis);
13231323
} catch (IOException | DataSourceException | URISyntaxException | Profiles.InvalidProfileException ex) {
13241324
throw new RuntimeException(ex);
13251325
}
@@ -1328,7 +1328,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
13281328
// Return a null AST when the program is empty.
13291329
// Do run static analysis to allow for including this empty file in another file.
13301330
if(stream == null || stream.isEmpty()) {
1331-
staticAnalysis.analyze(null, environment, envs, compilerErrors);
1331+
staticAnalysis.analyze(null, env, envs, compilerErrors);
13321332
return null;
13331333
}
13341334

@@ -1348,7 +1348,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
13481348
}
13491349
}
13501350

1351-
processEarlyKeywords(stream, environment, compilerErrors);
1351+
processEarlyKeywords(stream, env, compilerErrors);
13521352
// All early keyword errors are handled, but then we halt compilation at this stage, since most
13531353
// further errors are likley meaningless.
13541354
if(!compilerErrors.isEmpty()) {
@@ -1493,7 +1493,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
14931493
myIndex.addChild(tree.getChildAt(j));
14941494
}
14951495
} else {
1496-
myIndex = new ParseTree(new CSlice("0..-1", t.target, environment), fileOptions, true);
1496+
myIndex = new ParseTree(new CSlice("0..-1", t.target, env), fileOptions, true);
14971497
}
14981498
tree.setChildren(tree.getChildren().subList(0, array));
14991499
ParseTree arrayGet = new ParseTree(new CFunction(array_get.NAME, t.target), fileOptions, true);
@@ -1547,7 +1547,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
15471547
+ " usage.";
15481548
CompilerWarning warning = new CompilerWarning(msg, t.target,
15491549
FileOptions.SuppressWarning.CodeUpgradeNotices);
1550-
environment.getEnv(CompilerEnvironment.class).addCodeUpgradeNotice(fileOptions, warning);
1550+
env.getEnv(CompilerEnvironment.class).addCodeUpgradeNotice(fileOptions, warning);
15511551
}
15521552
} catch (ConfigCompileException ex) {
15531553
// The function doesn't exist. It may be a compile error later (or maybe not, if it's
@@ -1576,7 +1576,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
15761576
+ " this warning will go away. If it is intended, move this parenthesis up to the same"
15771577
+ " line to actually execute it.", t.target,
15781578
SuppressWarning.PossibleUnexpectedExecution);
1579-
environment.getEnv(CompilerEnvironment.class).addCompilerWarning(fileOptions, warning);
1579+
env.getEnv(CompilerEnvironment.class).addCompilerWarning(fileOptions, warning);
15801580
f = new ParseTree(new CFunction(Compiler.__autoconcat__.NAME, unknown), fileOptions);
15811581
} else {
15821582
f = new ParseTree(new CFunction(Compiler.p.NAME, t.getTarget()), fileOptions);
@@ -1676,7 +1676,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
16761676
value = next1.val() + next2.val();
16771677
i++;
16781678
}
1679-
slice = new CSlice(".." + value, t.getTarget(), environment);
1679+
slice = new CSlice(".." + value, t.getTarget(), env);
16801680
i++;
16811681
tree.addChild(new ParseTree(slice, fileOptions));
16821682
constructCount.peek().incrementAndGet();
@@ -1699,7 +1699,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
16991699
value = next2.val() + next3.val();
17001700
i++;
17011701
}
1702-
slice = new CSlice(".." + value, next1.getTarget(), environment);
1702+
slice = new CSlice(".." + value, next1.getTarget(), env);
17031703
if(t.type.isKeyword()) {
17041704
tree.addChild(new ParseTree(new CKeyword(t.val(), t.getTarget()), fileOptions));
17051705
constructCount.peek().incrementAndGet();
@@ -1712,7 +1712,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
17121712
modifier = prev1.val();
17131713
tree.removeChildAt(tree.getChildren().size() - 1);
17141714
}
1715-
slice = new CSlice(modifier + t.value + "..", t.target, environment);
1715+
slice = new CSlice(modifier + t.value + "..", t.target, env);
17161716
} else {
17171717
//both are provided
17181718
String modifier1 = "";
@@ -1734,7 +1734,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
17341734
second = next3;
17351735
i++;
17361736
}
1737-
slice = new CSlice(modifier1 + first.value + ".." + modifier2 + second.value, t.target, environment);
1737+
slice = new CSlice(modifier1 + first.value + ".." + modifier2 + second.value, t.target, env);
17381738
}
17391739
i++;
17401740
tree.addChild(new ParseTree(slice, fileOptions));
@@ -1754,12 +1754,12 @@ public static ParseTree compile(TokenStream stream, Environment environment,
17541754
if(!(previous.getData() instanceof SourceType st)) {
17551755
throw new ConfigCompileException("Unexpected varargs token (\"...\"). This can only be used with types.", t.target);
17561756
}
1757-
previous.setData(st.asVariadicType(environment));
1757+
previous.setData(st.asVariadicType(env));
17581758
continue;
17591759
} else if(t.type == TType.LIT) {
17601760
Construct c;
17611761
try {
1762-
c = Static.resolveConstruct(t.val(), t.target, true, environment);
1762+
c = Static.resolveConstruct(t.val(), t.target, true, env);
17631763
} catch (ConfigRuntimeException ex) {
17641764
throw new ConfigCompileException(ex);
17651765
}
@@ -1805,7 +1805,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
18051805
tree.addChild(new ParseTree(new IVariable(t.val(), t.target), fileOptions));
18061806
constructCount.peek().incrementAndGet();
18071807
} else if(t.type.equals(TType.UNKNOWN)) {
1808-
tree.addChild(new ParseTree(Static.resolveConstruct(t.val(), t.target, environment), fileOptions));
1808+
tree.addChild(new ParseTree(Static.resolveConstruct(t.val(), t.target, env), fileOptions));
18091809
constructCount.peek().incrementAndGet();
18101810
} else if(t.type.isSymbol()) { //Logic and math symbols
18111811

@@ -1918,21 +1918,21 @@ public static ParseTree compile(TokenStream stream, Environment environment,
19181918
// Process the AST.
19191919
Stack<List<Procedure>> procs = new Stack<>();
19201920
procs.add(new ArrayList<>());
1921-
processKeywords(tree, environment, compilerErrors);
1922-
addSelfStatements(tree, environment, envs, compilerErrors);
1923-
rewriteAutoconcats(tree, environment, envs, compilerErrors, true);
1924-
processLateKeywords(tree, environment, compilerErrors);
1925-
checkLinearComponents(tree, environment, compilerErrors);
1926-
postParseRewrite(rootNode, environment, envs, compilerErrors, true); // Pass rootNode since this might rewrite 'tree'.
1921+
processKeywords(tree, env, compilerErrors);
1922+
addSelfStatements(tree, env, envs, compilerErrors);
1923+
rewriteAutoconcats(tree, env, envs, compilerErrors, true);
1924+
processLateKeywords(tree, env, compilerErrors);
1925+
checkLinearComponents(tree, env, compilerErrors);
1926+
postParseRewrite(rootNode, env, envs, compilerErrors, true); // Pass rootNode since this might rewrite 'tree'.
19271927
tree = rootNode.getChildAt(0);
19281928
moveNodeModifiersOffSyntheticNodes(tree);
1929-
staticAnalysis.analyze(tree, environment, envs, compilerErrors);
1930-
optimize(tree, environment, envs, procs, compilerErrors);
1929+
staticAnalysis.analyze(tree, env, envs, compilerErrors);
1930+
optimize(tree, env, envs, procs, compilerErrors);
19311931
link(tree, compilerErrors);
19321932
checkFunctionsExist(tree, compilerErrors, envs);
19331933
checkBreaks(tree, compilerErrors);
19341934
if(!staticAnalysis.isLocalEnabled()) {
1935-
checkUnhandledCompilerConstructs(tree, environment, compilerErrors);
1935+
checkUnhandledCompilerConstructs(tree, env, compilerErrors);
19361936
}
19371937
if(!compilerErrors.isEmpty()) {
19381938
if(compilerErrors.size() == 1) {
@@ -1942,7 +1942,7 @@ public static ParseTree compile(TokenStream stream, Environment environment,
19421942
throw new ConfigCompileGroupException(compilerErrors);
19431943
}
19441944
}
1945-
eliminateDeadCode(tree, environment, envs);
1945+
eliminateDeadCode(tree, env, envs);
19461946
return rootNode;
19471947
}
19481948

src/main/java/com/laytonsmith/core/ObjectGenerator.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,22 +2072,6 @@ public CArray vector(Vector3D vector) {
20722072
return vector(vector, (Environment) null);
20732073
}
20742074

2075-
/**
2076-
* Returns a CArray with an alpha channel from a given MCColor. It will be in the format array(a: 0, r: 0, g: 0, b: 0)
2077-
*
2078-
* @param color
2079-
* @param t
2080-
* @return
2081-
*/
2082-
public CArray transparentColor(MCColor color, Target t) {
2083-
CArray ca = CArray.GetAssociativeArray(t);
2084-
ca.set("r", new CInt(color.getRed(), t), t);
2085-
ca.set("g", new CInt(color.getGreen(), t), t);
2086-
ca.set("b", new CInt(color.getBlue(), t), t);
2087-
ca.set("a", new CInt(color.getAlpha(), t), t);
2088-
return ca;
2089-
}
2090-
20912075
/**
20922076
* Gets a vector object, given a Vector.
20932077
*
@@ -2216,6 +2200,22 @@ public Vector3D vector(Vector3D v, Mixed c, Target t, Environment env) {
22162200
}
22172201
}
22182202

2203+
/**
2204+
* Returns a CArray with an alpha channel from a given MCColor. It will be in the format array(a: 0, r: 0, g: 0, b: 0)
2205+
*
2206+
* @param color
2207+
* @param t
2208+
* @return
2209+
*/
2210+
public CArray transparentColor(MCColor color, Target t) {
2211+
CArray ca = CArray.GetAssociativeArray(t);
2212+
ca.set("r", new CInt(color.getRed(), t), t);
2213+
ca.set("g", new CInt(color.getGreen(), t), t);
2214+
ca.set("b", new CInt(color.getBlue(), t), t);
2215+
ca.set("a", new CInt(color.getAlpha(), t), t);
2216+
return ca;
2217+
}
2218+
22192219
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
22202220
@Deprecated
22212221
public CArray enchants(Map<MCEnchantment, Integer> map, Target t) {
@@ -3332,6 +3332,7 @@ public MCMetadataValue metadataValue(Mixed value, MCPlugin plugin, Environment e
33323332
* @param value
33333333
* @param plugin
33343334
* @return
3335+
* @deprecated Use {@link #metadataValue(Mixed, MCPlugin, Environment)} instead.
33353336
*/
33363337
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
33373338
@Deprecated
@@ -3363,4 +3364,4 @@ public CArray regMatchValue(MatchResult matchResult, Target t) {
33633364

33643365
return ret;
33653366
}
3366-
}
3367+
}

src/main/java/com/laytonsmith/core/Static.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,12 @@ public static MCCommandSender GetCommandSender(String name, Target t) throws Con
10281028
/**
10291029
* If the sender is a player, it is returned, otherwise a ConfigRuntimeException is thrown.
10301030
*
1031-
* @param environment
1031+
* @param env
10321032
* @param t
10331033
* @return
10341034
*/
1035-
public static MCPlayer getPlayer(Environment environment, Target t) {
1036-
MCPlayer player = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
1035+
public static MCPlayer getPlayer(Environment env, Target t) {
1036+
MCPlayer player = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
10371037
if(player != null) {
10381038
return player;
10391039
} else {
@@ -1564,16 +1564,16 @@ public static File GetFileFromArgument(String arg, Environment env, Target t, Fi
15641564
* Returns true if currently running in cmdline mode. If the environment is null, or the GlobalEnv is not available,
15651565
* then defaultValue is returned.
15661566
*
1567-
* @param environment
1567+
* @param env
15681568
* @param defaultValue What should be returned if the environment is null or GlobalEnv is not present. (Happens
15691569
* during compile time.)
15701570
* @return
15711571
*/
1572-
public static boolean InCmdLine(Environment environment, boolean defaultValue) {
1573-
if(environment == null || !environment.hasEnv(GlobalEnv.class)) {
1572+
public static boolean InCmdLine(Environment env, boolean defaultValue) {
1573+
if(env == null || !env.hasEnv(GlobalEnv.class)) {
15741574
return defaultValue;
15751575
}
1576-
return environment.getEnv(GlobalEnv.class).inCmdlineMode();
1576+
return env.getEnv(GlobalEnv.class).inCmdlineMode();
15771577
}
15781578

15791579
/** @deprecated Use {@link #AssertType(Class, Mixed[], int, Function, Target, Environment)} instead. */

src/main/java/com/laytonsmith/core/StrictMode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public class StrictMode {
1414
* There are a couple of factors that go into determining if strict mode is enabled or not. This method
1515
* combines all the reasons into a single function call.
1616
* @param fileOptions This parameter is mandatory, and should be provided by the compiler or other source object.
17-
* @param environment This parameter is optional, and may be set to null. This is going to be the case on the first
17+
* @param env This parameter is optional, and may be set to null. This is going to be the case on the first
1818
* compiler pass, but in dynamic code instances, may be present.
1919
* @param t The code target, for error messages
2020
* @return True if strict mode rules should be followed for this object.
2121
*/
22-
public static boolean isStrictMode(FileOptions fileOptions, Environment environment, Target t) {
22+
public static boolean isStrictMode(FileOptions fileOptions, Environment env, Target t) {
2323
boolean runtimeSetting = false;
24-
if(environment != null) {
25-
GlobalEnv env = environment.getEnv(GlobalEnv.class);
26-
runtimeSetting = env.GetRuntimeSetting("system.strict_mode.enabled", false, t, environment);
24+
if(env != null) {
25+
GlobalEnv genv = env.getEnv(GlobalEnv.class);
26+
runtimeSetting = genv.GetRuntimeSetting("system.strict_mode.enabled", false, t, env);
2727
}
2828
return fileOptions.isStrict() || runtimeSetting;
2929
}

src/main/java/com/laytonsmith/core/asm/LLVMFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Boolean runAsync() {
109109
}
110110

111111
@Override
112-
public final Mixed exec(Target t, Environment environment, GenericParameters generics, Mixed... args) throws ConfigRuntimeException {
112+
public final Mixed exec(Target t, Environment env, GenericParameters generics, Mixed... args) throws ConfigRuntimeException {
113113
throw new UnsupportedOperationException("Not supported.");
114114
}
115115

0 commit comments

Comments
 (0)