Integrate type checker in frontend
This commit is contained in:
parent
846536023d
commit
e6c54052f1
2 changed files with 10 additions and 5 deletions
|
@ -69,12 +69,19 @@ yargs
|
||||||
.string('target')
|
.string('target')
|
||||||
.describe('target', 'The target language to compile to.')
|
.describe('target', 'The target language to compile to.')
|
||||||
.default('target', 'JS')
|
.default('target', 'JS')
|
||||||
|
.boolean('force')
|
||||||
|
.describe('force', 'Ignore as much errors as possible.')
|
||||||
|
.default('force', false)
|
||||||
|
|
||||||
, args => {
|
, args => {
|
||||||
|
|
||||||
const sourceFiles = toArray(args.files as string[] | string).map(parseSourceFile);
|
const sourceFiles = toArray(args.files as string[] | string).map(parseSourceFile);
|
||||||
const program = new Program(sourceFiles);
|
const program = new Program(sourceFiles);
|
||||||
const frontend = new Frontend();
|
const frontend = new Frontend();
|
||||||
|
frontend.typeCheck(program);
|
||||||
|
if (frontend.diagnostics.hasErrors && !args.force) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
frontend.compile(program, args.target);
|
frontend.compile(program, args.target);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -88,19 +88,17 @@ export class Frontend {
|
||||||
return new Package(projectDir);
|
return new Package(projectDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public compile(program: Program, target: string) {
|
public typeCheck(program: Program) {
|
||||||
|
|
||||||
for (const sourceFile of program.getAllSourceFiles()) {
|
for (const sourceFile of program.getAllSourceFiles()) {
|
||||||
this.checker.registerSourceFile(sourceFile as BoltSourceFile);
|
this.checker.registerSourceFile(sourceFile as BoltSourceFile);
|
||||||
}
|
}
|
||||||
for (const sourceFile of program.getAllSourceFiles()) {
|
for (const sourceFile of program.getAllSourceFiles()) {
|
||||||
this.checker.checkSourceFile(sourceFile as BoltSourceFile);
|
this.checker.checkSourceFile(sourceFile as BoltSourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.diagnostics.hasErrors) {
|
|
||||||
throw new Error(`Compilation failed because of type-checking errors.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public compile(program: Program, target: string) {
|
||||||
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
|
|
||||||
case "JS":
|
case "JS":
|
||||||
|
|
Loading…
Reference in a new issue