bolt/src/program.ts

31 lines
851 B
TypeScript
Raw Normal View History

2020-03-03 14:53:54 +01:00
import { SourceFile } from "./ast"
import { FastStringMap } from "./util";
2020-03-03 14:53:54 +01:00
export class Program {
private transformed = new FastStringMap<string, SourceFile>();
2020-05-10 23:50:42 +02:00
constructor(
sourceFiles: SourceFile[]
) {
for (const sourceFile of sourceFiles) {
this.transformed.set(sourceFile.span!.file.fullPath, sourceFile);
}
}
public getAllSourceFiles() {
return this.transformed.values();
2020-03-03 14:53:54 +01:00
}
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.`);
2020-03-03 14:53:54 +01:00
}
this.transformed.delete(oldSourceFile.span!.file.fullPath);
this.transformed.set(newSourceFile.span!.file.fullPath, newSourceFile);
2020-03-03 14:53:54 +01:00
}
}