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