Remove ICompiler, other minor type fixes (#7079)

This commit is contained in:
Ofek
2024-11-25 18:36:20 +02:00
committed by GitHub
parent 636675c476
commit 20b8ccaa6f
13 changed files with 47 additions and 62 deletions

View File

@@ -65,7 +65,7 @@ import type {
OptPipelineBackendOptions,
OptPipelineOutput,
} from '../types/compilation/opt-pipeline-output.interfaces.js';
import type {CompilerInfo, ICompiler, PreliminaryCompilerInfo} from '../types/compiler.interfaces.js';
import type {CompilerInfo, PreliminaryCompilerInfo} from '../types/compiler.interfaces.js';
import {
BasicExecutionResult,
ExecutableExecutionOptions,
@@ -180,8 +180,8 @@ export interface SimpleOutputFilenameCompiler {
getOutputFilename(dirPath: string): string;
}
export class BaseCompiler implements ICompiler {
public compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type
export class BaseCompiler {
public compiler: CompilerInfo;
public lang: Language;
protected compileFilename: string;
protected env: CompilationEnvironment;
@@ -2858,7 +2858,7 @@ export class BaseCompiler implements ICompiler {
// it for preprocessor output.
if ((this.compiler.lang === 'c++' || this.compiler.lang === 'c') && options.includes('-E')) {
for (const key in filters) {
filters[key] = false;
(filters as any)[key] = false; // `any` cast is needed because filters can contain non-boolean fields
}
if (filters.binaryObject && !this.compiler.supportsBinaryObject) {

View File

@@ -145,14 +145,15 @@ export class ClientStateNormalizer {
}
}
addToolToCompiler(compilerId, toolId, args, stdin) {
addToolToCompiler(compilerId: number, toolId: string, args: string[], stdin: string) {
const glCompiler = this.findCompilerInGoldenLayout(this.rootContent!, compilerId);
if (glCompiler) {
let compiler;
let compiler: ClientStateCompiler;
if (glCompiler.componentState.source) {
const session = this.normalized.findOrCreateSession(glCompiler.componentState.source);
compiler = session.findOrCreateCompiler(compilerId);
} else if (glCompiler.componentState.tree) {
} else {
assert(glCompiler.componentState.tree);
const tree = this.normalized.findOrCreateTree(glCompiler.componentState.tree);
compiler = tree.findOrCreateCompiler(compilerId);
}
@@ -516,9 +517,9 @@ class GoldenLayoutComponents {
createToolComponent(
session: ClientStateSession | null,
compilerIndex: number,
toolId: number,
args,
stdin,
toolId: string,
args: string[],
stdin: string,
customSessionId?,
): GoldenLayoutComponentStruct {
return {
@@ -832,9 +833,9 @@ export class ClientStateGoldenifier extends GoldenLayoutComponents {
newToolStackFromCompiler(
session: ClientStateSession,
compilerIndex: number,
toolId,
args,
stdin,
toolId: string,
args: string[],
stdin: string,
width: number,
): BasicGoldenLayoutStruct {
return this.newStackWithOneComponent(

View File

@@ -125,7 +125,7 @@ export class CerberusCompiler extends BaseCompiler {
}
const lines = result.asm.split('\n');
const plines = lines.map(l => ({text: l}));
const plines = lines.map((l: string) => ({text: l}));
return {
asm: plines,
languageId: 'core',

View File

@@ -154,7 +154,7 @@ export class DosboxCompiler extends BaseCompiler {
const stdoutFilename = path.join(tempDir, 'STDOUT.TXT');
const stdout = await fs.readFile(stdoutFilename);
(result as any).stdout = stdout.toString('utf8');
result.stdout = stdout.toString('utf8');
return result;
}

View File

@@ -24,13 +24,18 @@
import _ from 'underscore';
import {BypassCache, ExecutionParams, FiledataPair} from '../../types/compilation/compilation.interfaces.js';
import type {ICompiler, PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {
ActiveTool,
BypassCache,
ExecutionParams,
FiledataPair,
} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {SelectedLibraryVersion} from '../../types/libraries/libraries.interfaces.js';
import {CompilerArguments} from '../compiler-arguments.js';
export class FakeCompiler implements ICompiler {
export class FakeCompiler {
public possibleArguments: CompilerArguments;
public lang: any;
private compiler: any;
@@ -81,7 +86,7 @@ export class FakeCompiler implements ICompiler {
backendOptions: Record<string, any>,
filters: ParseFiltersAndOutputOptions,
bypassCache: BypassCache,
tools,
tools: ActiveTool[],
executeParameters: ExecutionParams,
libraries: SelectedLibraryVersion[],
files?: FiledataPair[],

View File

@@ -112,7 +112,7 @@ export class LDCCompiler extends BaseCompiler {
return this.loadASTOutput(
await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions),
) as any;
);
}
async loadASTOutput(result: CompilationResult): Promise<ResultLine[]> {

View File

@@ -27,6 +27,7 @@ import path from 'path';
import fs from 'fs-extra';
import _ from 'underscore';
import {CompilationResult} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {unwrap} from '../assert.js';
@@ -91,14 +92,18 @@ export class NimCompiler extends BaseCompiler {
return path.join(cacheDir, resultName);
}
override async postProcess(result, outputFilename: string, filters: ParseFiltersAndOutputOptions) {
override async postProcess(
result: CompilationResult,
outputFilename: string,
filters: ParseFiltersAndOutputOptions,
) {
const options = result.compilationOptions;
const cacheDir = this.cacheDir(outputFilename);
try {
if (_.intersection(options, ['js', 'check']).length > 0) filters.binary = false;
if (_.intersection(options!, ['js', 'check']).length > 0) filters.binary = false;
else {
filters.binary = true;
const objFile = this.getCacheFile(options, result.inputFilename, cacheDir);
const objFile = this.getCacheFile(options!, result.inputFilename!, cacheDir);
await fs.move(unwrap(objFile), outputFilename);
}
return super.postProcess(result, outputFilename, filters);

View File

@@ -42,7 +42,7 @@ export class SourceHandler {
}
private getActionForSource(source: Source, action: string): ((...args: unknown[]) => Promise<unknown>) | null {
return ALLOWED_ACTIONS.has(action) ? source[action] : null;
return ALLOWED_ACTIONS.has(action) ? (source as any)[action] : null;
}
public handle(req: express.Request, res: express.Response, next: express.NextFunction): void {

View File

@@ -59,7 +59,8 @@ export class S3Bucket {
}
}
async delete(key, path): Promise<boolean> {
// Unused?
async delete(key: string, path: string): Promise<boolean> {
try {
await this.instance.deleteObject({Bucket: this.bucket, Key: `${path}/${key}`});
} catch (x: any) {

View File

@@ -66,6 +66,7 @@ import {Printerinator} from './print-view.js';
import {formatISODate, updateAndCalcTopBarHeight} from './utils.js';
import {localStorage, sessionThenLocalStorage} from './local.js';
import {setupRealDark, takeUsersOutOfRealDark} from './real-dark.js';
import {ParseFiltersAndOutputOptions} from './features/filters.interfaces.js';
const logos = require.context('../views/resources/logos', false, /\.(png|svg)$/);
@@ -256,15 +257,16 @@ function configFromEmbedded(embeddedUrl: string, defaultLangId: string) {
throw new Error('Embed url decode error');
}
if (params && params.source && params.compiler) {
const filters = Object.fromEntries(((params.filters as string) || '').split(',').map(o => [o, true]));
// TODO(jeremy-rifkin): Fix types
const filters: ParseFiltersAndOutputOptions = Object.fromEntries(
((params.filters as string) || '').split(',').map(o => [o, true]),
);
return {
content: [
{
type: 'row',
content: [
Components.getEditorWith(1, params.source, filters as any, defaultLangId),
Components.getCompilerWith(1, filters as any, params.options, params.compiler),
Components.getEditorWith(1, params.source, filters, defaultLangId),
Components.getCompilerWith(1, filters, params.options, params.compiler),
],
},
],

View File

@@ -198,7 +198,7 @@ export class Diff extends MonacoPane<monaco.editor.IStandaloneDiffEditor, DiffSt
compilers: Record<string | number, CompilerEntry> = {};
lhs: DiffStateObject;
rhs: DiffStateObject;
selectize: SelectizeType = {} as any; // will be filled in by the constructor
selectize: SelectizeType;
constructor(hub: Hub, container: Container, state: MonacoPaneState & DiffState) {
super(hub, container, state);

View File

@@ -447,8 +447,7 @@ export class GccDump extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Gcc
...parent,
};
// TODO(jeremy-rifkin)
return state as any;
return state;
}
override close() {

View File

@@ -22,20 +22,11 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {
ActiveTool,
BypassCache,
CompilationResult,
ExecutionParams,
FiledataPair,
} from './compilation/compilation.interfaces.js';
import {AllCompilerOverrideOptions} from './compilation/compiler-overrides.interfaces.js';
import {ICompilerArguments} from './compiler-arguments.interfaces.js';
import {PossibleRuntimeTools} from './execution/execution.interfaces.js';
import {ParseFiltersAndOutputOptions} from './features/filters.interfaces.js';
import {InstructionSet} from './instructionsets.js';
import {Language, LanguageKey} from './languages.interfaces.js';
import {Library, SelectedLibraryVersion} from './libraries/libraries.interfaces.js';
import {LanguageKey} from './languages.interfaces.js';
import {Library} from './libraries/libraries.interfaces.js';
import {Tool, ToolInfo} from './tool.interfaces.js';
export type Remote = {
@@ -167,22 +158,3 @@ export type CompilerInfo = {
export type PreliminaryCompilerInfo = Omit<CompilerInfo, 'version' | 'fullVersion' | 'baseName' | 'disabledFilters'> & {
version?: string;
};
export interface ICompiler {
possibleArguments: ICompilerArguments;
lang: Language;
compile(
source: string,
options: string[],
backendOptions: Record<string, any>,
filters: ParseFiltersAndOutputOptions,
bypassCache: BypassCache,
tools: ActiveTool[],
executeParameters: ExecutionParams,
libraries: SelectedLibraryVersion[],
files: FiledataPair[],
): Promise<any>;
cmake(files: FiledataPair[], key, bypassCache: BypassCache): Promise<CompilationResult>;
initialise(mtime: Date, clientOptions, isPrediscovered: boolean): Promise<ICompiler | null>;
getInfo(): CompilerInfo;
}