Skip to content

Commit

Permalink
Binge of (mostly) mindless tsification (compiler-explorer#6838)
Browse files Browse the repository at this point in the history
Turned on `noImplicitAny` in tsconfig, then went around fixing some
random easy stuff.
Hopefully tsification-PRs with more real content coming up.
  • Loading branch information
OfekShilon authored Sep 7, 2024
1 parent 78e075f commit 9ef46fb
Show file tree
Hide file tree
Showing 98 changed files with 336 additions and 189 deletions.
4 changes: 2 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,11 @@ async function main() {
return options;
}

function isMobileViewer(req) {
function isMobileViewer(req: express.Request) {
return req.header('CloudFront-Is-Mobile-Viewer') === 'true';
}

function renderGoldenLayout(config, metadata, req, res) {
function renderGoldenLayout(config, metadata, req: express.Request, res: express.Response) {
staticHeaders(res);
contentPolicyHeader(res);

Expand Down
2 changes: 1 addition & 1 deletion lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function initConfig(properties: PropertyGetter) {
awsConfig = await loadAwsConfig(properties);
}

export function getConfig(name): string {
export function getConfig(name: string): string {
if (!awsConfigInit) throw new Error("Reading AWS config before it's loaded");
return awsConfig[name] || unwrap(awsProps)<string>(name);
}
22 changes: 13 additions & 9 deletions lib/base-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ export class BaseCompiler implements ICompiler {
}

async objdump(
outputFilename,
outputFilename: string,
result: any,
maxSize: number,
intelAsm,
demangle,
intelAsm: boolean,
demangle: boolean,
staticReloc: boolean | undefined,
dynamicReloc: boolean,
filters: ParseFiltersAndOutputOptions,
Expand Down Expand Up @@ -651,7 +651,7 @@ export class BaseCompiler implements ICompiler {
};
}

protected filename(fn) {
protected filename(fn: string) {
return fn;
}

Expand Down Expand Up @@ -1167,7 +1167,7 @@ export class BaseCompiler implements ICompiler {
return userOptions;
}

async generateAST(inputFilename, options): Promise<ResultLine[]> {
async generateAST(inputFilename: string, options: string[]): Promise<ResultLine[]> {
// These options make Clang produce an AST dump
const newOptions = options
.filter(option => option !== '-fcolor-diagnostics')
Expand Down Expand Up @@ -1659,7 +1659,11 @@ export class BaseCompiler implements ICompiler {
else return null;
}

async checkOutputFileAndDoPostProcess(asmResult, outputFilename: string, filters: ParseFiltersAndOutputOptions) {
async checkOutputFileAndDoPostProcess(
asmResult: CompilationResult,
outputFilename: string,
filters: ParseFiltersAndOutputOptions,
) {
try {
const stat = await fs.stat(outputFilename);
asmResult.asmSize = stat.size;
Expand Down Expand Up @@ -2030,7 +2034,7 @@ export class BaseCompiler implements ICompiler {
}

async handleExecution(
key,
key: CacheKey,
executeParameters: ExecutableExecutionOptions,
bypassCache: BypassCache,
): Promise<CompilationResult> {
Expand Down Expand Up @@ -3126,8 +3130,8 @@ but nothing was dumped. Possible causes are:
outputFilename,
result,
maxSize,
filters.intel,
filters.demangle,
!!filters.intel,
!!filters.demangle,
filters.binaryObject,
false,
filters,
Expand Down
2 changes: 1 addition & 1 deletion lib/cfg/cfg-parsers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class BaseCFGParser {
let rangeBb: BBRange = {nameId: functionName, start: first, end: 0, actionPos: []};
const result: BBRange[] = [];

const newRangeWith = function (oldRange, nameId, start) {
const newRangeWith = function (oldRange: BBRange, nameId: string, start: number) {
return {nameId: nameId, start: start, actionPos: [], end: oldRange.end};
};

Expand Down
6 changes: 4 additions & 2 deletions lib/compilers/ada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@

import path from 'path';

import {CompileChildLibraries} from '../../types/compilation/compilation.interfaces.js';
import type {ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {unwrap} from '../assert.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
import * as utils from '../utils.js';

export class AdaCompiler extends BaseCompiler {
static get key() {
return 'ada';
}

constructor(info: PreliminaryCompilerInfo, env) {
constructor(info: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(info, env);

this.outputFilebase = 'example';
Expand Down Expand Up @@ -85,7 +87,7 @@ export class AdaCompiler extends BaseCompiler {
backendOptions: Record<string, any>,
inputFilename: string,
outputFilename: string,
libraries,
libraries: CompileChildLibraries[],
overrides: ConfiguredOverrides,
) {
backendOptions = backendOptions || {};
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/analysis-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';

// Plain compiler, which just runs the tool and returns whatever the output was
export class AnalysisTool extends BaseCompiler {
static get key() {
return 'analysis-tool';
}

constructor(info: PreliminaryCompilerInfo, env) {
constructor(info: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(
{
// Default is to disable all "cosmetic" filters
Expand Down
17 changes: 11 additions & 6 deletions lib/compilers/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import path from 'path';

import _ from 'underscore';

import type {BuildResult} from '../../types/compilation/compilation.interfaces.js';
import type {BuildResult, 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 {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
import {AsmRaw} from '../parsers/asm-raw.js';
import {fileExists} from '../utils.js';

Expand All @@ -41,7 +42,7 @@ export class AssemblyCompiler extends BaseCompiler {
return 'assembly';
}

constructor(info: PreliminaryCompilerInfo, env) {
constructor(info: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(info, env);
this.asm = new AsmRaw();
}
Expand All @@ -59,7 +60,7 @@ export class AssemblyCompiler extends BaseCompiler {
return [];
}

getGeneratedOutputFilename(fn: string) {
getGeneratedOutputFilename(fn: string): string {
const outputFolder = path.dirname(fn);
const files = fs.readdirSync(outputFolder);

Expand All @@ -77,7 +78,7 @@ export class AssemblyCompiler extends BaseCompiler {
return this.getGeneratedOutputFilename(path.join(dirPath, 'example.asm'));
}

async runReadelf(fullResult, objectFilename) {
async runReadelf(fullResult: BuildResult, objectFilename: string) {
const execOptions = this.getDefaultExecOptions();
execOptions.customCwd = path.dirname(objectFilename);
return await this.doBuildstepAndAddToResult(
Expand All @@ -89,7 +90,7 @@ export class AssemblyCompiler extends BaseCompiler {
);
}

async getArchitecture(fullResult, objectFilename) {
async getArchitecture(fullResult: BuildResult, objectFilename: string) {
const result = await this.runReadelf(fullResult, objectFilename);
const output = result.stdout.map(line => line.text).join('\n');
if (output.includes('ELF32') && output.includes('80386')) {
Expand Down Expand Up @@ -183,7 +184,11 @@ export class AssemblyCompiler extends BaseCompiler {
return fullResult;
}

override checkOutputFileAndDoPostProcess(asmResult, outputFilename, filters: ParseFiltersAndOutputOptions) {
override checkOutputFileAndDoPostProcess(
asmResult: CompilationResult,
outputFilename: string,
filters: ParseFiltersAndOutputOptions,
) {
return this.postProcess(asmResult, outputFilename, filters);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/avrgcc6502.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {ExecutionOptions} from '../../types/compilation/compilation.interfa
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';

export class AvrGcc6502Compiler extends BaseCompiler {
private readonly avrgccpath: string;
Expand All @@ -38,7 +39,7 @@ export class AvrGcc6502Compiler extends BaseCompiler {
return 'avrgcc6502';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(compilerInfo, env);

this.avrgccpath = this.compilerProps<string>(`compiler.${this.compiler.id}.avrgccpath`);
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/beebasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {ArtifactType} from '../../types/tool.interfaces.js';
import {addArtifactToResult} from '../artifact-utils.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
import {AsmParserBeebAsm} from '../parsers/asm-parser-beebasm.js';
import * as utils from '../utils.js';

Expand All @@ -39,7 +40,7 @@ export class BeebAsmCompiler extends BaseCompiler {
return 'beebasm';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(compilerInfo, env);

this.asm = new AsmParserBeebAsm(this.compilerProps);
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/c3c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import path from 'path';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';

export class C3Compiler extends BaseCompiler {
static get key() {
return 'c3c';
}

constructor(info: PreliminaryCompilerInfo, env) {
constructor(info: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(info, env);
this.compiler.supportsIrView = true;
this.compiler.irArg = ['--emit-llvm'];
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import type {ResultLine} from '../../types/resultline/resultline.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';

import {BaseParser} from './argument-parsers.js';

Expand All @@ -36,7 +37,7 @@ export class CarbonCompiler extends BaseCompiler {
return 'carbon';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(compilerInfo, env);
this.compiler.demangler = '';
this.demanglerClass = null;
Expand Down
13 changes: 7 additions & 6 deletions lib/compilers/cc65.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import path from 'path';
import fs from 'fs-extra';
import _ from 'underscore';

import type {CompilationResult} from '../../types/compilation/compilation.interfaces.js';
import type {CompilationResult, CompileChildLibraries} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {ArtifactType} from '../../types/tool.interfaces.js';
import {addArtifactToResult} from '../artifact-utils.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
import {CC65AsmParser} from '../parsers/asm-parser-cc65.js';
import * as utils from '../utils.js';

Expand All @@ -41,14 +42,14 @@ export class Cc65Compiler extends BaseCompiler {
return 'cc65';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(compilerInfo, env);

this.asm = new CC65AsmParser(this.compilerProps);
this.toolchainPath = path.resolve(path.dirname(compilerInfo.exe), '..');
}

override getSharedLibraryPathsAsArguments(libraries, libDownloadPath?) {
override getSharedLibraryPathsAsArguments(libraries: CompileChildLibraries[], libDownloadPath?: string) {
const libPathFlag = this.compiler.libpathFlag || '-L';

if (!libDownloadPath) {
Expand Down Expand Up @@ -96,11 +97,11 @@ export class Cc65Compiler extends BaseCompiler {
}

override async objdump(
outputFilename,
outputFilename: string,
result: CompilationResult,
maxSize: number,
intelAsm,
demangle,
intelAsm: boolean,
demangle: boolean,
staticReloc: boolean,
dynamicReloc: boolean,
filters: ParseFiltersAndOutputOptions,
Expand Down
5 changes: 3 additions & 2 deletions lib/compilers/cerberus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
import {logger} from '../logger.js';
import * as utils from '../utils.js';

Expand All @@ -37,7 +38,7 @@ export class CerberusCompiler extends BaseCompiler {
return 'cerberus';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(
{
// Default is to disable all "cosmetic" filters
Expand All @@ -61,7 +62,7 @@ export class CerberusCompiler extends BaseCompiler {
return path.join(dirPath, `${path.basename(this.compileFilename, this.lang.extensions[0])}.co`);
}

override async objdump(outputFilename, result: any, maxSize: number) {
override async objdump(outputFilename: string, result: any, maxSize: number) {
if (!(await utils.fileExists(outputFilename))) {
result.asm = '<No output file ' + outputFilename + '>';
return result;
Expand Down
11 changes: 6 additions & 5 deletions lib/compilers/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import path from 'path';

import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';

import {CircleParser} from './argument-parsers.js';
Expand All @@ -38,7 +39,7 @@ export class CircleCompiler extends BaseCompiler {
return CircleParser;
}

override optionsForFilter(filters, outputFilename) {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) {
let options = [`-o=${this.filename(outputFilename)}`];
if (this.compiler.intelAsm && filters.intel && !filters.binary) {
options = options.concat(this.compiler.intelAsm.split(' '));
Expand All @@ -49,16 +50,16 @@ export class CircleCompiler extends BaseCompiler {
return options;
}

override getOutputFilename(dirPath, outputFilebase) {
override getOutputFilename(dirPath: string, outputFilebase: string) {
// Do not add '.s' as default implementation does,
// because circle emit assembly file instead of executable.
return path.join(dirPath, outputFilebase);
}

override async runCompiler(
compiler,
options,
inputFilename,
compiler: string,
options: string[],
inputFilename: string,
execOptions: ExecutionOptions & {env: Record<string, string>},
) {
if (!execOptions) {
Expand Down
Loading

0 comments on commit 9ef46fb

Please sign in to comment.