Skip to content

Commit

Permalink
Merge branch 'optimize-jass-translation' into temp-merger-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed Aug 31, 2021
2 parents 1d972ae + 58a3a0c commit c1b4456
Show file tree
Hide file tree
Showing 41 changed files with 780 additions and 262 deletions.
4 changes: 2 additions & 2 deletions de.peeeq.wurstscript/build.gradle
Expand Up @@ -75,7 +75,7 @@ dependencies {
antlr "org.antlr:antlr4:4.9.2"

// tool for generating AST-classes
compileOnly 'com.github.peterzeller:abstractsyntaxgen:ef7fec791a'
compileOnly 'com.github.peterzeller:abstractsyntaxgen:0.3.2'

// JUnit for testing
testImplementation group: 'org.testng', name: 'testng', version: '6.14.3'
Expand All @@ -88,7 +88,7 @@ dependencies {
implementation 'io.vavr:vavr:1.0.0-alpha-3'

// Support for the vscode language server protocol
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.10.0'
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.12.0'

// @Nullable annotations
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.1.0'
Expand Down
2 changes: 1 addition & 1 deletion de.peeeq.wurstscript/parserspec/jass_im.parseq
Expand Up @@ -10,7 +10,7 @@ ImProg(
ImMethods methods,
ImClasses classes,
ImTypeClassFuncs typeClassFunctions,
java.util.Map<ImVar, java.util.List<ImExpr>> globalInits)
java.util.Map<ImVar, java.util.List<ImSet>> globalInits)

ImVars * ImVar
ImFunctions * ImFunction
Expand Down
2 changes: 1 addition & 1 deletion de.peeeq.wurstscript/parserspec/wurstscript.parseq
Expand Up @@ -609,7 +609,7 @@ HasModifier.attrIsVararg()
returns boolean
implemented by de.peeeq.wurstscript.attributes.ModifiersHelper.isVararg

ClassOrModuleOrModuleInstanciation.getModuleInstanciations
ClassOrModuleOrModuleInstanciation.getModuleInstanciations()
returns ModuleInstanciations
implemented by de.peeeq.wurstscript.ModuleExpander.expandModules

Expand Down
Expand Up @@ -87,8 +87,8 @@ public Set<Set<T>> findStronglyConnectedComponents(List<T> nodes) {
// It also uses a counter C of the number of vertices reached so far, which it uses to compute the preorder numbers of the vertices.
AtomicInteger c = new AtomicInteger();
AtomicInteger componentCount = new AtomicInteger();
Map<T, Integer> preorderNumber = new HashMap<>();
Map<T, Integer> component = new HashMap<>();
Map<T, Integer> preorderNumber = new LinkedHashMap<>();
Map<T, Integer> component = new LinkedHashMap<>();

for (T v : nodes) {
if (!preorderNumber.containsKey(v)) {
Expand Down
Expand Up @@ -274,6 +274,7 @@ public ImVar initFor(ILconstObject obj) {
imProg.getGlobals().add(res);
ImAlloc alloc = JassIm.ImAlloc(obj.getTrace(), obj.getType());
addCompiletimeStateInitAlloc(alloc.getTrace(), res, alloc);
globalState.setVal(res, obj);


Element trace = obj.getTrace();
Expand Down Expand Up @@ -322,6 +323,7 @@ public ImVar initFor(IlConstHandle a) {
ImType type = TypesHelper.imHashTable();
ImVar res = JassIm.ImVar(trace, type, type + "_compiletime", false);
imProg.getGlobals().add(res);
globalState.setVal(res, a);

init = constantToExprHashtable(trace, res, a, map);
addCompiletimeStateInitAlloc(trace, res, init);
Expand Down Expand Up @@ -395,8 +397,9 @@ private ImFunction getCompiletimeStateInitFunction() {

// insert at the beginning
private void addCompiletimeStateInitAlloc(Element trace, ImVar v, ImExpr init) {
imProg.getGlobalInits().put(v, Collections.singletonList(init));
getCompiletimeStateInitFunction().getBody().add(0, JassIm.ImSet(trace, JassIm.ImVarAccess(v), init.copy()));
ImSet imSet = JassIm.ImSet(trace, JassIm.ImVarAccess(v), init.copy());
imProg.getGlobalInits().put(v, Collections.singletonList(imSet));
getCompiletimeStateInitFunction().getBody().add(0, imSet);
}

// insert at the end
Expand Down
Expand Up @@ -32,12 +32,12 @@
import de.peeeq.wurstscript.utils.NotNullList;
import de.peeeq.wurstscript.utils.TempDir;
import de.peeeq.wurstscript.utils.Utils;
import de.peeeq.wurstscript.validation.TRVEHelper;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4j.MessageType;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
Expand Down Expand Up @@ -143,36 +143,46 @@ public void loadWurstFilesInDir(File dir) {
} else if (Utils.isWurstFile(f)) {
loadFile(f);
} else if (f.getName().equals("wurst.dependencies")) {
addDependencyFile(f);
dependencies.addAll(checkDependencyFile(f, gui));
} else if ((!mapFile.isPresent() || runArgs.isNoExtractMapScript()) && f.getName().equals("war3map.j")) {
loadFile(f);
}
}
}

private void addDependencyFile(File f) {
try (FileReader fr = new FileReader(f); BufferedReader reader = new BufferedReader(fr)) {
while (true) {
String line = reader.readLine();
if (line == null)
break;
addDependencyFolder(f, line);
}
public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui) {
List<String> lines;
try {
lines = Files.readLines(depFile, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
throw new Error(e);
}
}

private void addDependencyFolder(File f, String folderName) {
File folder = new File(folderName);
if (!folder.exists()) {
gui.sendError(new CompileError(new WPos(f.getAbsolutePath(), new LineOffsets(), 0, 1), "Folder " + folderName + " not found."));
} else if (!folder.isDirectory()) {
gui.sendError(new CompileError(new WPos(f.getAbsolutePath(), new LineOffsets(), 0, 1), "" + folderName + " is not a folder."));
} else {
dependencies.add(folder);
LineOffsets offsets = new LineOffsets();
int lineNr = 0;
int offset = 0;
for (String line : lines) {
offsets.set(lineNr, offset);
lineNr++;
offset += line.length() + 1;
}
offsets.set(lineNr, offset);
lineNr = 0;
ImmutableList.Builder<File> dependencies = ImmutableList.builder();
for (String line : lines) {
int lineOffset = offsets.get(lineNr);
WPos pos = new WPos(depFile.getAbsolutePath(), offsets, lineOffset + 1, lineOffset + line.length() + 1);
File folder = new File(line);
if (!folder.exists()) {
gui.sendError(new CompileError(pos, "Folder " + line + " not found."));
} else if (!folder.isDirectory()) {
gui.sendError(new CompileError(pos, "" + line + " is not a folder."));
} else {
dependencies.add(folder);
}
lineNr++;
}
return dependencies.build();
}

@Override
Expand Down Expand Up @@ -207,7 +217,7 @@ private void addDependencyFolder(File f, String folderName) {
}
File dependencyFile = new File(projectFolder, "wurst.dependencies");
if (dependencyFile.exists()) {
addDependencyFile(dependencyFile);
dependencies.addAll(checkDependencyFile(dependencyFile, gui));
}
addDependenciesFromFolder(projectFolder, dependencies);
}
Expand Down Expand Up @@ -391,7 +401,7 @@ public void checkProg(WurstModel model) {
checkProg(model, model);
}

public void checkProg(WurstModel model, List<CompilationUnit> toCheck) {
public void checkProg(WurstModel model, Collection<CompilationUnit> toCheck) {
for (CompilationUnit cu : toCheck) {
Preconditions.checkNotNull(cu);
if (!model.contains(cu)) {
Expand Down
Expand Up @@ -17,10 +17,29 @@ public static Location posToLocation(WPos pos) {
return new Location(file, posToRange(pos));
}

private static Range posToRange(WPos pos) {
public static Range posToRange(WPos pos) {
int line = pos.getLine() - 1;
int column = pos.getStartColumn() - 1;
int endLine = pos.getEndLine() - 1;
int endColumn = pos.getEndColumn() - 1;
if (line < 0) {
line = 0;
}
if (endLine < line) {
endLine = line;
}
if (column < 0) {
column = 0;
}
if (endColumn < 0) {
endColumn = 0;
}
if (line == endLine && endColumn <= column) {
endColumn = column + 1;
}
return new Range(
new Position(pos.getLine() - 1, pos.getStartColumn() - 1),
new Position(pos.getEndLine() - 1, pos.getEndColumn() - 1)
new Position(line, column),
new Position(endLine, endColumn)
);
}

Expand Down
Expand Up @@ -58,4 +58,6 @@ public void visit(ModuleInstanciations mis) {
}

File getProjectPath();
}

String getFirstErrorDescription();
}

0 comments on commit c1b4456

Please sign in to comment.