Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2018, Compiler Explorer Authors |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer in the |
| 11 | // documentation and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) , |
| 22 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | // POSSIBILITY OF SUCH DAMAGE. |
| 24 | "use strict"; |
| 25 | |
| 26 | let ClientState = require('./clientstate'); |
| 27 | |
| 28 | class ClientStateNormalizer { |
| 29 | constructor() { |
| 30 | this.normalized = new ClientState.State(); |
| 31 | } |
| 32 | |
| 33 | fromGoldenLayoutContent(content) { |
Partouf | 3fa93fa | 2018-09-30 11:19:26 +0200 | [diff] [blame] | 34 | content.forEach((component) => { |
| 35 | this.fromGoldenLayoutComponent(component); |
| 36 | }); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Partouf | ef42dbb | 2020-06-20 21:20:45 +0200 | [diff] [blame] | 39 | setFilterSettingsFromComponent(compiler, component) { |
| 40 | compiler.filters.binary = component.componentState.filters.binary; |
| 41 | compiler.filters.labels = component.componentState.filters.labels; |
| 42 | compiler.filters.directives = component.componentState.filters.directives; |
| 43 | compiler.filters.commentOnly = component.componentState.filters.commentOnly; |
| 44 | compiler.filters.trim = component.componentState.filters.trim; |
| 45 | compiler.filters.intel = component.componentState.filters.intel; |
| 46 | compiler.filters.demangle = component.componentState.filters.demangle; |
Partouf | ef42dbb | 2020-06-20 21:20:45 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 49 | fromGoldenLayoutComponent(component) { |
| 50 | if (component.componentName === "codeEditor") { |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 51 | const session = this.normalized.findOrCreateSession(component.componentState.id); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 52 | session.language = component.componentState.lang; |
| 53 | session.source = component.componentState.source; |
| 54 | } else if (component.componentName === "compiler") { |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 55 | const session = this.normalized.findOrCreateSession(component.componentState.source); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 56 | |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 57 | const compiler = new ClientState.Compiler(); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 58 | compiler.id = component.componentState.compiler; |
| 59 | compiler.options = component.componentState.options; |
| 60 | compiler.libs = component.componentState.libs; |
Partouf | ef42dbb | 2020-06-20 21:20:45 +0200 | [diff] [blame] | 61 | this.setFilterSettingsFromComponent(compiler, component); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 62 | |
| 63 | session.compilers.push(compiler); |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 64 | } else if (component.componentName === "executor") { |
| 65 | const session = this.normalized.findOrCreateSession(component.componentState.source); |
| 66 | |
| 67 | const executor = new ClientState.Executor(); |
| 68 | executor.compiler.id = component.componentState.compiler; |
| 69 | executor.compiler.options = component.componentState.options; |
| 70 | executor.compiler.libs = component.componentState.libs; |
| 71 | executor.compilerVisible = component.componentState.compilationPanelShown; |
| 72 | executor.compilerOutputVisible = component.componentState.compilerOutShown; |
| 73 | executor.arguments = component.componentState.execArgs; |
| 74 | executor.argumentsVisible = component.componentState.argsPanelShown; |
| 75 | executor.stdin = component.componentState.execStdin; |
| 76 | executor.stdinVisible = component.componentState.stdinPanelShown; |
| 77 | |
| 78 | session.executors.push(executor); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 79 | } else if (component.componentName === "ast") { |
| 80 | const session = this.normalized.findOrCreateSession(component.componentState.editorid); |
| 81 | const compiler = session.findOrCreateCompiler(component.componentState.id); |
| 82 | |
| 83 | compiler.specialoutputs.push("ast"); |
| 84 | } else if (component.componentName === "opt") { |
| 85 | const session = this.normalized.findOrCreateSession(component.componentState.editorid); |
| 86 | const compiler = session.findOrCreateCompiler(component.componentState.id); |
| 87 | |
| 88 | compiler.specialoutputs.push("opt"); |
| 89 | } else if (component.componentName === "cfg") { |
| 90 | const session = this.normalized.findOrCreateSession(component.componentState.editorid); |
| 91 | const compiler = session.findOrCreateCompiler(component.componentState.id); |
| 92 | |
| 93 | compiler.specialoutputs.push("cfg"); |
| 94 | } else if (component.componentName === "gccdump") { |
Partouf | 1b6ddc3 | 2018-09-30 11:35:41 +0200 | [diff] [blame] | 95 | const session = this.normalized.findOrCreateSession(component.componentState._editorid); |
| 96 | const compiler = session.findOrCreateCompiler(component.componentState._compilerid); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 97 | |
| 98 | compiler.specialoutputs.push("gccdump"); |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 99 | } else if (component.componentName === "output") { |
| 100 | const session = this.normalized.findOrCreateSession(component.componentState.editor); |
| 101 | const compiler = session.findOrCreateCompiler(component.componentState.compiler); |
| 102 | |
| 103 | compiler.specialoutputs.push("compilerOutput"); |
Partouf | 1d24eea | 2018-10-14 02:15:28 +0200 | [diff] [blame] | 104 | } else if (component.componentName === "conformance") { |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 105 | const session = this.normalized.findOrCreateSession(component.componentState.editorid); |
| 106 | session.conformanceview = new ClientState.ConformanceView(component.componentState); |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 107 | } else if (component.componentName === "tool") { |
| 108 | const session = this.normalized.findOrCreateSession(component.componentState.editor); |
| 109 | const compiler = session.findOrCreateCompiler(component.componentState.compiler); |
| 110 | |
| 111 | compiler.tools.push({ |
| 112 | id: component.componentState.toolId, |
| 113 | args: component.componentState.args |
| 114 | }); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 115 | } else if (component.content) { |
| 116 | this.fromGoldenLayoutContent(component.content); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | fromGoldenLayout(globj) { |
| 121 | if (globj.content) { |
| 122 | this.fromGoldenLayoutContent(globj.content); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 127 | class GoldenLayoutComponents { |
| 128 | createSourceComponent(session, customSessionId) { |
| 129 | return { |
| 130 | type: "component", |
| 131 | componentName: "codeEditor", |
| 132 | componentState: { |
| 133 | id: customSessionId ? customSessionId : session.id, |
| 134 | source: session.source, |
Partouf | 37e93d7 | 2020-06-20 21:44:08 +0200 | [diff] [blame] | 135 | lang: session.language |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 136 | }, |
| 137 | isClosable: true, |
| 138 | reorderEnabled: true |
| 139 | }; |
| 140 | } |
| 141 | |
| 142 | createAstComponent(session, compilerIndex, customSessionId) { |
| 143 | return { |
| 144 | type: "component", |
| 145 | componentName: "ast", |
| 146 | componentState: { |
| 147 | id: compilerIndex, |
| 148 | editorid: customSessionId ? customSessionId : session.id |
| 149 | }, |
| 150 | isClosable: true, |
| 151 | reorderEnabled: true |
| 152 | }; |
| 153 | } |
| 154 | |
| 155 | createOptComponent(session, compilerIndex, customSessionId) { |
| 156 | return { |
| 157 | type: "component", |
| 158 | componentName: "opt", |
| 159 | componentState: { |
| 160 | id: compilerIndex, |
| 161 | editorid: customSessionId ? customSessionId : session.id |
| 162 | }, |
| 163 | isClosable: true, |
| 164 | reorderEnabled: true |
| 165 | }; |
| 166 | } |
| 167 | |
| 168 | createCfgComponent(session, compilerIndex, customSessionId) { |
| 169 | return { |
| 170 | type: "component", |
| 171 | componentName: "opt", |
| 172 | componentState: { |
| 173 | id: compilerIndex, |
| 174 | editorid: customSessionId ? customSessionId : session.id, |
| 175 | options: { |
| 176 | navigation: false, |
| 177 | physics: false |
| 178 | } |
| 179 | }, |
| 180 | isClosable: true, |
| 181 | reorderEnabled: true |
| 182 | }; |
| 183 | } |
| 184 | |
| 185 | createGccDumpComponent(session, compilerIndex, customSessionId) { |
| 186 | return { |
| 187 | type: "component", |
| 188 | componentName: "gccdump", |
| 189 | componentState: { |
| 190 | _compilerid: compilerIndex, |
| 191 | _editorid: customSessionId ? customSessionId : session.id |
| 192 | }, |
| 193 | isClosable: true, |
| 194 | reorderEnabled: true |
| 195 | }; |
| 196 | } |
| 197 | |
| 198 | createCompilerOutComponent(session, compilerIndex, customSessionId) { |
| 199 | return { |
| 200 | type: "component", |
| 201 | componentName: "output", |
| 202 | componentState: { |
| 203 | compiler: compilerIndex, |
| 204 | editor: customSessionId ? customSessionId : session.id, |
| 205 | wrap: false, |
| 206 | fontScale: 14 |
| 207 | }, |
| 208 | isClosable: true, |
| 209 | reorderEnabled: true |
| 210 | }; |
| 211 | } |
| 212 | |
| 213 | createToolComponent(session, compilerIndex, toolId, args, customSessionId) { |
| 214 | return { |
| 215 | type: "component", |
| 216 | componentName: "tool", |
| 217 | componentState: { |
| 218 | editor: customSessionId ? customSessionId : session.id, |
| 219 | compiler: compilerIndex, |
| 220 | toolId: toolId, |
| 221 | args: args |
| 222 | }, |
| 223 | isClosable: true, |
| 224 | reorderEnabled: true |
| 225 | }; |
| 226 | } |
| 227 | |
| 228 | createConformanceViewComponent(session, conformanceview, customSessionId) { |
| 229 | return { |
| 230 | type: "component", |
| 231 | componentName: "conformance", |
| 232 | componentState: { |
| 233 | editorid: customSessionId ? customSessionId : session.id, |
| 234 | langId: session.language, |
| 235 | compilers: [], |
| 236 | libs: conformanceview.libs |
| 237 | }, |
| 238 | isClosable: true, |
| 239 | reorderEnabled: true |
| 240 | }; |
| 241 | } |
| 242 | |
| 243 | createCompilerComponent(session, compiler, customSessionId) { |
| 244 | return { |
| 245 | type: "component", |
| 246 | componentName: "compiler", |
| 247 | componentState: { |
| 248 | compiler: compiler.id, |
| 249 | source: customSessionId ? customSessionId : session.id, |
| 250 | options: compiler.options, |
| 251 | filters: { |
| 252 | binary: compiler.filters.binary, |
| 253 | execute: compiler.filters.execute, |
| 254 | labels: compiler.filters.labels, |
| 255 | directives: compiler.filters.directives, |
| 256 | commentOnly: compiler.filters.commentOnly, |
| 257 | trim: compiler.filters.trim, |
| 258 | intel: compiler.filters.intel, |
Partouf | 37e93d7 | 2020-06-20 21:44:08 +0200 | [diff] [blame] | 259 | demangle: compiler.filters.demangle |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 260 | }, |
| 261 | libs: compiler.libs, |
| 262 | lang: session.language |
| 263 | }, |
| 264 | isClosable: true, |
| 265 | reorderEnabled: true |
| 266 | }; |
| 267 | } |
| 268 | |
| 269 | createExecutorComponent(session, executor, customSessionId) { |
| 270 | return { |
| 271 | type: "component", |
| 272 | componentName: "executor", |
| 273 | componentState: { |
| 274 | compiler: executor.compiler.id, |
| 275 | source: customSessionId ? customSessionId : session.id, |
| 276 | options: executor.compiler.options, |
| 277 | execArgs: executor.arguments, |
| 278 | execStdin: executor.stdin, |
| 279 | libs: executor.compiler.libs, |
| 280 | lang: session.language, |
| 281 | compilationPanelShown: executor.compilerVisible, |
| 282 | compilerOutShown: executor.compilerOutputVisible, |
| 283 | argsPanelShown: executor.argumentsVisible, |
| 284 | stdinPanelShown: executor.stdinVisible |
| 285 | }, |
| 286 | isClosable: true, |
| 287 | reorderEnabled: true |
| 288 | }; |
| 289 | } |
| 290 | |
| 291 | createDiffComponent(left, right) { |
| 292 | return { |
| 293 | type: "component", |
| 294 | componentName: "diff", |
| 295 | componentState: |
| 296 | { |
| 297 | lhs: left, |
| 298 | rhs: right, |
| 299 | lhsdifftype: 0, |
| 300 | rhsdifftype: 0, |
| 301 | fontScale: 14 |
| 302 | } |
| 303 | }; |
| 304 | } |
| 305 | |
| 306 | createSpecialOutputComponent(viewtype, session, idxCompiler, customSessionId) { |
| 307 | let component = null; |
| 308 | if (viewtype === "ast") { |
| 309 | component = this.createAstComponent(session, idxCompiler + 1, customSessionId); |
| 310 | } else if (viewtype === "opt") { |
| 311 | component = this.createOptComponent(session, idxCompiler + 1, customSessionId); |
| 312 | } else if (viewtype === "cfg") { |
| 313 | component = this.createCfgComponent(session, idxCompiler + 1, customSessionId); |
| 314 | } else if (viewtype === "gccdump") { |
| 315 | component = this.createGccDumpComponent(session, idxCompiler + 1, customSessionId); |
| 316 | } else if (viewtype === "compilerOutput") { |
| 317 | component = this.createCompilerOutComponent(session, idxCompiler + 1, customSessionId); |
| 318 | } |
| 319 | |
| 320 | return component; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | class ClientStateGoldenifier extends GoldenLayoutComponents { |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 325 | constructor() { |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 326 | super(); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 327 | this.golden = {}; |
| 328 | } |
| 329 | |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 330 | newStackWithOneComponent(width, component) { |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 331 | return { |
| 332 | type: "stack", |
| 333 | width: width, |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 334 | content: [component] |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 335 | }; |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | newSourceStackFromSession(session, width) { |
| 339 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 340 | this.createSourceComponent(session) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 341 | ); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 344 | newAstStackFromCompiler(session, compilerIndex, width) { |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 345 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 346 | this.createAstComponent(session, compilerIndex) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 347 | ); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 350 | newOptStackFromCompiler(session, compilerIndex, width) { |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 351 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 352 | this.createOptComponent(session, compilerIndex) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 353 | ); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 356 | newCfgStackFromCompiler(session, compilerIndex, width) { |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 357 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 358 | this.createCfgComponent(session, compilerIndex) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 359 | ); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 362 | newGccDumpStackFromCompiler(session, compilerIndex, width) { |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 363 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 364 | this.createGccDumpComponent(session, compilerIndex) |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 365 | ); |
| 366 | } |
| 367 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 368 | newCompilerOutStackFromCompiler(session, compilerIndex, width) { |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 369 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 370 | this.createCompilerOutComponent(session, compilerIndex) |
| 371 | ); |
| 372 | } |
| 373 | |
| 374 | newToolStackFromCompiler(session, compilerIndex, toolId, args, width) { |
| 375 | return this.newStackWithOneComponent(width, |
| 376 | this.createToolComponent(session, compilerIndex, toolId, args) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 377 | ); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 380 | newConformanceViewStack(session, width, conformanceview) { |
| 381 | const stack = this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 382 | this.createConformanceViewComponent(session, conformanceview) |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 383 | ); |
| 384 | |
| 385 | conformanceview.compilers.forEach((compiler) => { |
| 386 | const compjson = { |
| 387 | compilerId: compiler.id, |
| 388 | options: compiler.options |
| 389 | }; |
| 390 | |
| 391 | stack.content[0].componentState.compilers.push(compjson); |
| 392 | }); |
| 393 | |
| 394 | return stack; |
| 395 | } |
| 396 | |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 397 | newCompilerStackFromSession(session, compiler, width) { |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 398 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 399 | this.createCompilerComponent(session, compiler) |
Partouf | 7b5b31a | 2018-10-02 22:05:24 +0200 | [diff] [blame] | 400 | ); |
Partouf | 7583df9 | 2020-06-18 23:19:45 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 403 | newExecutorStackFromSession(session, executor, width) { |
| 404 | return this.newStackWithOneComponent(width, |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 405 | this.createExecutorComponent(session, executor) |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 406 | ); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 409 | createSourceContentArray(state, left, right) { |
| 410 | if (left.session === right.session) { |
| 411 | return [this.createPresentationModeComponents(state.sessions[left.session], 1, 100)]; |
| 412 | } else { |
| 413 | return [ |
| 414 | this.createPresentationModeComponents(state.sessions[left.session], 1), |
| 415 | this.createPresentationModeComponents(state.sessions[right.session], 2) |
| 416 | ]; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | getPresentationModeEmptyLayout() { |
| 421 | return { |
| 422 | settings: { |
| 423 | hasHeaders: true, |
| 424 | constrainDragToContainer: false, |
| 425 | reorderEnabled: true, |
| 426 | selectionEnabled: false, |
| 427 | popoutWholeStack: false, |
| 428 | blockedPopoutsThrowError: true, |
| 429 | closePopoutsOnUnload: true, |
| 430 | showPopoutIcon: false, |
| 431 | showMaximiseIcon: true, |
| 432 | showCloseIcon: false, |
| 433 | responsiveMode: "onload", |
| 434 | tabOverlapAllowance: 0, |
| 435 | reorderOnTabMenuClick: true, |
| 436 | tabControlOffset: 10 |
| 437 | }, |
| 438 | dimensions: |
| 439 | { |
| 440 | borderWidth: 5, |
| 441 | borderGrabWidth: 15, |
| 442 | minItemHeight: 10, |
| 443 | minItemWidth: 10, |
| 444 | headerHeight: 20, |
| 445 | dragProxyWidth: 300, |
| 446 | dragProxyHeight: 200 |
| 447 | }, |
| 448 | labels: |
| 449 | { |
| 450 | close: "close", |
| 451 | maximise: "maximise", |
| 452 | minimise: "minimise", |
| 453 | popout: "open in new window", |
| 454 | popin: "pop in", |
| 455 | tabDropdown: "additional tabs" |
| 456 | }, |
| 457 | content: [ |
| 458 | { |
| 459 | type: "column", |
| 460 | content: [] |
| 461 | } |
| 462 | ] |
| 463 | }; |
| 464 | } |
| 465 | |
| 466 | getPresentationModeLayoutForSource(state, left) { |
| 467 | const gl = this.getPresentationModeEmptyLayout(); |
| 468 | gl.content[0].content = [ |
| 469 | { |
| 470 | type: "column", |
| 471 | width: 100, |
| 472 | content: this.createSourceContentArray(state, left, left) |
| 473 | }]; |
| 474 | |
| 475 | return gl; |
| 476 | } |
| 477 | |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 478 | getPresentationModeLayoutForComparisonSlide(state, left, right) { |
| 479 | const gl = this.getPresentationModeEmptyLayout(); |
| 480 | gl.content[0].content = [ |
| 481 | { |
| 482 | type: "row", |
| 483 | height: 50, |
| 484 | content: this.createSourceContentArray(state, left, right) |
| 485 | }, |
| 486 | { |
| 487 | type: "row", |
| 488 | height: 50, |
| 489 | content: [ |
| 490 | { |
| 491 | type: "stack", |
| 492 | width: 100, |
| 493 | content: [ |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 494 | this.createDiffComponent(left.compiler + 1, right.compiler + 1) |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 495 | ] |
| 496 | } |
| 497 | ] |
| 498 | } |
| 499 | ]; |
| 500 | |
| 501 | return gl; |
| 502 | } |
| 503 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 504 | createPresentationModeComponents(session, customSessionId, customWidth) { |
| 505 | const stack = { |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 506 | type: "stack", |
| 507 | width: customWidth ? customWidth : 50, |
| 508 | activeItemIndex: 0, |
| 509 | content: [ |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 510 | this.createSourceComponent(session, customSessionId) |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 511 | ] |
| 512 | }; |
| 513 | |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 514 | for (let idxCompiler = 0; idxCompiler < session.compilers.length; idxCompiler++) { |
| 515 | const compiler = session.compilers[idxCompiler]; |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 516 | stack.content.push( |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 517 | this.createCompilerComponent(session, compiler, customSessionId) |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 518 | ); |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 519 | |
| 520 | compiler.specialoutputs.forEach((viewtype) => { |
| 521 | stack.content.push( |
| 522 | this.createSpecialOutputComponent(viewtype, session, idxCompiler, customSessionId) |
| 523 | ); |
| 524 | }); |
| 525 | |
| 526 | compiler.tools.forEach((tool) => { |
| 527 | stack.content.push( |
| 528 | this.createToolComponent(session, idxCompiler + 1, tool.id, tool.args, customSessionId) |
| 529 | ); |
| 530 | }); |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Partouf | 7583df9 | 2020-06-18 23:19:45 +0200 | [diff] [blame] | 533 | for (let idxExecutor = 0; idxExecutor < session.executors.length; idxExecutor++) { |
| 534 | stack.content.push( |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 535 | this.createExecutorComponent(session, session.executors[idxExecutor], customSessionId) |
Partouf | 7583df9 | 2020-06-18 23:19:45 +0200 | [diff] [blame] | 536 | ); |
| 537 | } |
| 538 | |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 539 | return stack; |
| 540 | } |
| 541 | |
| 542 | generatePresentationModeMobileViewerSlides(state) { |
| 543 | const slides = []; |
| 544 | |
| 545 | for (var idxSession = 0; idxSession < state.sessions.length; idxSession++) { |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 546 | const gl = this.getPresentationModeLayoutForSource(state, { |
| 547 | session: idxSession, |
| 548 | compiler: 0 |
| 549 | }); |
Partouf | 7087182 | 2020-06-18 20:53:04 +0200 | [diff] [blame] | 550 | slides.push(gl); |
| 551 | } |
| 552 | |
| 553 | return slides; |
| 554 | } |
| 555 | |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 556 | fromClientState(state) { |
| 557 | this.golden = { |
| 558 | settings: { |
| 559 | hasHeaders: true, |
| 560 | constrainDragToContainer: false, |
| 561 | reorderEnabled: true, |
| 562 | selectionEnabled: false, |
| 563 | popoutWholeStack: false, |
| 564 | blockedPopoutsThrowError: true, |
| 565 | closePopoutsOnUnload: true, |
| 566 | showPopoutIcon: false, |
| 567 | showMaximiseIcon: true, |
| 568 | showCloseIcon: true, |
| 569 | responsiveMode: "onload", |
| 570 | tabOverlapAllowance: 0, |
| 571 | reorderOnTabMenuClick: true, |
| 572 | tabControlOffset: 10 |
| 573 | }, |
| 574 | dimensions: { |
| 575 | borderWidth: 5, |
| 576 | borderGrabWidth: 15, |
| 577 | minItemHeight: 10, |
| 578 | minItemWidth: 10, |
| 579 | headerHeight: 20, |
| 580 | dragProxyWidth: 300, |
| 581 | dragProxyHeight: 200 |
| 582 | }, |
| 583 | labels: { |
| 584 | close: "close", |
| 585 | maximise: "maximise", |
| 586 | minimise: "minimise", |
| 587 | popout: "open in new window", |
| 588 | popin: "pop in", |
| 589 | tabDropdown: "additional tabs" |
| 590 | }, |
| 591 | content: [ |
| 592 | { |
| 593 | type: "row", |
| 594 | content: [ |
| 595 | ] |
| 596 | } |
| 597 | ] |
| 598 | }; |
| 599 | |
| 600 | if (state.sessions.length > 1) { |
| 601 | const sessionWidth = 100.0 / state.sessions.length; |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 602 | |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 603 | for (let idxSession = 0; idxSession < state.sessions.length; idxSession++) { |
| 604 | const session = state.sessions[idxSession]; |
| 605 | |
| 606 | this.golden.content[0].content[idxSession] = { |
| 607 | type: "column", |
| 608 | isClosable: true, |
| 609 | reorderEnabled: true, |
| 610 | width: sessionWidth, |
| 611 | content: [ |
| 612 | { |
| 613 | type: "row", |
| 614 | content: [ |
| 615 | ] |
| 616 | }, |
| 617 | { |
| 618 | type: "row", |
| 619 | content: [ |
| 620 | ] |
| 621 | } |
| 622 | ] |
| 623 | }; |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 624 | |
Partouf | de6d355 | 2018-10-01 19:24:19 +0200 | [diff] [blame] | 625 | let stack = this.newSourceStackFromSession(session, 100.0); |
| 626 | this.golden.content[0].content[idxSession].content[0].content.push(stack); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 627 | |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 628 | const compilerWidth = 100.0 / |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 629 | (1 + session.compilers.length + session.executors.length + |
| 630 | session.countNumberOfSpecialOutputsAndTools()); |
| 631 | |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 632 | if (session.conformanceview) { |
| 633 | const stack = this.newConformanceViewStack(session, compilerWidth, session.conformanceview); |
| 634 | this.golden.content[0].content[idxSession].content[1].content.push(stack); |
| 635 | } |
| 636 | |
| 637 | for (let idxCompiler = 0; idxCompiler < session.compilers.length; idxCompiler++) { |
| 638 | const compiler = session.compilers[idxCompiler]; |
Partouf | de6d355 | 2018-10-01 19:24:19 +0200 | [diff] [blame] | 639 | let stack = this.newCompilerStackFromSession(session, compiler, compilerWidth); |
| 640 | this.golden.content[0].content[idxSession].content[1].content.push(stack); |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 641 | |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 642 | compiler.specialoutputs.forEach((viewtype) => { |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 643 | let stack = this.newStackWithOneComponent(compilerWidth, |
| 644 | this.createSpecialOutputComponent(viewtype, session, idxCompiler)); |
| 645 | |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 646 | if (stack) { |
| 647 | this.golden.content[0].content[idxSession].content[1].content.push(stack); |
| 648 | } |
| 649 | }); |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 650 | |
| 651 | compiler.tools.forEach((tool) => { |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 652 | let stack = this.newToolStackFromCompiler(session, idxCompiler + 1, |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 653 | tool.id, tool.args, compilerWidth); |
| 654 | this.golden.content[0].content[idxSession].content[1].content.push(stack); |
| 655 | }); |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 656 | } |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 657 | |
| 658 | for (let idxExecutor = 0; idxExecutor < session.executors.length; idxExecutor++) { |
| 659 | const executor = session.executors[idxExecutor]; |
| 660 | let stack = this.newExecutorStackFromSession(session, executor, compilerWidth); |
| 661 | this.golden.content[0].content[idxSession].content[1].content.push(stack); |
| 662 | } |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 663 | } |
| 664 | } else if (state.sessions.length === 1) { |
| 665 | const session = state.sessions[0]; |
| 666 | this.golden.content[0] = { |
| 667 | type: "row", |
| 668 | content: [ |
| 669 | ] |
| 670 | }; |
| 671 | |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 672 | const width = 100.0 / (1 + session.compilers.length + session.executors.length + |
| 673 | session.countNumberOfSpecialOutputsAndTools()); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 674 | this.golden.content[0].content.push(this.newSourceStackFromSession(session, width)); |
| 675 | |
Partouf | a51ebd4 | 2018-10-14 00:39:58 +0200 | [diff] [blame] | 676 | if (session.conformanceview) { |
| 677 | const stack = this.newConformanceViewStack(session, width, session.conformanceview); |
| 678 | this.golden.content[0].content.push(stack); |
| 679 | } |
| 680 | |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 681 | for (let idxCompiler = 0; idxCompiler < session.compilers.length; idxCompiler++) { |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 682 | const compiler = session.compilers[idxCompiler]; |
Partouf | de6d355 | 2018-10-01 19:24:19 +0200 | [diff] [blame] | 683 | let stack = this.newCompilerStackFromSession(session, compiler, width); |
| 684 | this.golden.content[0].content.push(stack); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 685 | |
| 686 | compiler.specialoutputs.forEach((viewtype) => { |
Partouf | efe1327 | 2020-06-20 02:12:14 +0200 | [diff] [blame] | 687 | let stack = this.newStackWithOneComponent(width, |
| 688 | this.createSpecialOutputComponent(viewtype, session, idxCompiler)); |
Partouf | de6d355 | 2018-10-01 19:24:19 +0200 | [diff] [blame] | 689 | |
| 690 | if (stack) { |
| 691 | this.golden.content[0].content.push(stack); |
Partouf | 428b09c | 2018-09-30 11:11:53 +0200 | [diff] [blame] | 692 | } |
| 693 | }); |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 694 | |
| 695 | compiler.tools.forEach((tool) => { |
| 696 | let stack = this.newToolStackFromCompiler(session, compiler, idxCompiler + 1, |
| 697 | tool.id, tool.args, width); |
| 698 | this.golden.content[0].content.push(stack); |
| 699 | }); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 700 | } |
Partouf | d5659af | 2019-09-07 17:51:54 +0200 | [diff] [blame] | 701 | |
| 702 | session.executors.forEach((executor) => { |
| 703 | let stack = this.newExecutorStackFromSession(session, executor, width); |
| 704 | this.golden.content[0].content.push(stack); |
| 705 | }); |
Partouf | b99cc61 | 2018-09-26 00:17:49 +0200 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | module.exports = { |
| 711 | ClientStateNormalizer: ClientStateNormalizer, |
| 712 | ClientStateGoldenifier: ClientStateGoldenifier |
| 713 | }; |