|
|
|
@ -16,14 +16,14 @@ export enum TypeModifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export abstract class Type {
|
|
|
|
|
constructor(public modifiers: TypeModifier[] = null) {
|
|
|
|
|
constructor(public modifiers: TypeModifier[]|null = null) {
|
|
|
|
|
if (!modifiers) {
|
|
|
|
|
this.modifiers = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
abstract visitType(visitor: TypeVisitor, context: any): any;
|
|
|
|
|
|
|
|
|
|
hasModifier(modifier: TypeModifier): boolean { return this.modifiers.indexOf(modifier) !== -1; }
|
|
|
|
|
hasModifier(modifier: TypeModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum BuiltinTypeName {
|
|
|
|
@ -37,14 +37,16 @@ export enum BuiltinTypeName {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class BuiltinType extends Type {
|
|
|
|
|
constructor(public name: BuiltinTypeName, modifiers: TypeModifier[] = null) { super(modifiers); }
|
|
|
|
|
constructor(public name: BuiltinTypeName, modifiers: TypeModifier[]|null = null) {
|
|
|
|
|
super(modifiers);
|
|
|
|
|
}
|
|
|
|
|
visitType(visitor: TypeVisitor, context: any): any {
|
|
|
|
|
return visitor.visitBuiltintType(this, context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ExpressionType extends Type {
|
|
|
|
|
constructor(public value: Expression, modifiers: TypeModifier[] = null) { super(modifiers); }
|
|
|
|
|
constructor(public value: Expression, modifiers: TypeModifier[]|null = null) { super(modifiers); }
|
|
|
|
|
visitType(visitor: TypeVisitor, context: any): any {
|
|
|
|
|
return visitor.visitExpressionType(this, context);
|
|
|
|
|
}
|
|
|
|
@ -52,7 +54,7 @@ export class ExpressionType extends Type {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class ArrayType extends Type {
|
|
|
|
|
constructor(public of : Type, modifiers: TypeModifier[] = null) { super(modifiers); }
|
|
|
|
|
constructor(public of : Type, modifiers: TypeModifier[]|null = null) { super(modifiers); }
|
|
|
|
|
visitType(visitor: TypeVisitor, context: any): any {
|
|
|
|
|
return visitor.visitArrayType(this, context);
|
|
|
|
|
}
|
|
|
|
@ -60,7 +62,11 @@ export class ArrayType extends Type {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class MapType extends Type {
|
|
|
|
|
constructor(public valueType: Type, modifiers: TypeModifier[] = null) { super(modifiers); }
|
|
|
|
|
public valueType: Type|null;
|
|
|
|
|
constructor(valueType: Type|null|undefined, modifiers: TypeModifier[]|null = null) {
|
|
|
|
|
super(modifiers);
|
|
|
|
|
this.valueType = valueType || null;
|
|
|
|
|
}
|
|
|
|
|
visitType(visitor: TypeVisitor, context: any): any { return visitor.visitMapType(this, context); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -101,92 +107,99 @@ export enum BinaryOperator {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export abstract class Expression {
|
|
|
|
|
constructor(public type: Type, public sourceSpan?: ParseSourceSpan) {}
|
|
|
|
|
public type: Type|null;
|
|
|
|
|
public sourceSpan: ParseSourceSpan|null;
|
|
|
|
|
|
|
|
|
|
constructor(type: Type|null|undefined, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
this.type = type || null;
|
|
|
|
|
this.sourceSpan = sourceSpan || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
|
|
|
|
|
|
|
|
prop(name: string, sourceSpan?: ParseSourceSpan): ReadPropExpr {
|
|
|
|
|
prop(name: string, sourceSpan?: ParseSourceSpan|null): ReadPropExpr {
|
|
|
|
|
return new ReadPropExpr(this, name, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key(index: Expression, type: Type = null, sourceSpan?: ParseSourceSpan): ReadKeyExpr {
|
|
|
|
|
key(index: Expression, type?: Type|null, sourceSpan?: ParseSourceSpan|null): ReadKeyExpr {
|
|
|
|
|
return new ReadKeyExpr(this, index, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callMethod(name: string|BuiltinMethod, params: Expression[], sourceSpan?: ParseSourceSpan):
|
|
|
|
|
callMethod(name: string|BuiltinMethod, params: Expression[], sourceSpan?: ParseSourceSpan|null):
|
|
|
|
|
InvokeMethodExpr {
|
|
|
|
|
return new InvokeMethodExpr(this, name, params, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callFn(params: Expression[], sourceSpan?: ParseSourceSpan): InvokeFunctionExpr {
|
|
|
|
|
callFn(params: Expression[], sourceSpan?: ParseSourceSpan|null): InvokeFunctionExpr {
|
|
|
|
|
return new InvokeFunctionExpr(this, params, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instantiate(params: Expression[], type: Type = null, sourceSpan?: ParseSourceSpan):
|
|
|
|
|
instantiate(params: Expression[], type?: Type|null, sourceSpan?: ParseSourceSpan|null):
|
|
|
|
|
InstantiateExpr {
|
|
|
|
|
return new InstantiateExpr(this, params, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conditional(trueCase: Expression, falseCase: Expression = null, sourceSpan?: ParseSourceSpan):
|
|
|
|
|
ConditionalExpr {
|
|
|
|
|
conditional(
|
|
|
|
|
trueCase: Expression, falseCase: Expression|null = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null): ConditionalExpr {
|
|
|
|
|
return new ConditionalExpr(this, trueCase, falseCase, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
equals(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
equals(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Equals, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
notEquals(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
notEquals(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.NotEquals, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
identical(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
identical(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Identical, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
notIdentical(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
notIdentical(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.NotIdentical, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
minus(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
minus(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Minus, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
plus(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
plus(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Plus, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
divide(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
divide(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Divide, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
multiply(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
multiply(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Multiply, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
modulo(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
modulo(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Modulo, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
and(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
and(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.And, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
or(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
or(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Or, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
lower(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
lower(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Lower, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
lowerEquals(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
lowerEquals(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.LowerEquals, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
bigger(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
bigger(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.Bigger, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
biggerEquals(rhs: Expression, sourceSpan?: ParseSourceSpan): BinaryOperatorExpr {
|
|
|
|
|
biggerEquals(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
|
|
|
|
return new BinaryOperatorExpr(BinaryOperator.BiggerEquals, this, rhs, null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
isBlank(sourceSpan?: ParseSourceSpan): Expression {
|
|
|
|
|
isBlank(sourceSpan?: ParseSourceSpan|null): Expression {
|
|
|
|
|
// Note: We use equals by purpose here to compare to null and undefined in JS.
|
|
|
|
|
// We use the typed null to allow strictNullChecks to narrow types.
|
|
|
|
|
return this.equals(TYPED_NULL_EXPR, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
cast(type: Type, sourceSpan?: ParseSourceSpan): Expression {
|
|
|
|
|
cast(type: Type, sourceSpan?: ParseSourceSpan|null): Expression {
|
|
|
|
|
return new CastExpr(this, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toStmt(): Statement { return new ExpressionStatement(this); }
|
|
|
|
|
toStmt(): Statement { return new ExpressionStatement(this, null); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum BuiltinVar {
|
|
|
|
@ -197,10 +210,10 @@ export enum BuiltinVar {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ReadVarExpr extends Expression {
|
|
|
|
|
public name: string;
|
|
|
|
|
public builtin: BuiltinVar;
|
|
|
|
|
public name: string|null;
|
|
|
|
|
public builtin: BuiltinVar|null;
|
|
|
|
|
|
|
|
|
|
constructor(name: string|BuiltinVar, type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(name: string|BuiltinVar, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
if (typeof name === 'string') {
|
|
|
|
|
this.name = name;
|
|
|
|
@ -215,6 +228,9 @@ export class ReadVarExpr extends Expression {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set(value: Expression): WriteVarExpr {
|
|
|
|
|
if (!this.name) {
|
|
|
|
|
throw new Error(`Built in variable ${this.builtin} can not be assigned to.`)
|
|
|
|
|
}
|
|
|
|
|
return new WriteVarExpr(this.name, value, null, this.sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -223,7 +239,7 @@ export class ReadVarExpr extends Expression {
|
|
|
|
|
export class WriteVarExpr extends Expression {
|
|
|
|
|
public value: Expression;
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, value: Expression, type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public name: string, value: Expression, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type || value.type, sourceSpan);
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
@ -232,7 +248,7 @@ export class WriteVarExpr extends Expression {
|
|
|
|
|
return visitor.visitWriteVarExpr(this, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toDeclStmt(type: Type = null, modifiers: StmtModifier[] = null): DeclareVarStmt {
|
|
|
|
|
toDeclStmt(type?: Type|null, modifiers?: StmtModifier[]|null): DeclareVarStmt {
|
|
|
|
|
return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -241,8 +257,8 @@ export class WriteVarExpr extends Expression {
|
|
|
|
|
export class WriteKeyExpr extends Expression {
|
|
|
|
|
public value: Expression;
|
|
|
|
|
constructor(
|
|
|
|
|
public receiver: Expression, public index: Expression, value: Expression, type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public receiver: Expression, public index: Expression, value: Expression, type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type || value.type, sourceSpan);
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
@ -255,8 +271,8 @@ export class WriteKeyExpr extends Expression {
|
|
|
|
|
export class WritePropExpr extends Expression {
|
|
|
|
|
public value: Expression;
|
|
|
|
|
constructor(
|
|
|
|
|
public receiver: Expression, public name: string, value: Expression, type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public receiver: Expression, public name: string, value: Expression, type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type || value.type, sourceSpan);
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
@ -272,11 +288,11 @@ export enum BuiltinMethod {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class InvokeMethodExpr extends Expression {
|
|
|
|
|
public name: string;
|
|
|
|
|
public builtin: BuiltinMethod;
|
|
|
|
|
public name: string|null;
|
|
|
|
|
public builtin: BuiltinMethod|null;
|
|
|
|
|
constructor(
|
|
|
|
|
public receiver: Expression, method: string|BuiltinMethod, public args: Expression[],
|
|
|
|
|
type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
if (typeof method === 'string') {
|
|
|
|
|
this.name = method;
|
|
|
|
@ -294,8 +310,8 @@ export class InvokeMethodExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class InvokeFunctionExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public fn: Expression, public args: Expression[], type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public fn: Expression, public args: Expression[], type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -306,8 +322,8 @@ export class InvokeFunctionExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class InstantiateExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public classExpr: Expression, public args: Expression[], type?: Type,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public classExpr: Expression, public args: Expression[], type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -317,7 +333,7 @@ export class InstantiateExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class LiteralExpr extends Expression {
|
|
|
|
|
constructor(public value: any, type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(public value: any, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -328,8 +344,8 @@ export class LiteralExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class ExternalExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public value: CompileIdentifierMetadata, type: Type = null, public typeParams: Type[] = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public value: CompileIdentifierMetadata, type?: Type|null,
|
|
|
|
|
public typeParams: Type[]|null = null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -341,8 +357,8 @@ export class ExternalExpr extends Expression {
|
|
|
|
|
export class ConditionalExpr extends Expression {
|
|
|
|
|
public trueCase: Expression;
|
|
|
|
|
constructor(
|
|
|
|
|
public condition: Expression, trueCase: Expression, public falseCase: Expression = null,
|
|
|
|
|
type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public condition: Expression, trueCase: Expression, public falseCase: Expression|null = null,
|
|
|
|
|
type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type || trueCase.type, sourceSpan);
|
|
|
|
|
this.trueCase = trueCase;
|
|
|
|
|
}
|
|
|
|
@ -353,7 +369,7 @@ export class ConditionalExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class NotExpr extends Expression {
|
|
|
|
|
constructor(public condition: Expression, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(public condition: Expression, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(BOOL_TYPE, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -362,7 +378,7 @@ export class NotExpr extends Expression {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class CastExpr extends Expression {
|
|
|
|
|
constructor(public value: Expression, type: Type, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(public value: Expression, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -372,21 +388,21 @@ export class CastExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class FnParam {
|
|
|
|
|
constructor(public name: string, public type: Type = null) {}
|
|
|
|
|
constructor(public name: string, public type: Type|null = null) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class FunctionExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public params: FnParam[], public statements: Statement[], type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public params: FnParam[], public statements: Statement[], type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
|
return visitor.visitFunctionExpr(this, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toDeclStmt(name: string, modifiers: StmtModifier[] = null): DeclareFunctionStmt {
|
|
|
|
|
toDeclStmt(name: string, modifiers: StmtModifier[]|null = null): DeclareFunctionStmt {
|
|
|
|
|
return new DeclareFunctionStmt(
|
|
|
|
|
name, this.params, this.statements, this.type, modifiers, this.sourceSpan);
|
|
|
|
|
}
|
|
|
|
@ -396,8 +412,8 @@ export class FunctionExpr extends Expression {
|
|
|
|
|
export class BinaryOperatorExpr extends Expression {
|
|
|
|
|
public lhs: Expression;
|
|
|
|
|
constructor(
|
|
|
|
|
public operator: BinaryOperator, lhs: Expression, public rhs: Expression, type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public operator: BinaryOperator, lhs: Expression, public rhs: Expression, type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type || lhs.type, sourceSpan);
|
|
|
|
|
this.lhs = lhs;
|
|
|
|
|
}
|
|
|
|
@ -409,8 +425,8 @@ export class BinaryOperatorExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class ReadPropExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public receiver: Expression, public name: string, type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public receiver: Expression, public name: string, type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -424,8 +440,8 @@ export class ReadPropExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class ReadKeyExpr extends Expression {
|
|
|
|
|
constructor(
|
|
|
|
|
public receiver: Expression, public index: Expression, type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public receiver: Expression, public index: Expression, type?: Type|null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -439,7 +455,7 @@ export class ReadKeyExpr extends Expression {
|
|
|
|
|
|
|
|
|
|
export class LiteralArrayExpr extends Expression {
|
|
|
|
|
public entries: Expression[];
|
|
|
|
|
constructor(entries: Expression[], type: Type = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(entries: Expression[], type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
this.entries = entries;
|
|
|
|
|
}
|
|
|
|
@ -453,9 +469,9 @@ export class LiteralMapEntry {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class LiteralMapExpr extends Expression {
|
|
|
|
|
public valueType: Type = null;
|
|
|
|
|
public valueType: Type|null = null;
|
|
|
|
|
constructor(
|
|
|
|
|
public entries: LiteralMapEntry[], type: MapType = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public entries: LiteralMapEntry[], type?: MapType|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(type, sourceSpan);
|
|
|
|
|
if (type) {
|
|
|
|
|
this.valueType = type.valueType;
|
|
|
|
@ -467,7 +483,7 @@ export class LiteralMapExpr extends Expression {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class CommaExpr extends Expression {
|
|
|
|
|
constructor(public parts: Expression[], sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
constructor(public parts: Expression[], sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(parts[parts.length - 1].type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitExpression(visitor: ExpressionVisitor, context: any): any {
|
|
|
|
@ -497,12 +513,12 @@ export interface ExpressionVisitor {
|
|
|
|
|
visitCommaExpr(ast: CommaExpr, context: any): any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const THIS_EXPR = new ReadVarExpr(BuiltinVar.This);
|
|
|
|
|
export const SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super);
|
|
|
|
|
export const CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError);
|
|
|
|
|
export const CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack);
|
|
|
|
|
export const NULL_EXPR = new LiteralExpr(null, null);
|
|
|
|
|
export const TYPED_NULL_EXPR = new LiteralExpr(null, INFERRED_TYPE);
|
|
|
|
|
export const THIS_EXPR = new ReadVarExpr(BuiltinVar.This, null, null);
|
|
|
|
|
export const SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super, null, null);
|
|
|
|
|
export const CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError, null, null);
|
|
|
|
|
export const CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack, null, null);
|
|
|
|
|
export const NULL_EXPR = new LiteralExpr(null, null, null);
|
|
|
|
|
export const TYPED_NULL_EXPR = new LiteralExpr(null, INFERRED_TYPE, null);
|
|
|
|
|
|
|
|
|
|
//// Statements
|
|
|
|
|
export enum StmtModifier {
|
|
|
|
@ -511,23 +527,24 @@ export enum StmtModifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export abstract class Statement {
|
|
|
|
|
constructor(public modifiers: StmtModifier[] = null, public sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
if (!modifiers) {
|
|
|
|
|
this.modifiers = [];
|
|
|
|
|
}
|
|
|
|
|
public modifiers: StmtModifier[];
|
|
|
|
|
public sourceSpan: ParseSourceSpan|null;
|
|
|
|
|
constructor(modifiers?: StmtModifier[]|null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
this.modifiers = modifiers || [];
|
|
|
|
|
this.sourceSpan = sourceSpan || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract visitStatement(visitor: StatementVisitor, context: any): any;
|
|
|
|
|
|
|
|
|
|
hasModifier(modifier: StmtModifier): boolean { return this.modifiers.indexOf(modifier) !== -1; }
|
|
|
|
|
hasModifier(modifier: StmtModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class DeclareVarStmt extends Statement {
|
|
|
|
|
public type: Type;
|
|
|
|
|
public type: Type|null;
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, public value: Expression, type: Type = null,
|
|
|
|
|
modifiers: StmtModifier[] = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public name: string, public value: Expression, type?: Type|null,
|
|
|
|
|
modifiers: StmtModifier[]|null = null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(modifiers, sourceSpan);
|
|
|
|
|
this.type = type || value.type;
|
|
|
|
|
}
|
|
|
|
@ -538,10 +555,12 @@ export class DeclareVarStmt extends Statement {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DeclareFunctionStmt extends Statement {
|
|
|
|
|
public type: Type|null;
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, public params: FnParam[], public statements: Statement[],
|
|
|
|
|
public type: Type = null, modifiers: StmtModifier[] = null, sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
type?: Type|null, modifiers: StmtModifier[]|null = null, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(modifiers, sourceSpan);
|
|
|
|
|
this.type = type || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
@ -550,7 +569,9 @@ export class DeclareFunctionStmt extends Statement {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ExpressionStatement extends Statement {
|
|
|
|
|
constructor(public expr: Expression, sourceSpan?: ParseSourceSpan) { super(null, sourceSpan); }
|
|
|
|
|
constructor(public expr: Expression, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
|
return visitor.visitExpressionStmt(this, context);
|
|
|
|
@ -559,23 +580,27 @@ export class ExpressionStatement extends Statement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class ReturnStatement extends Statement {
|
|
|
|
|
constructor(public value: Expression, sourceSpan?: ParseSourceSpan) { super(null, sourceSpan); }
|
|
|
|
|
constructor(public value: Expression, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
|
return visitor.visitReturnStmt(this, context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class AbstractClassPart {
|
|
|
|
|
constructor(public type: Type = null, public modifiers: StmtModifier[]) {
|
|
|
|
|
public type: Type|null;
|
|
|
|
|
constructor(type: Type|null|undefined, public modifiers: StmtModifier[]|null) {
|
|
|
|
|
if (!modifiers) {
|
|
|
|
|
this.modifiers = [];
|
|
|
|
|
}
|
|
|
|
|
this.type = type || null;
|
|
|
|
|
}
|
|
|
|
|
hasModifier(modifier: StmtModifier): boolean { return this.modifiers.indexOf(modifier) !== -1; }
|
|
|
|
|
hasModifier(modifier: StmtModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ClassField extends AbstractClassPart {
|
|
|
|
|
constructor(public name: string, type: Type = null, modifiers: StmtModifier[] = null) {
|
|
|
|
|
constructor(public name: string, type?: Type|null, modifiers: StmtModifier[]|null = null) {
|
|
|
|
|
super(type, modifiers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -583,8 +608,8 @@ export class ClassField extends AbstractClassPart {
|
|
|
|
|
|
|
|
|
|
export class ClassMethod extends AbstractClassPart {
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, public params: FnParam[], public body: Statement[], type: Type = null,
|
|
|
|
|
modifiers: StmtModifier[] = null) {
|
|
|
|
|
public name: string|null, public params: FnParam[], public body: Statement[],
|
|
|
|
|
type?: Type|null, modifiers: StmtModifier[]|null = null) {
|
|
|
|
|
super(type, modifiers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -592,8 +617,8 @@ export class ClassMethod extends AbstractClassPart {
|
|
|
|
|
|
|
|
|
|
export class ClassGetter extends AbstractClassPart {
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, public body: Statement[], type: Type = null,
|
|
|
|
|
modifiers: StmtModifier[] = null) {
|
|
|
|
|
public name: string, public body: Statement[], type?: Type|null,
|
|
|
|
|
modifiers: StmtModifier[]|null = null) {
|
|
|
|
|
super(type, modifiers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -601,10 +626,10 @@ export class ClassGetter extends AbstractClassPart {
|
|
|
|
|
|
|
|
|
|
export class ClassStmt extends Statement {
|
|
|
|
|
constructor(
|
|
|
|
|
public name: string, public parent: Expression, public fields: ClassField[],
|
|
|
|
|
public name: string, public parent: Expression|null, public fields: ClassField[],
|
|
|
|
|
public getters: ClassGetter[], public constructorMethod: ClassMethod,
|
|
|
|
|
public methods: ClassMethod[], modifiers: StmtModifier[] = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public methods: ClassMethod[], modifiers: StmtModifier[]|null = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(modifiers, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
@ -616,7 +641,7 @@ export class ClassStmt extends Statement {
|
|
|
|
|
export class IfStmt extends Statement {
|
|
|
|
|
constructor(
|
|
|
|
|
public condition: Expression, public trueCase: Statement[],
|
|
|
|
|
public falseCase: Statement[] = [], sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public falseCase: Statement[] = [], sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
@ -626,7 +651,9 @@ export class IfStmt extends Statement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class CommentStmt extends Statement {
|
|
|
|
|
constructor(public comment: string, sourceSpan?: ParseSourceSpan) { super(null, sourceSpan); }
|
|
|
|
|
constructor(public comment: string, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
|
return visitor.visitCommentStmt(this, context);
|
|
|
|
|
}
|
|
|
|
@ -635,7 +662,8 @@ export class CommentStmt extends Statement {
|
|
|
|
|
|
|
|
|
|
export class TryCatchStmt extends Statement {
|
|
|
|
|
constructor(
|
|
|
|
|
public bodyStmts: Statement[], public catchStmts: Statement[], sourceSpan?: ParseSourceSpan) {
|
|
|
|
|
public bodyStmts: Statement[], public catchStmts: Statement[],
|
|
|
|
|
sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
@ -645,7 +673,9 @@ export class TryCatchStmt extends Statement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class ThrowStmt extends Statement {
|
|
|
|
|
constructor(public error: Expression, sourceSpan?: ParseSourceSpan) { super(null, sourceSpan); }
|
|
|
|
|
constructor(public error: Expression, sourceSpan?: ParseSourceSpan|null) {
|
|
|
|
|
super(null, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
visitStatement(visitor: StatementVisitor, context: any): any {
|
|
|
|
|
return visitor.visitThrowStmt(this, context);
|
|
|
|
|
}
|
|
|
|
@ -697,7 +727,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
|
|
|
|
const method = ast.builtin || ast.name;
|
|
|
|
|
return this.transformExpr(
|
|
|
|
|
new InvokeMethodExpr(
|
|
|
|
|
ast.receiver.visitExpression(this, context), method,
|
|
|
|
|
ast.receiver.visitExpression(this, context), method !,
|
|
|
|
|
this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan),
|
|
|
|
|
context);
|
|
|
|
|
}
|
|
|
|
@ -729,7 +759,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
|
|
|
|
new ConditionalExpr(
|
|
|
|
|
ast.condition.visitExpression(this, context),
|
|
|
|
|
ast.trueCase.visitExpression(this, context),
|
|
|
|
|
ast.falseCase.visitExpression(this, context), ast.type, ast.sourceSpan),
|
|
|
|
|
ast.falseCase !.visitExpression(this, context), ast.type, ast.sourceSpan),
|
|
|
|
|
context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -784,7 +814,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
|
|
|
|
const entries = ast.entries.map(
|
|
|
|
|
(entry): LiteralMapEntry => new LiteralMapEntry(
|
|
|
|
|
entry.key, entry.value.visitExpression(this, context), entry.quoted, ));
|
|
|
|
|
const mapType = new MapType(ast.valueType);
|
|
|
|
|
const mapType = new MapType(ast.valueType, null);
|
|
|
|
|
return this.transformExpr(new LiteralMapExpr(entries, mapType, ast.sourceSpan), context);
|
|
|
|
|
}
|
|
|
|
|
visitCommaExpr(ast: CommaExpr, context: any): any {
|
|
|
|
@ -822,7 +852,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
visitDeclareClassStmt(stmt: ClassStmt, context: any): any {
|
|
|
|
|
const parent = stmt.parent.visitExpression(this, context);
|
|
|
|
|
const parent = stmt.parent !.visitExpression(this, context);
|
|
|
|
|
const getters = stmt.getters.map(
|
|
|
|
|
getter => new ClassGetter(
|
|
|
|
|
getter.name, this.visitAllStatements(getter.body, context), getter.type,
|
|
|
|
@ -911,7 +941,7 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
|
|
|
|
|
visitConditionalExpr(ast: ConditionalExpr, context: any): any {
|
|
|
|
|
ast.condition.visitExpression(this, context);
|
|
|
|
|
ast.trueCase.visitExpression(this, context);
|
|
|
|
|
ast.falseCase.visitExpression(this, context);
|
|
|
|
|
ast.falseCase !.visitExpression(this, context);
|
|
|
|
|
return ast;
|
|
|
|
|
}
|
|
|
|
|
visitNotExpr(ast: NotExpr, context: any): any {
|
|
|
|
@ -972,7 +1002,7 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
|
|
|
|
|
return stmt;
|
|
|
|
|
}
|
|
|
|
|
visitDeclareClassStmt(stmt: ClassStmt, context: any): any {
|
|
|
|
|
stmt.parent.visitExpression(this, context);
|
|
|
|
|
stmt.parent !.visitExpression(this, context);
|
|
|
|
|
stmt.getters.forEach(getter => this.visitAllStatements(getter.body, context));
|
|
|
|
|
if (stmt.constructorMethod) {
|
|
|
|
|
this.visitAllStatements(stmt.constructorMethod.body, context);
|
|
|
|
@ -1018,13 +1048,15 @@ class _ReadVarVisitor extends RecursiveAstVisitor {
|
|
|
|
|
return stmt;
|
|
|
|
|
}
|
|
|
|
|
visitReadVarExpr(ast: ReadVarExpr, context: any): any {
|
|
|
|
|
this.varNames.add(ast.name);
|
|
|
|
|
if (ast.name) {
|
|
|
|
|
this.varNames.add(ast.name);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function applySourceSpanToStatementIfNeeded(
|
|
|
|
|
stmt: Statement, sourceSpan: ParseSourceSpan): Statement {
|
|
|
|
|
stmt: Statement, sourceSpan: ParseSourceSpan | null): Statement {
|
|
|
|
|
if (!sourceSpan) {
|
|
|
|
|
return stmt;
|
|
|
|
|
}
|
|
|
|
@ -1033,7 +1065,7 @@ export function applySourceSpanToStatementIfNeeded(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function applySourceSpanToExpressionIfNeeded(
|
|
|
|
|
expr: Expression, sourceSpan: ParseSourceSpan): Expression {
|
|
|
|
|
expr: Expression, sourceSpan: ParseSourceSpan | null): Expression {
|
|
|
|
|
if (!sourceSpan) {
|
|
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
@ -1069,48 +1101,51 @@ class _ApplySourceSpanTransformer extends AstTransformer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function variable(
|
|
|
|
|
name: string, type: Type = null, sourceSpan?: ParseSourceSpan): ReadVarExpr {
|
|
|
|
|
name: string, type?: Type | null, sourceSpan?: ParseSourceSpan | null): ReadVarExpr {
|
|
|
|
|
return new ReadVarExpr(name, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function importExpr(
|
|
|
|
|
id: CompileIdentifierMetadata, typeParams: Type[] = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan): ExternalExpr {
|
|
|
|
|
id: CompileIdentifierMetadata, typeParams: Type[] | null = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan | null): ExternalExpr {
|
|
|
|
|
return new ExternalExpr(id, null, typeParams, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function importType(
|
|
|
|
|
id: CompileIdentifierMetadata, typeParams: Type[] = null,
|
|
|
|
|
typeModifiers: TypeModifier[] = null): ExpressionType {
|
|
|
|
|
return id != null ? expressionType(importExpr(id, typeParams), typeModifiers) : null;
|
|
|
|
|
id: CompileIdentifierMetadata, typeParams: Type[] | null = null,
|
|
|
|
|
typeModifiers: TypeModifier[] | null = null): ExpressionType|null {
|
|
|
|
|
return id != null ? expressionType(importExpr(id, typeParams, null), typeModifiers) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function expressionType(
|
|
|
|
|
expr: Expression, typeModifiers: TypeModifier[] = null): ExpressionType {
|
|
|
|
|
return expr != null ? new ExpressionType(expr, typeModifiers) : null;
|
|
|
|
|
expr: Expression, typeModifiers: TypeModifier[] | null = null): ExpressionType|null {
|
|
|
|
|
return expr != null ? new ExpressionType(expr, typeModifiers) ! : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function literalArr(
|
|
|
|
|
values: Expression[], type: Type = null, sourceSpan?: ParseSourceSpan): LiteralArrayExpr {
|
|
|
|
|
values: Expression[], type?: Type | null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan | null): LiteralArrayExpr {
|
|
|
|
|
return new LiteralArrayExpr(values, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function literalMap(
|
|
|
|
|
values: [string, Expression][], type: MapType = null, quoted: boolean = false): LiteralMapExpr {
|
|
|
|
|
values: [string, Expression][], type: MapType | null = null,
|
|
|
|
|
quoted: boolean = false): LiteralMapExpr {
|
|
|
|
|
return new LiteralMapExpr(
|
|
|
|
|
values.map(entry => new LiteralMapEntry(entry[0], entry[1], quoted)), type);
|
|
|
|
|
values.map(entry => new LiteralMapEntry(entry[0], entry[1], quoted)), type, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function not(expr: Expression, sourceSpan?: ParseSourceSpan): NotExpr {
|
|
|
|
|
export function not(expr: Expression, sourceSpan?: ParseSourceSpan | null): NotExpr {
|
|
|
|
|
return new NotExpr(expr, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fn(
|
|
|
|
|
params: FnParam[], body: Statement[], type: Type = null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan): FunctionExpr {
|
|
|
|
|
params: FnParam[], body: Statement[], type?: Type | null,
|
|
|
|
|
sourceSpan?: ParseSourceSpan | null): FunctionExpr {
|
|
|
|
|
return new FunctionExpr(params, body, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function literal(value: any, type: Type = null, sourceSpan?: ParseSourceSpan): LiteralExpr {
|
|
|
|
|
export function literal(
|
|
|
|
|
value: any, type?: Type | null, sourceSpan?: ParseSourceSpan | null): LiteralExpr {
|
|
|
|
|
return new LiteralExpr(value, type, sourceSpan);
|
|
|
|
|
}
|
|
|
|
|