Skip to content

Implement calls to 'super()' #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 31, 2019
6 changes: 0 additions & 6 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ export function nodeIsGenericCallable(kind: NodeKind): bool {
return false;
}

export function nodeIsSuperCall(node: Node): bool {
if (node.kind == NodeKind.EXPRESSION) node = (<ExpressionStatement>node).expression;
return node.kind == NodeKind.CALL
&& (<CallExpression>node).expression.kind == NodeKind.SUPER;
}

/** Base class of all nodes. */
export abstract class Node {

Expand Down
4 changes: 1 addition & 3 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ import {
FieldDeclaration,

nodeIsConstantValue,
nodeIsSuperCall,
isLastStatement,
findDecorator
} from "./ast";
Expand Down Expand Up @@ -1076,8 +1075,7 @@ export class Compiler extends DiagnosticEmitter {
flow.finalize();
} else {
assert(body.kind == NodeKind.BLOCK);
let statements = (<BlockStatement>body).statements;
let stmts = this.compileStatements(statements);
let stmts = this.compileStatements((<BlockStatement>body).statements);
if (instance.is(CommonFlags.MAIN)) {
module.addGlobal("~started", NativeType.I32, true, module.createI32(0));
stmts.unshift(
Expand Down
15 changes: 15 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,21 @@ export class Class extends Element {
}
}

/** Gets the first applicable constructor. */
getfirstConstructor(includingThis: bool = true): Function | null {
if (includingThis && this.constructorInstance) return this.constructorInstance;

// traverse to the top-most derived constructor
var currentBase: Class | null = this.base;
var instance: Function | null = null;
while (currentBase) {
instance = currentBase.constructorInstance;
if (instance) return instance;
currentBase = currentBase.base;
}
return null;
}

/** Tests if a value of this class type is assignable to a target of the specified class type. */
isAssignableTo(target: Class): bool {
var current: Class | null = this;
Expand Down