Skip to content

Commit cdced5d

Browse files
committed
decent improvements
1 parent e96e226 commit cdced5d

19 files changed

Lines changed: 624 additions & 408 deletions

File tree

de.peeeq.wurstscript/META-INF/MANIFEST.MF

Lines changed: 0 additions & 104 deletions
This file was deleted.

de.peeeq.wurstscript/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ dependencies {
8787
antlr "org.antlr:antlr4:4.13.1"
8888

8989
// tool for generating AST-classes
90-
compileOnly 'com.github.peterzeller:abstractsyntaxgen:062a7ff178'
90+
compileOnly 'com.github.peterzeller:abstractsyntaxgen:f4723157ec'
9191

9292
// JUnit for testing
9393
testImplementation group: 'org.testng', name: 'testng', version: '7.8.0'
@@ -115,10 +115,10 @@ dependencies {
115115
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
116116

117117
// Crigges' jmpq
118-
implementation group: 'com.github.inwc3', name: 'jmpq3', version: '264c54cfc8'
118+
implementation group: 'com.github.inwc3', name: 'jmpq3', version: 'dac0f9e21a'
119119

120120
// Water's wc3 libs
121-
implementation 'com.github.inwc3:wc3libs:00a29ccefd'
121+
implementation 'com.github.inwc3:wc3libs:412316b332'
122122

123123
// The setup tool for wurst.build handling
124124
implementation 'com.github.wurstscript:wurstsetup:475cc7fae8'
@@ -129,6 +129,8 @@ dependencies {
129129
implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.7.0.202309050840-r'
130130
implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.apache', version: '6.7.0.202309050840-r'
131131

132+
implementation 'it.unimi.dsi:fastutil:8.5.16'
133+
132134
// Smallcheck testing library:
133135
testImplementation group: 'com.github.peterzeller', name: 'java-smallcheck', version: '3f6a178ba7'
134136
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/intermediateLang/interpreter/ProgramStateIO.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import org.jetbrains.annotations.NotNull;
2222

2323
import java.io.*;
24+
import java.nio.charset.StandardCharsets;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
2427
import java.util.List;
2528
import java.util.Map;
2629
import java.util.Optional;
@@ -331,10 +334,7 @@ private void writebackObjectFile(ObjMod<? extends ObjMod.Obj> dataStore, ObjectF
331334
out.close();
332335
byte[] w3_ = baos.toByteArray();
333336

334-
// TODO wurst exported objects
335-
FileUtils.write(
336-
exportToWurst(dataStore, fileType),
337-
new File(folder.get(), "WurstExportedObjects_" + fileType.getExt() + ".wurst.txt"));
337+
exportToWurst(dataStore, fileType, new File(folder.get(), "WurstExportedObjects_" + fileType.getExt() + ".wurst.txt").toPath());
338338

339339
if (inject) {
340340
if (mpqEditor == null) {
@@ -351,23 +351,23 @@ private void writebackObjectFile(ObjMod<? extends ObjMod.Obj> dataStore, ObjectF
351351

352352
}
353353

354-
public String exportToWurst(ObjMod<? extends ObjMod.Obj> dataStore, ObjectFileType fileType) throws IOException {
354+
public void exportToWurst(ObjMod<? extends ObjMod.Obj> dataStore,
355+
ObjectFileType fileType, Path outFile) throws IOException {
356+
try (BufferedWriter out = Files.newBufferedWriter(outFile, StandardCharsets.UTF_8)) {
357+
out.write("package WurstExportedObjects_" + fileType.getExt() + "\n");
358+
out.write("import ObjEditingNatives\n\n");
355359

356-
Appendable out = new StringBuilder();
357-
out.append("package WurstExportedObjects_").append(fileType.getExt()).append("\n");
358-
out.append("import ObjEditingNatives\n\n");
360+
out.write("// Modified Table (contains all custom objects)\n\n");
361+
exportToWurst(dataStore.getCustomObjs(), fileType, out);
359362

360-
out.append("// Modified Table (contains all custom objects)\n\n");
361-
exportToWurst(dataStore.getCustomObjs(), fileType, out);
362-
363-
out.append("// Original Table (contains all modified default objects)\n" +
364-
"// Wurst does not support modifying default objects\n" +
365-
"// but you can copy these functions and replace 'xxxx' with a new, custom id.\n\n");
366-
exportToWurst(dataStore.getOrigObjs(), fileType, out);
367-
368-
return out.toString();
363+
out.write("// Original Table (contains all modified default objects)\n" +
364+
"// Wurst does not support modifying default objects\n" +
365+
"// but you can copy these functions and replace 'xxxx' with a new, custom id.\n\n");
366+
exportToWurst(dataStore.getOrigObjs(), fileType, out);
367+
}
369368
}
370369

370+
371371
public void exportToWurst(List<? extends ObjMod.Obj> customObjs, ObjectFileType fileType, Appendable out) throws IOException {
372372
for (ObjMod.Obj obj : customObjs) {
373373
String oldId = obj.getBaseId().getVal();

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ protected File compileMap(File projectFolder, WurstGui gui, Optional<File> mapCo
182182

183183
if (!runArgs.isDisablePjass()) {
184184
gui.sendProgress("Running PJass");
185+
timeTaker.beginPhase("Pjass execution");
185186
Pjass.Result pJassResult = Pjass.runPjass(outFile,
186187
new File(buildDir, "common.j").getAbsolutePath(),
187188
new File(buildDir, "blizzard.j").getAbsolutePath());
@@ -192,6 +193,7 @@ protected File compileMap(File projectFolder, WurstGui gui, Optional<File> mapCo
192193
}
193194
throw new RuntimeException("Could not compile project (PJass error)");
194195
}
196+
timeTaker.endPhase();
195197
}
196198

197199
if (runArgs.isHotStartmap()) {
@@ -387,18 +389,30 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
387389
return result;
388390
}
389391

392+
private static boolean startsWith(byte[] data, byte[] prefix) {
393+
if (data.length < prefix.length) return false;
394+
for (int i = 0; i < prefix.length; i++) {
395+
if (data[i] != prefix[i]) return false;
396+
}
397+
return true;
398+
}
390399

391400
private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, WurstGui gui) throws Exception {
392401
File scriptFile = new File(new File(workspaceRoot.getFile(), "wurst"), "war3map.j");
393402
// If runargs are no extract, either use existing or throw error
394403
// Otherwise try loading from map, if map was saved with wurst, try existing script, otherwise error
395404
if (!mapCopy.isPresent() || runArgs.isNoExtractMapScript()) {
405+
System.out.println("No extract map script enabled - not extracting.");
396406
if (scriptFile.exists()) {
397-
modelManager.syncCompilationUnit(WFile.create(scriptFile));
407+
System.out.println("war3map.j exists at wurst root.");
408+
CompilationUnit compilationUnit = modelManager.getCompilationUnit(WFile.create(scriptFile));
409+
if (compilationUnit == null) {
410+
modelManager.syncCompilationUnit(WFile.create(scriptFile));
411+
}
398412
return scriptFile;
399413
} else {
400414
throw new CompileError(new WPos("", new LineOffsets(), 0, 0),
401-
"RunArg noExtractMapScript is set but no mapscript is provided inside the wurst folder");
415+
"RunArg noExtractMapScript is set but no war3map.j is provided inside the wurst folder");
402416
}
403417
}
404418
if (MapRequest.mapLastModified > lastMapModified || !MapRequest.mapPath.equals(lastMapPath)) {
@@ -421,7 +435,7 @@ private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, Wu
421435
gui.showInfoMessage(err.getMessage());
422436
WLogger.severe(err);
423437
}
424-
} else if (new String(extractedScript, StandardCharsets.UTF_8).startsWith(JassPrinter.WURST_COMMENT_RAW)) {
438+
} else if (startsWith(extractedScript, JassPrinter.WURST_COMMENT_RAW.getBytes(StandardCharsets.UTF_8))) {
425439
WLogger.info("map has already been compiled with wurst");
426440
// file generated by wurst, do not use
427441
if (scriptFile.exists()) {

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/AttrClosureCapturedVariables.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public static ImmutableMultimap<Element, VarDef> calculate(ExprClosure e) {
1616
// closure itself
1717
collect(result, e, e.getImplementation());
1818

19-
// TODO Auto-generated method stub
2019
return result.build();
2120
}
2221

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/ErrorHandler.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
import de.peeeq.wurstscript.gui.WurstGui;
55
import de.peeeq.wurstscript.utils.NotNullList;
66

7+
import java.util.HashMap;
78
import java.util.List;
9+
import java.util.Map;
810

911
public class ErrorHandler {
1012

11-
private final List<CompileError> errors = new NotNullList<>();
13+
// Public-facing lists (unchanged)
14+
private final List<CompileError> errors = new NotNullList<>();
1215
private final List<CompileError> warnings = new NotNullList<>();
16+
17+
// Per-file buckets to avoid O(all) scans
18+
private final Map<String, List<CompileError>> errorsByFile = new HashMap<>();
19+
private final Map<String, List<CompileError>> warningsByFile = new HashMap<>();
20+
1321
private final WurstGui gui;
1422
private boolean unitTestMode = false;
1523

@@ -18,7 +26,7 @@ public ErrorHandler(WurstGui gui) {
1826
}
1927

2028
public int getErrorCount() {
21-
return getErrors().size();
29+
return errors.size();
2230
}
2331

2432
public List<CompileError> getWarnings() {
@@ -30,18 +38,21 @@ public List<CompileError> getErrors() {
3038
}
3139

3240
public void setProgress(String message, double percent) {
33-
getGui().sendProgress(message);
41+
gui.sendProgress(message);
3442
}
3543

3644
public WurstGui getGui() {
3745
return gui;
3846
}
3947

48+
/** Called after makeCompileError() decides to keep it. */
4049
public void sendError(CompileError err) {
4150
if (err.getErrorType() == ErrorType.ERROR) {
4251
errors.add(err);
52+
addToBucket(errorsByFile, err);
4353
} else {
4454
warnings.add(err);
55+
addToBucket(warningsByFile, err);
4556
}
4657
gui.sendError(err);
4758
}
@@ -54,4 +65,37 @@ public boolean isUnitTestMode() {
5465
return unitTestMode;
5566
}
5667

68+
// ---------- package-private helpers for ErrorHandling ----------
69+
70+
List<CompileError> getBucketForFile(String file, ErrorType type) {
71+
return (type == ErrorType.ERROR) ? errorsByFile.get(file) : warningsByFile.get(file);
72+
}
73+
74+
void removeFromGlobal(CompileError err) {
75+
final String file = err.getSource().getFile();
76+
if (err.getErrorType() == ErrorType.ERROR) {
77+
errors.remove(err);
78+
removeFromBucket(errorsByFile, file, err);
79+
} else {
80+
warnings.remove(err);
81+
removeFromBucket(warningsByFile, file, err);
82+
}
83+
}
84+
85+
// ---------- internal helpers ----------
86+
87+
private static void addToBucket(Map<String, List<CompileError>> byFile, CompileError err) {
88+
final String file = err.getSource().getFile();
89+
byFile.computeIfAbsent(file, f -> new NotNullList<>()).add(err);
90+
}
91+
92+
private static void removeFromBucket(Map<String, List<CompileError>> byFile, String file, CompileError err) {
93+
List<CompileError> bucket = byFile.get(file);
94+
if (bucket != null) {
95+
bucket.remove(err);
96+
if (bucket.isEmpty()) {
97+
byFile.remove(file);
98+
}
99+
}
100+
}
57101
}

0 commit comments

Comments
 (0)