import { ProceduresEnvironment } from "./ProceduresEnvironment"; import { ClassDeclarator, TypeEnvironment } from "./TypeEnvironment"; // Environment that maps identifiers to procedures, monitors, structs, variables or conditions. // This is typically the environment for the whole program export class ClassesEnvironment extends ProceduresEnvironment { private readonly classes: Map = new Map(); constructor(parentEnvironment: TypeEnvironment) { super(parentEnvironment); } override getDeclarationForClassIdentifier(id: string): ClassDeclarator | undefined { const myRes = this.classes.get(id); if (myRes != undefined) { return myRes; } else { return super.getDeclarationForClassIdentifier(id); } } override _addClass(id: string, decl: ClassDeclarator, calledOn: TypeEnvironment): TypeEnvironment { if (this.classes.has(id)) { throw Error(`Class '${id}' is already defined in scope.`); } else { this.classes.set(id, decl); return calledOn; } } // The method is actually overridden from the grandparent, but TypeScript does not allow to use `override` in this case override getAllClassDeclarators(): ClassDeclarator[] { return Array.from(this.classes.values()); } }