bolt/src/program.ts
Sam Vervaeck f3d8b021c2 Major restructuring
- Add a new `TransformManager` that automatically sets up pipelines
 - Integrate with a small IoC-like-framework
 - Add template code for some new transformations
 - `Program` is not seperate from a new class `Frontend`
 - Fixed some bugs in `src/treegen/`
2020-05-23 14:18:20 +02:00

34 lines
933 B
TypeScript

import { BoltSourceFile, JSSourceFile } from "./ast"
import { FastStringMap } from "./util";
export type SourceFile
= BoltSourceFile
| JSSourceFile
export class Program {
private transformed = new FastStringMap<string, SourceFile>();
constructor(
sourceFiles: BoltSourceFile[]
) {
for (const sourceFile of sourceFiles) {
this.transformed.set(sourceFile.span!.file.fullPath, sourceFile);
}
}
public getAllSourceFiles() {
return this.transformed.values();
}
public updateSourceFile(oldSourceFile: SourceFile, newSourceFile: SourceFile): void {
if (!this.transformed.has(oldSourceFile.span!.file.fullPath)) {
throw new Error(`Could not update ${oldSourceFile.span!.file.origPath} because it was not found in this program.`);
}
this.transformed.delete(oldSourceFile.span!.file.fullPath);
this.transformed.set(newSourceFile.span!.file.fullPath, newSourceFile);
}
}