Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

wurstscript / WurstScript / 1198

22 Oct 2019 - 20:22 coverage decreased (-0.04%) to 62.819%
1198

Pull #899

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
fixes
Pull Request #899: Workspace config

16348 of 26024 relevant lines covered (62.82%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompilationProcess.java
1
package de.peeeq.wurstio;
2

3
import de.peeeq.wurstio.languageserver.requests.RunTests;
4
import de.peeeq.wurstio.mpq.MpqEditor;
5
import de.peeeq.wurstio.utils.FileUtils;
6
import de.peeeq.wurstscript.RunArgs;
7
import de.peeeq.wurstscript.WLogger;
8
import de.peeeq.wurstscript.ast.WurstModel;
9
import de.peeeq.wurstscript.attributes.CompileError;
10
import de.peeeq.wurstscript.gui.WurstGui;
11
import de.peeeq.wurstscript.intermediatelang.interpreter.ILStackFrame;
12
import de.peeeq.wurstscript.jassAst.JassProg;
13
import de.peeeq.wurstscript.jassprinter.JassPrinter;
14
import de.peeeq.wurstscript.utils.Utils;
15
import org.eclipse.jdt.annotation.Nullable;
16

17
import java.io.File;
18
import java.io.IOException;
19
import java.io.PrintStream;
20

21
/**
22
 *
23
 */
24
public class CompilationProcess {
25

26
    private final WurstGui gui;
27
    private final RunArgs runArgs;
28
    private final TimeTaker timeTaker;
29

30
    public CompilationProcess(WurstGui gui, RunArgs runArgs) {
!
31
        this.gui = gui;
!
32
        this.runArgs = runArgs;
!
33
        if (runArgs.isMeasureTimes()) {
!
34
            this.timeTaker = new TimeTaker.Recording();
!
35
        } else {
36
            this.timeTaker = new TimeTaker.Default();
!
37
        }
38
    }
!
39

40
    @Nullable CharSequence doCompilation(@Nullable MpqEditor mpqEditor) throws IOException {
41
        return doCompilation(mpqEditor, null);
!
42
    }
43

44
    @Nullable CharSequence doCompilation(@Nullable MpqEditor mpqEditor, @Nullable File projectFolder) throws IOException {
UNCOV
45
        WurstCompilerJassImpl compiler = new WurstCompilerJassImpl(timeTaker, projectFolder, gui, mpqEditor, runArgs);
!
UNCOV
46
        gui.sendProgress("Check input map");
!
UNCOV
47
        if (mpqEditor != null && !mpqEditor.canWrite()) {
!
48
            WLogger.severe("The supplied map is invalid/corrupted/protected and Wurst cannot write to it.\n" +
!
49
                    "Please supply a valid .w3x input map that can be opened in the world editor.");
50
        }
51

52
        for (String file : runArgs.getFiles()) {
!
UNCOV
53
            compiler.loadFiles(file);
!
54
        }
!
55
        WurstModel model = timeTaker.measure("parse files",
!
UNCOV
56
                () -> compiler.parseFiles());
!
57

58
        if (gui.getErrorCount() > 0) {
!
UNCOV
59
            return null;
!
60
        }
61
        if (model == null) {
!
62
            return null;
!
63
        }
64

65
        timeTaker.measure("Typecheck program",
!
UNCOV
66
                () -> compiler.checkProg(model));
!
67

68
        if (gui.getErrorCount() > 0) {
!
69
            return null;
!
70
        }
71

72
        timeTaker.measure("Translate program to Im",
!
UNCOV
73
                () -> compiler.translateProgToIm(model));
!
74

75
        if (gui.getErrorCount() > 0) {
!
UNCOV
76
            return null;
!
77
        }
78

79
        File mapFile = compiler.getMapFile();
!
80

UNCOV
81
        if (runArgs.isRunTests()) {
!
82
            timeTaker.measure("Run tests",
!
83
                    () -> runTests(compiler));
!
84
        }
85

86
        timeTaker.measure("Run compiletime functions",
!
UNCOV
87
                () -> compiler.runCompiletime());
!
88

89
        JassProg jassProg = timeTaker.measure("Transform program to Jass",
!
UNCOV
90
                () -> compiler.transformProgToJass());
!
91

UNCOV
92
        if (jassProg == null || gui.getErrorCount() > 0) {
!
93
            return null;
!
94
        }
95

96
        boolean withSpace;
97
        withSpace = !runArgs.isOptimize();
!
98

99
        gui.sendProgress("Printing Jass");
!
100

UNCOV
101
        JassPrinter printer = new JassPrinter(withSpace, jassProg);
!
102
        CharSequence mapScript = timeTaker.measure("Print Jass",
!
103
                () -> printer.printProg());
!
104

105
        // output to file
106
        File outputMapscript = timeTaker.measure("Print Jass",
!
107
                () -> writeMapscript(mapScript));
!
108

UNCOV
109
        if (!runArgs.isDisablePjass()) {
!
110
            boolean pjassError = timeTaker.measure("Run PJass",
!
111
                    () -> runPjass(outputMapscript));
!
UNCOV
112
            if (pjassError) return null;
!
113
        }
UNCOV
114
        timeTaker.printReport();
!
115
        return mapScript;
!
116
    }
117

118
    private boolean runPjass(File outputMapscript) {
119
        Pjass.Result pJassResult = Pjass.runPjass(outputMapscript);
!
120
        WLogger.info(pJassResult.getMessage());
!
121
        if (!pJassResult.isOk()) {
!
UNCOV
122
            for (CompileError err : pJassResult.getErrors()) {
!
123
                gui.sendError(err);
!
UNCOV
124
            }
!
UNCOV
125
            return true;
!
126
        }
127
        return false;
!
128
    }
129

130
    private File writeMapscript(CharSequence mapScript) {
UNCOV
131
        gui.sendProgress("Writing output file");
!
132
        File outputMapscript;
133
        if (runArgs.getOutFile() != null) {
!
UNCOV
134
            outputMapscript = new File(runArgs.getOutFile());
!
135
        } else {
136
            //outputMapscript = File.createTempFile("outputMapscript", ".j");
137
            outputMapscript = new File("./temp/output.j");
!
138
        }
139
        outputMapscript.getParentFile().mkdirs();
!
140
        try {
UNCOV
141
            FileUtils.write(mapScript, outputMapscript);
!
UNCOV
142
            return outputMapscript;
!
UNCOV
143
        } catch (IOException e) {
!
UNCOV
144
            throw new RuntimeException(e);
!
145
        }
146
    }
147

148
    private void runTests(WurstCompilerJassImpl compiler) {
149
        PrintStream out = System.out;
!
150
        // tests
UNCOV
151
        gui.sendProgress("Running tests");
!
152
        System.out.println("Running tests");
!
153
        RunTests runTests = new RunTests(null, 0, 0, null) {
!
154
            @Override
155
            protected void print(String message) {
UNCOV
156
                out.print(message);
!
157
            }
!
158
        };
159
        runTests.runTests(compiler.getImProg(), null, null);
!
160

161
        for (RunTests.TestFailure e : runTests.getFailTests()) {
!
162
            gui.sendError(new CompileError(e.getFunction(), e.getMessage()));
!
163
            if (runArgs.isGui()) {
!
164
                // when using graphical user interface, send stack trace to GUI
165
                for (ILStackFrame sf : Utils.iterateReverse(e.getStackTrace().getStackFrames())) {
!
UNCOV
166
                    gui.sendError(sf.makeCompileError());
!
167
                }
!
168
            }
UNCOV
169
        }
!
170

UNCOV
171
        System.out.println("Finished running tests");
!
UNCOV
172
    }
!
173

174

175
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc