Initial implementation of 'instanceof'

Works like an assignability check for now / does not yet honor nullables.
This commit is contained in:
dcodeIO
2018-06-07 17:04:41 +02:00
parent cea69a6de1
commit 7478c8a0d3
9 changed files with 472 additions and 4 deletions

View File

@ -45,6 +45,7 @@ export enum NodeKind {
ELEMENTACCESS,
FALSE,
FUNCTION,
INSTANCEOF,
LITERAL,
NEW,
NULL,
@ -346,6 +347,18 @@ export abstract class Node {
return expr;
}
static createInstanceOfExpression(
expression: Expression,
isType: CommonTypeNode,
range: Range
): InstanceOfExpression {
var expr = new InstanceOfExpression();
expr.range = range;
expr.expression = expression; expression.parent = expr;
expr.isType = isType; isType.parent = expr;
return expr;
}
static createIntegerLiteralExpression(
value: I64,
range: Range
@ -1267,6 +1280,16 @@ export class FunctionExpression extends Expression {
declaration: FunctionDeclaration;
}
/** Represents an `instanceof` expression. */
export class InstanceOfExpression extends Expression {
kind = NodeKind.INSTANCEOF;
/** Expression being asserted. */
expression: Expression;
/** Type to test for. */
isType: CommonTypeNode;
}
/** Represents an integer literal expression. */
export class IntegerLiteralExpression extends LiteralExpression {
literalKind = LiteralKind.INTEGER;