/** * One file, checked: what the rules read. Kept apart from `checking.zena` * (which reads files and runs the compiler) so that a host with a * compiler of its own — the language service — can build one without * importing the filesystem. */ import { Diagnostic, DiagnosticSeverity, SemanticModel } from 'compiler/compiler'; import { Module } from 'compiler/ast'; /** One file, checked: its syntax tree, its types, and what the checker said. */ export final class CheckedFile { path: String; source: String; ast: Module; model: SemanticModel; /** The diagnostics reported against this file, not its dependencies. */ diagnostics: GrowableArray; /** * Whether the file is part of the standard library, which the compiler * treats as its own: it synthesizes writes to some of its fields * (`String.#hashCode`) and roots some of its functions by name. */ var isStdlib = false; new(this.path, this.source, this.ast, this.model, this.diagnostics); /** The errors, as `line: message` strings. */ errors(): GrowableArray { let out = new Array(); for (let diagnostic in this.diagnostics) { if (diagnostic.severity == DiagnosticSeverity.Error) { let location = diagnostic.location; let line = if (location != null) i32ToString(location.line) else '?'; out.push(`${line}: ${diagnostic.message}`); } } return out; } hasErrors(): boolean { return this.errors().length > 0; } }