2020-03-03 14:53:54 +01:00
|
|
|
|
2020-05-25 11:29:19 +02:00
|
|
|
import { Package } from "./common"
|
2020-05-24 21:50:29 +02:00
|
|
|
import { SourceFile } 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(
|
2020-05-25 11:29:19 +02:00
|
|
|
pkgs: Package[]
|
2020-05-23 14:18:20 +02:00
|
|
|
) {
|
2020-05-25 11:29:19 +02:00
|
|
|
for (const pkg of pkgs) {
|
|
|
|
for (const sourceFile of pkg.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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|