From 876d4078d7013e8c926056d620f7b2fbae2b71eb Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 4 Sep 2022 08:34:53 +0300 Subject: [PATCH 01/22] rename statement -> body in all loop-related AST nodes --- src/ast.ts | 16 ++++++++-------- src/compiler.ts | 6 +++--- src/extra/ast.ts | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index bc070e7f0b..48ae839797 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1833,8 +1833,8 @@ export class ContinueStatement extends Statement { /** Represents a `do` statement. */ export class DoStatement extends Statement { constructor( - /** Statement being looped over. */ - public statement: Statement, + /** Body statement being looped over. */ + public body: Statement, /** Condition when to repeat. */ public condition: Expression, /** Source range. */ @@ -1999,8 +1999,8 @@ export class ForStatement extends Statement { public condition: Expression | null, /** Incrementor expression, if present. */ public incrementor: Expression | null, - /** Statement being looped over. */ - public statement: Statement, + /** Body statment being looped over. */ + public body: Statement, /** Source range. */ range: Range ) { @@ -2015,8 +2015,8 @@ export class ForOfStatement extends Statement { public variable: Statement, /** Iterable expression being iterated. */ public iterable: Expression, - /** Statement being looped over. */ - public statement: Statement, + /** Body statment being looped over. */ + public body: Statement, /** Source range. */ range: Range ) { @@ -2355,8 +2355,8 @@ export class WhileStatement extends Statement { constructor( /** Condition expression. */ public condition: Expression, - /** Statement being looped over. */ - public statement: Statement, + /** Body statement being looped over. */ + public body: Statement, /** Source range. */ range: Range ) { diff --git a/src/compiler.ts b/src/compiler.ts index f2eaac1bba..ec149c560e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2323,7 +2323,7 @@ export class Compiler extends DiagnosticEmitter { var bodyFlow = flow.fork(); this.currentFlow = bodyFlow; var bodyStmts = new Array(); - var body = statement.statement; + var body = statement.body; if (body.kind == NodeKind.BLOCK) { this.compileStatements((body).statements, false, bodyStmts); } else { @@ -2528,7 +2528,7 @@ export class Compiler extends DiagnosticEmitter { bodyFlow.inheritNonnullIfTrue(condExpr); this.currentFlow = bodyFlow; var bodyStmts = new Array(); - var body = statement.statement; + var body = statement.body; if (body.kind == NodeKind.BLOCK) { this.compileStatements((body).statements, false, bodyStmts); } else { @@ -3209,7 +3209,7 @@ export class Compiler extends DiagnosticEmitter { bodyFlow.inheritNonnullIfTrue(condExpr); this.currentFlow = bodyFlow; var bodyStmts = new Array(); - var body = statement.statement; + var body = statement.body; if (body.kind == NodeKind.BLOCK) { this.compileStatements((body).statements, false, bodyStmts); } else { diff --git a/src/extra/ast.ts b/src/extra/ast.ts index fff9aaccb6..ec5d3577a1 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -909,8 +909,8 @@ export class ASTBuilder { visitDoStatement(node: DoStatement): void { var sb = this.sb; sb.push("do "); - this.visitNode(node.statement); - if (node.statement.kind == NodeKind.BLOCK) { + this.visitNode(node.body); + if (node.body.kind == NodeKind.BLOCK) { sb.push(" while ("); } else { sb.push(";\n"); @@ -1090,7 +1090,7 @@ export class ASTBuilder { sb.push(";"); } sb.push(") "); - this.visitNode(node.statement); + this.visitNode(node.body); } visitForOfStatement(node: ForOfStatement): void { @@ -1100,7 +1100,7 @@ export class ASTBuilder { sb.push(" of "); this.visitNode(node.iterable); sb.push(") "); - this.visitNode(node.statement); + this.visitNode(node.body); } visitFunctionDeclaration(node: FunctionDeclaration, isDefault: bool = false): void { @@ -1530,12 +1530,12 @@ export class ASTBuilder { var sb = this.sb; sb.push("while ("); this.visitNode(node.condition); - var statement = node.statement; - if (statement.kind == NodeKind.EMPTY) { + var body = node.body; + if (body.kind == NodeKind.EMPTY) { sb.push(")"); } else { sb.push(") "); - this.visitNode(node.statement); + this.visitNode(body); } } From 938358ae498a4c6bc010d0ae9ab97f47ad2aeb8a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 4 Sep 2022 08:48:49 +0300 Subject: [PATCH 02/22] add Node.isEmpty --- src/ast.ts | 4 ++++ src/extra/ast.ts | 2 +- tests/parser/arrow-functions.ts | 1 + tests/parser/arrow-functions.ts.fixture.ts | 1 + tests/parser/export-default-in-namespace.ts.fixture.ts | 2 +- 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 48ae839797..c134fbb475 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -814,6 +814,10 @@ export abstract class Node { get isAccessOnSuper(): bool { return this.isAccessOn(NodeKind.SUPER); } + + get isEmpty(): bool { + return this.kind == NodeKind.EMPTY; + } } // types diff --git a/src/extra/ast.ts b/src/extra/ast.ts index ec5d3577a1..c907276f8e 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -1531,7 +1531,7 @@ export class ASTBuilder { sb.push("while ("); this.visitNode(node.condition); var body = node.body; - if (body.kind == NodeKind.EMPTY) { + if (body.isEmpty) { sb.push(")"); } else { sb.push(") "); diff --git a/tests/parser/arrow-functions.ts b/tests/parser/arrow-functions.ts index 8c842f65c2..d1ae00bdb5 100644 --- a/tests/parser/arrow-functions.ts +++ b/tests/parser/arrow-functions.ts @@ -5,6 +5,7 @@ (x?, y?) => x; (x?: i32) => x; x => x; +() => {}; // not an array function (b ? x : y); diff --git a/tests/parser/arrow-functions.ts.fixture.ts b/tests/parser/arrow-functions.ts.fixture.ts index 3f049b2a6a..aae3fe4715 100644 --- a/tests/parser/arrow-functions.ts.fixture.ts +++ b/tests/parser/arrow-functions.ts.fixture.ts @@ -4,5 +4,6 @@ (x?, y?) => x; (x?: i32) => x; x => x; +() => {}; (b ? x : y); (b ? f : g)(); diff --git a/tests/parser/export-default-in-namespace.ts.fixture.ts b/tests/parser/export-default-in-namespace.ts.fixture.ts index 5f0dfe42e8..2874bfc249 100644 --- a/tests/parser/export-default-in-namespace.ts.fixture.ts +++ b/tests/parser/export-default-in-namespace.ts.fixture.ts @@ -1 +1 @@ -// ERROR 1319: "A default export can only be used in a module." in export-default-in-namespace.ts(2,3+18) +// ERROR 1319: "A default export can only be used in a module." in export-default-in-namespace.ts(2,3+18) From 58fa85cf015beb8c6d503e45808a657ae8ef4e4e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 4 Sep 2022 09:18:26 +0300 Subject: [PATCH 03/22] fix typos in comments --- src/ast.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index c134fbb475..bb48e6dae3 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -2003,7 +2003,7 @@ export class ForStatement extends Statement { public condition: Expression | null, /** Incrementor expression, if present. */ public incrementor: Expression | null, - /** Body statment being looped over. */ + /** Body statement being looped over. */ public body: Statement, /** Source range. */ range: Range @@ -2019,7 +2019,7 @@ export class ForOfStatement extends Statement { public variable: Statement, /** Iterable expression being iterated. */ public iterable: Expression, - /** Body statment being looped over. */ + /** Body statement being looped over. */ public body: Statement, /** Source range. */ range: Range From 31d7ff8ac615d2f9d6df3087c2069ee8f6f6c76a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 4 Sep 2022 09:57:31 +0300 Subject: [PATCH 04/22] add isDefault getter for SwitchCase node --- src/ast.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ast.ts b/src/ast.ts index bb48e6dae3..d40c6802f1 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -2228,6 +2228,10 @@ export class SwitchCase extends Node { ) { super(NodeKind.SWITCHCASE, range); } + + get isDefault(): bool { + return this.label == null; + } } /** Represents a `switch` statement. */ From 77c4173ab59043a32625eea55cc89e99610a529e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 4 Sep 2022 11:34:31 +0300 Subject: [PATCH 05/22] statements -> bodyStatements for TryStatment node --- src/ast.ts | 18 +++++++++--------- src/extra/ast.ts | 6 +++--- src/parser.ts | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index d40c6802f1..45c01999ae 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -473,11 +473,11 @@ export abstract class Node { } static createDoStatement( - statement: Statement, + body: Statement, condition: Expression, range: Range ): DoStatement { - return new DoStatement(statement, condition, range); + return new DoStatement(body, condition, range); } static createEmptyStatement( @@ -606,19 +606,19 @@ export abstract class Node { initializer: Statement | null, condition: Expression | null, incrementor: Expression | null, - statement: Statement, + body: Statement, range: Range ): ForStatement { - return new ForStatement(initializer, condition, incrementor, statement, range); + return new ForStatement(initializer, condition, incrementor, body, range); } static createForOfStatement( variable: Statement, iterable: Expression, - statement: Statement, + body: Statement, range: Range ): ForOfStatement { - return new ForOfStatement(variable, iterable, statement, range); + return new ForOfStatement(variable, iterable, body, range); } static createFunctionDeclaration( @@ -696,13 +696,13 @@ export abstract class Node { } static createTryStatement( - statements: Statement[], + bodyStatements: Statement[], catchVariable: IdentifierExpression | null, catchStatements: Statement[] | null, finallyStatements: Statement[] | null, range: Range ): TryStatement { - return new TryStatement(statements, catchVariable, catchStatements, finallyStatements, range); + return new TryStatement(bodyStatements, catchVariable, catchStatements, finallyStatements, range); } static createTypeDeclaration( @@ -2264,7 +2264,7 @@ export class ThrowStatement extends Statement { export class TryStatement extends Statement { constructor( /** Contained statements. */ - public statements: Statement[], + public bodyStatements: Statement[], /** Exception variable name, if a `catch` clause is present. */ public catchVariable: IdentifierExpression | null, /** Statements being executed on catch, if a `catch` clause is present. */ diff --git a/src/extra/ast.ts b/src/extra/ast.ts index c907276f8e..3743e1b149 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -1420,10 +1420,10 @@ export class ASTBuilder { var sb = this.sb; sb.push("try {\n"); var indentLevel = ++this.indentLevel; - var statements = node.statements; - for (let i = 0, k = statements.length; i < k; ++i) { + var bodyStatements = node.bodyStatements; + for (let i = 0, k = bodyStatements.length; i < k; ++i) { indent(sb, indentLevel); - this.visitNodeAndTerminate(statements[i]); + this.visitNodeAndTerminate(bodyStatements[i]); } var catchVariable = node.catchVariable; if (catchVariable) { diff --git a/src/parser.ts b/src/parser.ts index 314d3a2cdf..73f0751bd7 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3423,11 +3423,11 @@ export class Parser extends DiagnosticEmitter { var startPos = tn.tokenPos; var stmt: Statement | null; if (tn.skip(Token.OPENBRACE)) { - let statements = new Array(); + let bodyStatements = new Array(); while (!tn.skip(Token.CLOSEBRACE)) { stmt = this.parseStatement(tn); if (!stmt) return null; - statements.push(stmt); + bodyStatements.push(stmt); } let catchVariable: IdentifierExpression | null = null; let catchStatements: Statement[] | null = null; @@ -3492,7 +3492,7 @@ export class Parser extends DiagnosticEmitter { return null; } let ret = Node.createTryStatement( - statements, + bodyStatements, catchVariable, catchStatements, finallyStatements, From b6341eea87043688f7973a13e668c3170b79b93d Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 00:39:44 +0300 Subject: [PATCH 06/22] use TitleCase for most of enums (WIP) --- src/ast.ts | 414 +++++----- src/bindings/js.ts | 54 +- src/bindings/tsd.ts | 14 +- src/bindings/util.ts | 44 +- src/builtins.ts | 922 ++++++++++----------- src/common.ts | 66 +- src/compiler.ts | 1426 ++++++++++++++++---------------- src/diagnostics.ts | 40 +- src/extra/ast.ts | 218 ++--- src/flow.ts | 422 +++++----- src/index-wasm.ts | 34 +- src/module.ts | 8 +- src/parser.ts | 266 +++--- src/passes/shadowstack.ts | 2 +- src/program.ts | 682 +++++++-------- src/resolver.ts | 570 ++++++------- src/types.ts | 334 ++++---- std/assembly/shared/feature.ts | 52 +- std/assembly/shared/target.ts | 6 +- 19 files changed, 2790 insertions(+), 2784 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 45c01999ae..cd47676852 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -46,83 +46,83 @@ import { /** Indicates the kind of a node. */ export const enum NodeKind { - SOURCE, + Source, // types - NAMEDTYPE, - FUNCTIONTYPE, - TYPENAME, - TYPEPARAMETER, - PARAMETER, + NamedType, + FunctionType, + TypeName, + TypeParameter, + Parameter, // expressions - IDENTIFIER, - ASSERTION, - BINARY, - CALL, - CLASS, - COMMA, - ELEMENTACCESS, - FALSE, - FUNCTION, - INSTANCEOF, - LITERAL, - NEW, - NULL, - OMITTED, - PARENTHESIZED, - PROPERTYACCESS, - TERNARY, - SUPER, - THIS, - TRUE, - CONSTRUCTOR, - UNARYPOSTFIX, - UNARYPREFIX, - COMPILED, + Identifier, + Assertion, + Binary, + Call, + Class, + Comma, + ElementAccess, + False, + Function, + InstanceOf, + Literal, + New, + Null, + Omitted, + Parenthesized, + PropertyAccess, + Ternary, + Super, + This, + True, + Constructor, + UnaryPostfix, + UnaryPrefix, + Compiled, // statements - BLOCK, - BREAK, - CONTINUE, - DO, - EMPTY, - EXPORT, - EXPORTDEFAULT, - EXPORTIMPORT, - EXPRESSION, - FOR, - FOROF, - IF, - IMPORT, - RETURN, - SWITCH, - THROW, - TRY, - VARIABLE, - VOID, - WHILE, - MODULE, + Block, + Break, + Continue, + Do, + Empty, + Export, + ExportDefault, + ExportImport, + Expression, + For, + ForOf, + If, + Import, + Return, + Switch, + Throw, + Try, + Variable, + Void, + While, + Module, // declaration statements - CLASSDECLARATION, - ENUMDECLARATION, - ENUMVALUEDECLARATION, - FIELDDECLARATION, - FUNCTIONDECLARATION, - IMPORTDECLARATION, - INTERFACEDECLARATION, - METHODDECLARATION, - NAMESPACEDECLARATION, - TYPEDECLARATION, - VARIABLEDECLARATION, + ClassDeclaration, + EnumDeclaration, + EnumValueDeclaration, + FieldDeclaration, + FunctionDeclaration, + ImportDeclaration, + InterfaceDeclaration, + MethodDeclaration, + NamespaceDeclaration, + TypeDeclaration, + VariableDeclaration, // special - DECORATOR, - EXPORTMEMBER, - SWITCHCASE, - INDEXSIGNATURE, - COMMENT + Decorator, + ExportMember, + SwitchCase, + IndexSignature, + Comment } /** Base class of all nodes. */ @@ -760,16 +760,16 @@ export abstract class Node { /** Tests if this node is a literal of the specified kind. */ isLiteralKind(literalKind: LiteralKind): bool { - return this.kind == NodeKind.LITERAL + return this.kind == NodeKind.Literal && (changetype(this)).literalKind == literalKind; // TS } /** Tests if this node is a literal of a numeric kind (float or integer). */ get isNumericLiteral(): bool { - if (this.kind == NodeKind.LITERAL) { + if (this.kind == NodeKind.Literal) { switch ((changetype(this)).literalKind) { // TS - case LiteralKind.FLOAT: - case LiteralKind.INTEGER: return true; + case LiteralKind.Float: + case LiteralKind.Integer: return true; } } return false; @@ -778,27 +778,27 @@ export abstract class Node { /** Tests whether this node is guaranteed to compile to a constant value. */ get compilesToConst(): bool { switch (this.kind) { - case NodeKind.LITERAL: { + case NodeKind.Literal: { switch ((changetype(this)).literalKind) { // TS - case LiteralKind.FLOAT: - case LiteralKind.INTEGER: - case LiteralKind.STRING: return true; + case LiteralKind.Float: + case LiteralKind.Integer: + case LiteralKind.String: return true; } break; } - case NodeKind.NULL: - case NodeKind.TRUE: - case NodeKind.FALSE: return true; + case NodeKind.Null: + case NodeKind.True: + case NodeKind.False: return true; } return false; } private isAccessOn(kind: NodeKind): bool { let node = changetype(this); - if (node.kind == NodeKind.CALL) { + if (node.kind == NodeKind.Call) { node = (node).expression; } - if (node.kind == NodeKind.PROPERTYACCESS) { + if (node.kind == NodeKind.PropertyAccess) { let target = (node).expression; if (target.kind == kind) return true; } @@ -807,16 +807,16 @@ export abstract class Node { /** Checks if this node accesses a method or property on `this`. */ get isAccessOnThis(): bool { - return this.isAccessOn(NodeKind.THIS); + return this.isAccessOn(NodeKind.This); } /** Checks if this node accesses a method or property on `super`. */ get isAccessOnSuper(): bool { - return this.isAccessOn(NodeKind.SUPER); + return this.isAccessOn(NodeKind.Super); } get isEmpty(): bool { - return this.kind == NodeKind.EMPTY; + return this.kind == NodeKind.Empty; } } @@ -836,7 +836,7 @@ export abstract class TypeNode extends Node { /** Tests if this type has a generic component matching one of the given type parameters. */ hasGenericComponent(typeParameterNodes: TypeParameterNode[]): bool { - if (this.kind == NodeKind.NAMEDTYPE) { + if (this.kind == NodeKind.NamedType) { let namedTypeNode = changetype(this); // TS if (!namedTypeNode.name.next) { let typeArgumentNodes = namedTypeNode.typeArguments; @@ -851,7 +851,7 @@ export abstract class TypeNode extends Node { } } } - } else if (this.kind == NodeKind.FUNCTIONTYPE) { + } else if (this.kind == NodeKind.FunctionType) { let functionTypeNode = changetype(this); // TS let parameterNodes = functionTypeNode.parameters; for (let i = 0, k = parameterNodes.length; i < k; ++i) { @@ -877,7 +877,7 @@ export class TypeName extends Node { /** Source range. */ range: Range ) { - super(NodeKind.TYPENAME, range); + super(NodeKind.TypeName, range); } } @@ -893,7 +893,7 @@ export class NamedTypeNode extends TypeNode { /** Source range. */ range: Range ) { - super(NodeKind.NAMEDTYPE, isNullable, range); + super(NodeKind.NamedType, isNullable, range); } /** Checks if this type node has type arguments. */ @@ -917,7 +917,7 @@ export class FunctionTypeNode extends TypeNode { /** Source range. */ range: Range ) { - super(NodeKind.FUNCTIONTYPE, isNullable, range); + super(NodeKind.FunctionType, isNullable, range); } } @@ -933,7 +933,7 @@ export class TypeParameterNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.TYPEPARAMETER, range); + super(NodeKind.TypeParameter, range); } } @@ -961,13 +961,13 @@ export class ParameterNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.PARAMETER, range); + super(NodeKind.Parameter, range); } /** Implicit field declaration, if applicable. */ implicitFieldDeclaration: FieldDeclaration | null = null; /** Common flags indicating specific traits. */ - flags: CommonFlags = CommonFlags.NONE; + flags: CommonFlags = CommonFlags.None; /** Tests if this node has the specified flag or flags. */ is(flag: CommonFlags): bool { return (this.flags & flag) == flag; } @@ -981,68 +981,68 @@ export class ParameterNode extends Node { /** Built-in decorator kinds. */ export enum DecoratorKind { - CUSTOM, - GLOBAL, - OPERATOR, - OPERATOR_BINARY, - OPERATOR_PREFIX, - OPERATOR_POSTFIX, - UNMANAGED, - FINAL, - INLINE, - EXTERNAL, - EXTERNAL_JS, - BUILTIN, - LAZY, - UNSAFE + Custom, + Global, + Operator, + OperatorBinary, + OperatorPrefix, + OperatorPostfix, + Unmanaged, + Final, + Inline, + External, + ExternalJs, + Builtin, + Lazy, + Unsafe } export namespace DecoratorKind { /** Returns the kind of the specified decorator name node. Defaults to {@link DecoratorKind.CUSTOM}. */ export function fromNode(nameNode: Expression): DecoratorKind { - if (nameNode.kind == NodeKind.IDENTIFIER) { + if (nameNode.kind == NodeKind.Identifier) { let nameStr = (nameNode).text; assert(nameStr.length); switch (nameStr.charCodeAt(0)) { case CharCode.b: { - if (nameStr == "builtin") return DecoratorKind.BUILTIN; + if (nameStr == "builtin") return DecoratorKind.Builtin; break; } case CharCode.e: { - if (nameStr == "external") return DecoratorKind.EXTERNAL; + if (nameStr == "external") return DecoratorKind.External; break; } case CharCode.f: { - if (nameStr == "final") return DecoratorKind.FINAL; + if (nameStr == "final") return DecoratorKind.Final; break; } case CharCode.g: { - if (nameStr == "global") return DecoratorKind.GLOBAL; + if (nameStr == "global") return DecoratorKind.Global; break; } case CharCode.i: { - if (nameStr == "inline") return DecoratorKind.INLINE; + if (nameStr == "inline") return DecoratorKind.Inline; break; } case CharCode.l: { - if (nameStr == "lazy") return DecoratorKind.LAZY; + if (nameStr == "lazy") return DecoratorKind.Lazy; break; } case CharCode.o: { - if (nameStr == "operator") return DecoratorKind.OPERATOR; + if (nameStr == "operator") return DecoratorKind.Operator; break; } case CharCode.u: { - if (nameStr == "unmanaged") return DecoratorKind.UNMANAGED; - if (nameStr == "unsafe") return DecoratorKind.UNSAFE; + if (nameStr == "unmanaged") return DecoratorKind.Unmanaged; + if (nameStr == "unsafe") return DecoratorKind.Unsafe; break; } } - } else if (nameNode.kind == NodeKind.PROPERTYACCESS) { + } else if (nameNode.kind == NodeKind.PropertyAccess) { let propertyAccessNode = nameNode; let expression = propertyAccessNode.expression; - if (expression.kind == NodeKind.IDENTIFIER) { + if (expression.kind == NodeKind.Identifier) { let nameStr = (expression).text; assert(nameStr.length); let propStr = propertyAccessNode.property.text; @@ -1050,26 +1050,26 @@ export namespace DecoratorKind { if (nameStr == "operator") { switch (propStr.charCodeAt(0)) { case CharCode.b: { - if (propStr == "binary") return DecoratorKind.OPERATOR_BINARY; + if (propStr == "binary") return DecoratorKind.OperatorBinary; break; } case CharCode.p: { - if (propStr == "prefix") return DecoratorKind.OPERATOR_PREFIX; - if (propStr == "postfix") return DecoratorKind.OPERATOR_POSTFIX; + if (propStr == "prefix") return DecoratorKind.OperatorPrefix; + if (propStr == "postfix") return DecoratorKind.OperatorPostfix; break; } } } else if (nameStr == "external") { switch (propStr.charCodeAt(0)) { case CharCode.j: { - if (propStr == "js") return DecoratorKind.EXTERNAL_JS; + if (propStr == "js") return DecoratorKind.ExternalJs; break; } } } } } - return DecoratorKind.CUSTOM; + return DecoratorKind.Custom; } } @@ -1085,7 +1085,7 @@ export class DecoratorNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.DECORATOR, range); + super(NodeKind.Decorator, range); } } @@ -1109,7 +1109,7 @@ export class CommentNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.COMMENT, range); + super(NodeKind.Comment, range); } } @@ -1128,19 +1128,19 @@ export class IdentifierExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.IDENTIFIER, range); + super(NodeKind.Identifier, range); } } /** Indicates the kind of a literal. */ export const enum LiteralKind { - FLOAT, - INTEGER, - STRING, - TEMPLATE, - REGEXP, - ARRAY, - OBJECT + Float, + Integer, + String, + Template, + RegExp, + Array, + Object } /** Base class of all literal expressions. */ @@ -1151,7 +1151,7 @@ export abstract class LiteralExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.LITERAL, range); + super(NodeKind.Literal, range); } } @@ -1163,20 +1163,20 @@ export class ArrayLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.ARRAY, range); + super(LiteralKind.Array, range); } } /** Indicates the kind of an assertion. */ export const enum AssertionKind { /** A prefix assertion, i.e. `expr`. */ - PREFIX, + Prefix, /** An as assertion, i.e. `expr as T`. */ - AS, + As, /** A non-null assertion, i.e. `!expr`. */ - NONNULL, + NonNull, /** A const assertion, i.e. `expr as const`. */ - CONST + Const } /** Represents an assertion expression. */ @@ -1191,7 +1191,7 @@ export class AssertionExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.ASSERTION, range); + super(NodeKind.Assertion, range); } } @@ -1207,7 +1207,7 @@ export class BinaryExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.BINARY, range); + super(NodeKind.Binary, range); } } @@ -1223,7 +1223,7 @@ export class CallExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.CALL, range); + super(NodeKind.Call, range); } /** Gets the type arguments range for reporting. */ @@ -1255,7 +1255,7 @@ export class ClassExpression extends Expression { /** Inline class declaration. */ public declaration: ClassDeclaration ) { - super(NodeKind.CLASS, declaration.range); + super(NodeKind.Class, declaration.range); } } @@ -1267,7 +1267,7 @@ export class CommaExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.COMMA, range); + super(NodeKind.Comma, range); } } @@ -1278,7 +1278,7 @@ export class ConstructorExpression extends IdentifierExpression { range: Range ) { super("constructor", false, range); - this.kind = NodeKind.CONSTRUCTOR; + this.kind = NodeKind.Constructor; } } @@ -1292,7 +1292,7 @@ export class ElementAccessExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.ELEMENTACCESS, range); + super(NodeKind.ElementAccess, range); } } @@ -1304,7 +1304,7 @@ export class FloatLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.FLOAT, range); + super(LiteralKind.Float, range); } } @@ -1314,7 +1314,7 @@ export class FunctionExpression extends Expression { /** Inline function declaration. */ public declaration: FunctionDeclaration ) { - super(NodeKind.FUNCTION, declaration.range); + super(NodeKind.Function, declaration.range); } } @@ -1328,7 +1328,7 @@ export class InstanceOfExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.INSTANCEOF, range); + super(NodeKind.InstanceOf, range); } } @@ -1340,7 +1340,7 @@ export class IntegerLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.INTEGER, range); + super(LiteralKind.Integer, range); } } @@ -1356,7 +1356,7 @@ export class NewExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.NEW, range); + super(NodeKind.New, range); } /** Gets the type arguments range for reporting. */ @@ -1387,7 +1387,7 @@ export class NullExpression extends IdentifierExpression { range: Range ) { super("null", false, range); - this.kind = NodeKind.NULL; + this.kind = NodeKind.Null; } } @@ -1401,7 +1401,7 @@ export class ObjectLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.OBJECT, range); + super(LiteralKind.Object, range); } } @@ -1411,7 +1411,7 @@ export class OmittedExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.OMITTED, range); + super(NodeKind.Omitted, range); } } @@ -1423,7 +1423,7 @@ export class ParenthesizedExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.PARENTHESIZED, range); + super(NodeKind.Parenthesized, range); } } @@ -1437,7 +1437,7 @@ export class PropertyAccessExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.PROPERTYACCESS, range); + super(NodeKind.PropertyAccess, range); } } @@ -1451,7 +1451,7 @@ export class RegexpLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.REGEXP, range); + super(LiteralKind.RegExp, range); } } @@ -1467,7 +1467,7 @@ export class TernaryExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.TERNARY, range); + super(NodeKind.Ternary, range); } } @@ -1479,7 +1479,7 @@ export class StringLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.STRING, range); + super(LiteralKind.String, range); } } @@ -1490,7 +1490,7 @@ export class SuperExpression extends IdentifierExpression { range: Range ) { super("super", false, range); - this.kind = NodeKind.SUPER; + this.kind = NodeKind.Super; } } @@ -1508,7 +1508,7 @@ export class TemplateLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.TEMPLATE, range); + super(LiteralKind.Template, range); } } @@ -1519,7 +1519,7 @@ export class ThisExpression extends IdentifierExpression { range: Range ) { super("this", false, range); - this.kind = NodeKind.THIS; + this.kind = NodeKind.This; } } @@ -1530,7 +1530,7 @@ export class TrueExpression extends IdentifierExpression { range: Range ) { super("true", false, range); - this.kind = NodeKind.TRUE; + this.kind = NodeKind.True; } } @@ -1541,7 +1541,7 @@ export class FalseExpression extends IdentifierExpression { range: Range ) { super("false", false, range); - this.kind = NodeKind.FALSE; + this.kind = NodeKind.False; } } @@ -1571,7 +1571,7 @@ export class UnaryPostfixExpression extends UnaryExpression { /** Source range. */ range: Range ) { - super(NodeKind.UNARYPOSTFIX, operator, operand, range); + super(NodeKind.UnaryPostfix, operator, operand, range); } } @@ -1585,7 +1585,7 @@ export class UnaryPrefixExpression extends UnaryExpression { /** Source range. */ range: Range ) { - super(NodeKind.UNARYPREFIX, operator, operand, range); + super(NodeKind.UnaryPrefix, operator, operand, range); } } @@ -1599,7 +1599,7 @@ export class CompiledExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.COMPILED, range); + super(NodeKind.Compiled, range); } } @@ -1630,7 +1630,7 @@ export class Source extends Node { /** Full source text. */ public text: string ) { - super(NodeKind.SOURCE, new Range(0, text.length)); + super(NodeKind.Source, new Range(0, text.length)); var internalPath = mangleInternalPath(normalizedPath); this.internalPath = internalPath; var pos = internalPath.lastIndexOf(PATH_DELIMITER); @@ -1740,7 +1740,7 @@ export class IndexSignatureNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.INDEXSIGNATURE, range); + super(NodeKind.IndexSignature, range); } } @@ -1774,7 +1774,7 @@ export class BlockStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.BLOCK, range); + super(NodeKind.Block, range); } } @@ -1786,7 +1786,7 @@ export class BreakStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.BREAK, range); + super(NodeKind.Break, range); } } @@ -1810,7 +1810,7 @@ export class ClassDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.CLASSDECLARATION, name, decorators, flags, range); + super(NodeKind.ClassDeclaration, name, decorators, flags, range); } /** Index signature, if present. */ @@ -1830,7 +1830,7 @@ export class ContinueStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.CONTINUE, range); + super(NodeKind.Continue, range); } } @@ -1844,7 +1844,7 @@ export class DoStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.DO, range); + super(NodeKind.Do, range); } } @@ -1854,7 +1854,7 @@ export class EmptyStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EMPTY, range); + super(NodeKind.Empty, range); } } @@ -1872,7 +1872,7 @@ export class EnumDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.ENUMDECLARATION, name, decorators, flags, range); + super(NodeKind.EnumDeclaration, name, decorators, flags, range); } } @@ -1888,7 +1888,7 @@ export class EnumValueDeclaration extends VariableLikeDeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.ENUMVALUEDECLARATION, name, null, flags, null, initializer, range); + super(NodeKind.EnumValueDeclaration, name, null, flags, null, initializer, range); } } @@ -1902,7 +1902,7 @@ export class ExportImportStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTIMPORT, range); + super(NodeKind.ExportImport, range); } } @@ -1916,7 +1916,7 @@ export class ExportMember extends Node { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTMEMBER, range); + super(NodeKind.ExportMember, range); } } @@ -1932,7 +1932,7 @@ export class ExportStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EXPORT, range); + super(NodeKind.Export, range); if (path) { let normalizedPath = normalizePath(path.value); if (path.value.startsWith(".")) { // relative @@ -1958,7 +1958,7 @@ export class ExportDefaultStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTDEFAULT, range); + super(NodeKind.ExportDefault, range); } } @@ -1968,7 +1968,7 @@ export class ExpressionStatement extends Statement { /** Expression being used as a statement.*/ public expression: Expression ) { - super(NodeKind.EXPRESSION, expression.range); + super(NodeKind.Expression, expression.range); } } @@ -1990,7 +1990,7 @@ export class FieldDeclaration extends VariableLikeDeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.FIELDDECLARATION, name, decorators, flags, type, initializer, range); + super(NodeKind.FieldDeclaration, name, decorators, flags, type, initializer, range); } } @@ -2008,7 +2008,7 @@ export class ForStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.FOR, range); + super(NodeKind.For, range); } } @@ -2024,18 +2024,18 @@ export class ForOfStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.FOROF, range); + super(NodeKind.ForOf, range); } } /** Indicates the kind of an array function. */ export const enum ArrowKind { /** Not an arrow function. */ - NONE, + None, /** Parenthesized parameter list. */ - ARROW_PARENTHESIZED, + Parenthesized, /** Single parameter without parenthesis. */ - ARROW_SINGLE + Single } /** Represents a `function` declaration. */ @@ -2058,7 +2058,7 @@ export class FunctionDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.FUNCTIONDECLARATION, name, decorators, flags, range); + super(NodeKind.FunctionDeclaration, name, decorators, flags, range); } /** Gets if this function is generic. */ @@ -2094,7 +2094,7 @@ export class IfStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.IF, range); + super(NodeKind.If, range); } } @@ -2108,7 +2108,7 @@ export class ImportDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.IMPORTDECLARATION, name, null, CommonFlags.NONE, range); + super(NodeKind.ImportDeclaration, name, null, CommonFlags.None, range); } } @@ -2124,7 +2124,7 @@ export class ImportStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.IMPORT, range); + super(NodeKind.Import, range); var normalizedPath = normalizePath(path.value); if (path.value.startsWith(".")) { // relative in project normalizedPath = resolvePath(normalizedPath, range.source.internalPath); @@ -2159,7 +2159,7 @@ export class InterfaceDeclaration extends ClassDeclaration { range: Range ) { super(name, decorators, flags, typeParameters, extendsType, implementsTypes, members, range); - this.kind = NodeKind.INTERFACEDECLARATION; + this.kind = NodeKind.InterfaceDeclaration; } } @@ -2181,8 +2181,8 @@ export class MethodDeclaration extends FunctionDeclaration { /** Source range. */ range: Range ) { - super(name, decorators, flags, typeParameters, signature, body, ArrowKind.NONE, range); - this.kind = NodeKind.METHODDECLARATION; + super(name, decorators, flags, typeParameters, signature, body, ArrowKind.None, range); + this.kind = NodeKind.MethodDeclaration; } } @@ -2200,7 +2200,7 @@ export class NamespaceDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.NAMESPACEDECLARATION, name, decorators, flags, range); + super(NodeKind.NamespaceDeclaration, name, decorators, flags, range); } } @@ -2212,7 +2212,7 @@ export class ReturnStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.RETURN, range); + super(NodeKind.Return, range); } } @@ -2226,7 +2226,7 @@ export class SwitchCase extends Node { /** Source range. */ range: Range ) { - super(NodeKind.SWITCHCASE, range); + super(NodeKind.SwitchCase, range); } get isDefault(): bool { @@ -2244,7 +2244,7 @@ export class SwitchStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.SWITCH, range); + super(NodeKind.Switch, range); } } @@ -2256,7 +2256,7 @@ export class ThrowStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.THROW, range); + super(NodeKind.Throw, range); } } @@ -2274,7 +2274,7 @@ export class TryStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.TRY, range); + super(NodeKind.Try, range); } } @@ -2288,7 +2288,7 @@ export class ModuleDeclaration extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.MODULE, range); + super(NodeKind.Module, range); } } @@ -2308,7 +2308,7 @@ export class TypeDeclaration extends DeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.TYPEDECLARATION, name, decorators, flags, range); + super(NodeKind.TypeDeclaration, name, decorators, flags, range); } } @@ -2328,7 +2328,7 @@ export class VariableDeclaration extends VariableLikeDeclarationStatement { /** Source range. */ range: Range ) { - super(NodeKind.VARIABLEDECLARATION, name, decorators, flags, type, initializer, range); + super(NodeKind.VariableDeclaration, name, decorators, flags, type, initializer, range); } } @@ -2342,7 +2342,7 @@ export class VariableStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.VARIABLE, range); + super(NodeKind.Variable, range); } } @@ -2354,7 +2354,7 @@ export class VoidStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.VOID, range); + super(NodeKind.Void, range); } } @@ -2368,7 +2368,7 @@ export class WhileStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.WHILE, range); + super(NodeKind.While, range); } } @@ -2395,7 +2395,7 @@ export function mangleInternalPath(path: string): string { /** Tests if the specified type node represents an omitted type. */ export function isTypeOmitted(type: TypeNode): bool { - if (type.kind == NodeKind.NAMEDTYPE) { + if (type.kind == NodeKind.NamedType) { let name = (type).name; return !(name.next || name.identifier.text.length > 0); } diff --git a/src/bindings/js.ts b/src/bindings/js.ts index 510b36e37b..8ae6b5be30 100644 --- a/src/bindings/js.ts +++ b/src/bindings/js.ts @@ -136,7 +136,7 @@ export class JSBuilder extends ExportsWalker { var sb = this.sb; var type = element.type; this.exports.push(name); - if (!isPlainValue(type, Mode.EXPORT)) { + if (!isPlainValue(type, Mode.Export)) { indent(sb, this.indentLevel); sb.push(name); sb.push(": {\n"); @@ -156,7 +156,7 @@ export class JSBuilder extends ExportsWalker { sb.push(";\n"); indent(sb, --this.indentLevel); sb.push("}"); - if (!element.is(CommonFlags.CONST)) { + if (!element.is(CommonFlags.Const)) { sb.push(",\n"); indent(sb, this.indentLevel); sb.push("set value(value) {\n"); @@ -190,11 +190,11 @@ export class JSBuilder extends ExportsWalker { if (members) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let value = _values[i]; - if (value.kind != ElementKind.ENUMVALUE) continue; + if (value.kind != ElementKind.EnumValue) continue; indent(sb, this.indentLevel); sb.push("values[values."); sb.push(value.name); - if (value.is(CommonFlags.INLINED)) { + if (value.is(CommonFlags.Inlined)) { sb.push(" = "); sb.push(i64_low((value).constantIntegerValue).toString()); } else { @@ -226,7 +226,7 @@ export class JSBuilder extends ExportsWalker { sb.push("\": "); } let moduleId = this.ensureModuleId(moduleName); - if (isPlainValue(type, Mode.IMPORT)) { + if (isPlainValue(type, Mode.Import)) { sb.push("(\n"); indent(sb, this.indentLevel + 1); sb.push("// "); @@ -271,7 +271,7 @@ export class JSBuilder extends ExportsWalker { sb.push(escapeString(name, CharCode.DOUBLEQUOTE)); sb.push("\""); } - if (isPlainFunction(signature, Mode.IMPORT) && !code) { + if (isPlainFunction(signature, Mode.Import) && !code) { sb.push(": (\n"); indent(sb, this.indentLevel + 1); sb.push("// "); @@ -303,7 +303,7 @@ export class JSBuilder extends ExportsWalker { sb.push("\n"); for (let i = 0, k = parameterTypes.length; i < k; ++i) { let type = parameterTypes[i]; - if (!isPlainValue(type, Mode.EXPORT)) { + if (!isPlainValue(type, Mode.Export)) { let name = element.getParameterName(i); indent(sb, this.indentLevel); sb.push(name); @@ -351,11 +351,11 @@ export class JSBuilder extends ExportsWalker { } visitFunction(name: string, element: Function): void { - if (element.is(CommonFlags.PRIVATE)) return; + if (element.is(CommonFlags.Private)) return; var sb = this.sb; var signature = element.signature; this.exports.push(name); - if (!isPlainFunction(signature, Mode.EXPORT)) { + if (!isPlainFunction(signature, Mode.Export)) { indent(sb, this.indentLevel); sb.push(name); sb.push("("); @@ -375,7 +375,7 @@ export class JSBuilder extends ExportsWalker { let releases = new Array(); for (let i = 0, k = parameterTypes.length; i < k; ++i) { let type = parameterTypes[i]; - if (!isPlainValue(type, Mode.IMPORT)) { + if (!isPlainValue(type, Mode.Import)) { let name = element.getParameterName(i); indent(sb, this.indentLevel); sb.push(name); @@ -465,17 +465,17 @@ export class JSBuilder extends ExportsWalker { } getExternalCode(element: Function): string | null { - let decorator = findDecorator(DecoratorKind.EXTERNAL_JS, element.decoratorNodes); + let decorator = findDecorator(DecoratorKind.ExternalJs, element.decoratorNodes); if (decorator) { let args = decorator.args; if (args && args.length == 1) { let codeArg = args[0]; - if (codeArg.kind == NodeKind.LITERAL) { + if (codeArg.kind == NodeKind.Literal) { let literal = codeArg; - if (literal.literalKind == LiteralKind.STRING) { + if (literal.literalKind == LiteralKind.String) { return (literal).value; } - if (literal.literalKind == LiteralKind.TEMPLATE) { + if (literal.literalKind == LiteralKind.Template) { let parts = (literal).parts; if (parts.length == 1) { return parts[0]; @@ -535,16 +535,16 @@ export class JSBuilder extends ExportsWalker { for (let _keys2 = Map_keys(module), j = 0, l = _keys2.length; j < l; ++j) { let name = _keys2[j]; let elem = assert(module.get(name)); - if (elem.kind == ElementKind.FUNCTION) { + if (elem.kind == ElementKind.Function) { let func = elem; let code = this.getExternalCode(func); - if (!isPlainFunction(func.signature, Mode.IMPORT) || !isIdentifier(name) || code) { + if (!isPlainFunction(func.signature, Mode.Import) || !isIdentifier(name) || code) { this.makeFunctionImport(moduleName, name, elem, code); ++numInstrumented; } - } else if (elem.kind == ElementKind.GLOBAL) { + } else if (elem.kind == ElementKind.Global) { let global = elem; - if (!isPlainValue(global.type, Mode.IMPORT) || !isIdentifier(name)) { + if (!isPlainValue(global.type, Mode.Import) || !isIdentifier(name)) { this.makeGlobalImport(moduleName, name, global); ++numInstrumented; } @@ -1107,7 +1107,7 @@ export class JSBuilder extends ExportsWalker { } } sb.push(")"); - if (!type.is(TypeFlags.NULLABLE)) { + if (!type.is(TypeFlags.Nullable)) { this.needsNotNull = true; sb.push(" || __notnull()"); } @@ -1241,7 +1241,7 @@ export class JSBuilder extends ExportsWalker { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberName = _keys[i]; let member = assert(members.get(memberName)); - if (member.kind != ElementKind.FIELD) continue; + if (member.kind != ElementKind.Field) continue; let field = member; indent(sb, this.indentLevel); sb.push(field.name); @@ -1283,7 +1283,7 @@ export class JSBuilder extends ExportsWalker { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberName = _keys[i]; let member = assert(members.get(memberName)); - if (member.kind != ElementKind.FIELD) continue; + if (member.kind != ElementKind.Field) continue; let field = member; indent(sb, this.indentLevel); this.makeLowerToMemory(field.type, sb, "pointer + " + field.memoryOffset.toString(), "value." + memberName); @@ -1303,12 +1303,12 @@ export class JSBuilder extends ExportsWalker { // Helpers enum Mode { - IMPORT, - EXPORT + Import, + Export } function isPlainValue(type: Type, kind: Mode): bool { - if (kind == Mode.IMPORT) { + if (kind == Mode.Import) { // may be stored to an Uint8Array, make sure to store 1/0 if (type == Type.bool) return false; // requires coercion of undefined to 0n @@ -1325,7 +1325,7 @@ function isPlainValue(type: Type, kind: Mode): bool { function isPlainFunction(signature: Signature, mode: Mode): bool { var parameterTypes = signature.parameterTypes; - var inverseMode = mode == Mode.IMPORT ? Mode.EXPORT : Mode.IMPORT; + var inverseMode = mode == Mode.Import ? Mode.Export : Mode.Import; if (!isPlainValue(signature.returnType, mode)) return false; for (let i = 0, k = parameterTypes.length; i < k; ++i) { if (!isPlainValue(parameterTypes[i], inverseMode)) return false; @@ -1340,8 +1340,8 @@ function isPlainObject(clazz: Class): bool { if (members) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = _values[i]; - if (member.isAny(CommonFlags.PRIVATE | CommonFlags.PROTECTED)) return false; - if (member.is(CommonFlags.CONSTRUCTOR)) { + if (member.isAny(CommonFlags.Private | CommonFlags.Protected)) return false; + if (member.is(CommonFlags.Constructor)) { // a generated constructor is ok if (member.declaration.range != member.program.nativeRange) return false; } diff --git a/src/bindings/tsd.ts b/src/bindings/tsd.ts index fc5c8a2e6b..a8ce46c1ce 100644 --- a/src/bindings/tsd.ts +++ b/src/bindings/tsd.ts @@ -70,7 +70,7 @@ export class TSDBuilder extends ExportsWalker { indent(sb, this.indentLevel); sb.push("get value(): "); sb.push(tsType); - if (!element.is(CommonFlags.CONST)) { + if (!element.is(CommonFlags.Const)) { sb.push(";\n"); indent(sb, this.indentLevel); sb.push("set value(value: "); @@ -101,7 +101,7 @@ export class TSDBuilder extends ExportsWalker { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberName = unchecked(_keys[i]); let member = assert(members.get(memberName)); - if (member.kind != ElementKind.ENUMVALUE) continue; + if (member.kind != ElementKind.EnumValue) continue; indent(sb, this.indentLevel); sb.push("/** @type `i32` */\n"); indent(sb, this.indentLevel); @@ -235,8 +235,8 @@ export class TSDBuilder extends ExportsWalker { if (members) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = _values[i]; - if (member.isAny(CommonFlags.PRIVATE | CommonFlags.PROTECTED)) return false; - if (member.is(CommonFlags.CONSTRUCTOR)) { + if (member.isAny(CommonFlags.Private | CommonFlags.Protected)) return false; + if (member.is(CommonFlags.Constructor)) { // a generated constructor is ok if (member.declaration.range != this.program.nativeRange) return false; } @@ -314,7 +314,7 @@ export class TSDBuilder extends ExportsWalker { } } } - if (type.is(TypeFlags.NULLABLE)) { + if (type.is(TypeFlags.Nullable)) { sb.push(" | null"); } return sb.join(""); @@ -347,7 +347,7 @@ export class TSDBuilder extends ExportsWalker { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberName = _keys[i]; let member = assert(members.get(memberName)); - if (member.kind != ElementKind.FIELD) continue; + if (member.kind != ElementKind.Field) continue; let field = member; sb.push(" /** @type `"); sb.push(field.type.toString()); @@ -367,7 +367,7 @@ export class TSDBuilder extends ExportsWalker { fieldAcceptsUndefined(type: Type): bool { if (type.isInternalReference) { - return type.is(TypeFlags.NULLABLE); + return type.is(TypeFlags.Nullable); } return true; } diff --git a/src/bindings/util.ts b/src/bindings/util.ts index 9e5ea8fc33..d40bfb0c2b 100644 --- a/src/bindings/util.ts +++ b/src/bindings/util.ts @@ -70,43 +70,43 @@ export abstract class ExportsWalker { /** Visits an element.*/ visitElement(name: string, element: Element): void { - if (element.is(CommonFlags.PRIVATE) && !this.includePrivate) return; + if (element.is(CommonFlags.Private) && !this.includePrivate) return; var seen = this.seen; - if (!element.is(CommonFlags.INSTANCE) && seen.has(element)) { + if (!element.is(CommonFlags.Instance) && seen.has(element)) { this.visitAlias(name, element, assert(seen.get(element))); return; } seen.set(element, name); switch (element.kind) { - case ElementKind.GLOBAL: { - if (element.is(CommonFlags.COMPILED)) this.visitGlobal(name, element); + case ElementKind.Global: { + if (element.is(CommonFlags.Compiled)) this.visitGlobal(name, element); break; } - case ElementKind.ENUM: { - if (element.is(CommonFlags.COMPILED)) this.visitEnum(name, element); + case ElementKind.Enum: { + if (element.is(CommonFlags.Compiled)) this.visitEnum(name, element); break; } - case ElementKind.ENUMVALUE: break; // handled by visitEnum - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.EnumValue: break; // handled by visitEnum + case ElementKind.FunctionPrototype: { this.visitFunctionInstances(name, element); break; } - case ElementKind.CLASS_PROTOTYPE: { + case ElementKind.ClassPrototype: { this.visitClassInstances(name, element); break; } - case ElementKind.FIELD: { + case ElementKind.Field: { let fieldInstance = element; - if (fieldInstance.is(CommonFlags.COMPILED)) this.visitField(name, fieldInstance); + if (fieldInstance.is(CommonFlags.Compiled)) this.visitField(name, fieldInstance); break; } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let propertyInstance = (element).instance; if (!propertyInstance) break; element = propertyInstance; // fall-through } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let propertyInstance = element; let getterInstance = propertyInstance.getterInstance; if (getterInstance) this.visitFunction(name, getterInstance); @@ -114,11 +114,11 @@ export abstract class ExportsWalker { if (setterInstance) this.visitFunction(name, setterInstance); break; } - case ElementKind.NAMESPACE: { + case ElementKind.Namespace: { if (hasCompiledMember(element)) this.visitNamespace(name, element); break; } - case ElementKind.TYPEDEFINITION: break; + case ElementKind.TypeDefinition: break; default: assert(false); } } @@ -129,7 +129,7 @@ export abstract class ExportsWalker { // TODO: for (let instance of instances.values()) { for (let _values = Map_values(instances), i = 0, k = _values.length; i < k; ++i) { let instance = unchecked(_values[i]); - if (instance.is(CommonFlags.COMPILED)) this.visitFunction(name, instance); + if (instance.is(CommonFlags.Compiled)) this.visitFunction(name, instance); } } } @@ -140,7 +140,7 @@ export abstract class ExportsWalker { // TODO: for (let instance of instances.values()) { for (let _values = Map_values(instances), i = 0, k = _values.length; i < k; ++i) { let instance = unchecked(_values[i]); - if (instance.is(CommonFlags.COMPILED)) this.visitClass(name, instance); + if (instance.is(CommonFlags.Compiled)) this.visitClass(name, instance); } } } @@ -165,30 +165,30 @@ export function hasCompiledMember(element: Element): bool { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = unchecked(_values[i]); switch (member.kind) { - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let instances = (member).instances; if (instances) { // TODO: for (let instance of instances.values()) { for (let _values = Map_values(instances), j = 0, l = _values.length; j < l; ++j) { let instance = unchecked(_values[j]); - if (instance.is(CommonFlags.COMPILED)) return true; + if (instance.is(CommonFlags.Compiled)) return true; } } break; } - case ElementKind.CLASS_PROTOTYPE: { + case ElementKind.ClassPrototype: { let instances = (member).instances; if (instances) { // TODO: for (let instance of instances.values()) { for (let _values = Map_values(instances), j = 0, l = _values.length; j < l; ++j) { let instance = unchecked(_values[j]); - if (instance.is(CommonFlags.COMPILED)) return true; + if (instance.is(CommonFlags.Compiled)) return true; } } break; } default: { - if (member.is(CommonFlags.COMPILED) || hasCompiledMember(member)) return true; + if (member.is(CommonFlags.Compiled) || hasCompiledMember(member)) return true; break; } } diff --git a/src/builtins.ts b/src/builtins.ts index 0b91345de7..c6a68a50cb 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -925,7 +925,7 @@ function builtin_isDefined(ctx: BuiltinContext): ExpressionRef { ctx.operands[0], compiler.currentFlow, Type.auto, - ReportMode.SWALLOW + ReportMode.Swallow ); return module.i32(element ? 1 : 0); } @@ -970,7 +970,7 @@ function builtin_isVoid(ctx: BuiltinContext): ExpressionRef { var type = checkConstantType(ctx); compiler.currentType = Type.bool; if (!type) return module.unreachable(); - return reifyConstantType(ctx, module.i32(type.kind == TypeKind.VOID ? 1 : 0)); + return reifyConstantType(ctx, module.i32(type.kind == TypeKind.Void ? 1 : 0)); } builtins.set(BuiltinNames.isVoid, builtin_isVoid); @@ -1068,7 +1068,7 @@ function builtin_offsetof(ctx: BuiltinContext): ExpressionRef { } if (operands.length) { let firstOperand = operands[0]; - if (!firstOperand.isLiteralKind(LiteralKind.STRING)) { + if (!firstOperand.isLiteralKind(LiteralKind.String)) { compiler.error( DiagnosticCode.String_literal_expected, operands[0].range @@ -1079,7 +1079,7 @@ function builtin_offsetof(ctx: BuiltinContext): ExpressionRef { let classMembers = classReference.members; if (classMembers && classMembers.has(fieldName)) { let member = assert(classMembers.get(fieldName)); - if (member.kind == ElementKind.FIELD) { + if (member.kind == ElementKind.Field) { return contextualUsize(compiler, i64_new((member).memoryOffset), contextualType); } } @@ -1130,7 +1130,7 @@ function builtin_idof(ctx: BuiltinContext): ExpressionRef { return reifyConstantType(ctx, module.i32(signatureReference.id)); } let classReference = type.getClassOrWrapper(compiler.program); - if (classReference && !classReference.hasDecorator(DecoratorFlags.UNMANAGED)) { + if (classReference && !classReference.hasDecorator(DecoratorFlags.Unmanaged)) { return reifyConstantType(ctx, module.i32(classReference.id)); } compiler.error( @@ -1155,18 +1155,18 @@ function builtin_bswap(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( ctx.operands[0], typeArguments[0].toUnsigned(), - Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP + Constraints.ConvImplicit | Constraints.MustWrap ) : compiler.compileExpression( ctx.operands[0], Type.u32, - Constraints.MUST_WRAP + Constraints.MustWrap ); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.U8: return arg0; case TypeKind.I16: @@ -1174,7 +1174,7 @@ function builtin_bswap(ctx: BuiltinContext): ExpressionRef { // (x << 8 | x >> 8) let flow = compiler.currentFlow; let temp = flow.getTempLocal(type); - flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp.index, LocalFlags.Wrapped); let res = module.binary( BinaryOp.OrI32, @@ -1198,13 +1198,13 @@ function builtin_bswap(ctx: BuiltinContext): ExpressionRef { } case TypeKind.I32: case TypeKind.U32: - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { if (type.size == 32) { // rotl(x & 0xFF00FF00, 8) | rotr(x & 0x00FF00FF, 8) let flow = compiler.currentFlow; let temp = flow.getTempLocal(type); - flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp.index, LocalFlags.Wrapped); let res = module.binary( BinaryOp.OrI32, @@ -1246,9 +1246,9 @@ function builtin_bswap(ctx: BuiltinContext): ExpressionRef { let flow = compiler.currentFlow; let temp1 = flow.getTempLocal(type); - flow.setLocalFlag(temp1.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp1.index, LocalFlags.Wrapped); let temp2 = flow.getTempLocal(type); - flow.setLocalFlag(temp2.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp2.index, LocalFlags.Wrapped); // t = ((x >>> 8) & 0x00FF00FF00FF00FF) | ((x & 0x00FF00FF00FF00FF) << 8) let expr = module.local_tee( @@ -1334,20 +1334,20 @@ function builtin_clz(ctx: BuiltinContext): ExpressionRef { ) return module.unreachable(); var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(ctx.operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(ctx.operands[0], Type.i32, Constraints.MUST_WRAP); + ? compiler.compileExpression(ctx.operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(ctx.operands[0], Type.i32, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: // not wrapped + case TypeKind.Bool: // not wrapped case TypeKind.I8: case TypeKind.U8: case TypeKind.I16: case TypeKind.U16: case TypeKind.I32: case TypeKind.U32: return module.unary(UnaryOp.ClzI32, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.unary(UnaryOp.ClzSize, arg0); + case TypeKind.Isize: + case TypeKind.Usize: return module.unary(UnaryOp.ClzSize, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.ClzI64, arg0); } @@ -1371,20 +1371,20 @@ function builtin_ctz(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.i32, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.i32, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: // not wrapped + case TypeKind.Bool: // not wrapped case TypeKind.I8: case TypeKind.U8: case TypeKind.I16: case TypeKind.U16: case TypeKind.I32: case TypeKind.U32: return module.unary(UnaryOp.CtzI32, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.unary(UnaryOp.CtzSize, arg0); + case TypeKind.Isize: + case TypeKind.Usize: return module.unary(UnaryOp.CtzSize, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.CtzI64, arg0); } @@ -1408,12 +1408,12 @@ function builtin_popcnt(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.i32, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.i32, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { switch (compiler.currentType.kind) { - case TypeKind.BOOL: return arg0; + case TypeKind.Bool: return arg0; case TypeKind.I8: // not wrapped case TypeKind.U8: case TypeKind.I16: @@ -1422,8 +1422,8 @@ function builtin_popcnt(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.unary(UnaryOp.PopcntI32, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.PopcntI64, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.unary(UnaryOp.PopcntSize, arg0); + case TypeKind.Isize: + case TypeKind.Usize: return module.unary(UnaryOp.PopcntSize, arg0); } } compiler.error( @@ -1445,13 +1445,13 @@ function builtin_rotl(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.i32, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.i32, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { - let arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + let arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); switch (type.kind) { - case TypeKind.BOOL: return arg0; + case TypeKind.Bool: return arg0; case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -1459,9 +1459,9 @@ function builtin_rotl(ctx: BuiltinContext): ExpressionRef { // (value << (shift & mask)) | (value >>> ((0 - shift) & mask)) let flow = compiler.currentFlow; let temp1 = flow.getTempLocal(type, findUsedLocals(arg1)); - flow.setLocalFlag(temp1.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp1.index, LocalFlags.Wrapped); let temp2 = flow.getTempLocal(type); - flow.setLocalFlag(temp2.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp2.index, LocalFlags.Wrapped); let ret = module.binary(BinaryOp.OrI32, module.binary( @@ -1496,8 +1496,8 @@ function builtin_rotl(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.RotlI32, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.RotlI64, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.RotlSize, arg0, arg1); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.RotlSize, arg0, arg1); } } compiler.error( @@ -1519,13 +1519,13 @@ function builtin_rotr(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.i32, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.i32, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { - let arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + let arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); switch (type.kind) { - case TypeKind.BOOL: return arg0; + case TypeKind.Bool: return arg0; case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -1533,9 +1533,9 @@ function builtin_rotr(ctx: BuiltinContext): ExpressionRef { // (value >>> (shift & mask)) | (value << ((0 - shift) & mask)) let flow = compiler.currentFlow; let temp1 = flow.getTempLocal(type, findUsedLocals(arg1)); - flow.setLocalFlag(temp1.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp1.index, LocalFlags.Wrapped); let temp2 = flow.getTempLocal(type); - flow.setLocalFlag(temp2.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp2.index, LocalFlags.Wrapped); let ret = module.binary(BinaryOp.OrI32, module.binary( @@ -1570,8 +1570,8 @@ function builtin_rotr(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.RotrI32, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.RotrI64, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.RotrSize, arg0, arg1); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.RotrSize, arg0, arg1); } } compiler.error( @@ -1593,17 +1593,17 @@ function builtin_abs(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.auto, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.auto, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; + case TypeKind.Usize: return arg0; case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: { @@ -1631,7 +1631,7 @@ function builtin_abs(ctx: BuiltinContext): ExpressionRef { flow.freeTempLocal(temp1); return ret; } - case TypeKind.ISIZE: { + case TypeKind.Isize: { let options = compiler.options; let flow = compiler.currentFlow; @@ -1705,32 +1705,32 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef { var typeArguments = ctx.typeArguments; var left = operands[0]; var arg0 = typeArguments - ? compiler.compileExpression(left, typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.auto, Constraints.MUST_WRAP); + ? compiler.compileExpression(left, typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.auto, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { let arg1: ExpressionRef; if (!typeArguments && left.isNumericLiteral) { // prefer right type - arg1 = compiler.compileExpression(operands[1], type, Constraints.MUST_WRAP); + arg1 = compiler.compileExpression(operands[1], type, Constraints.MustWrap); if (compiler.currentType != type) { - arg0 = compiler.compileExpression(left, type = compiler.currentType, Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP); + arg0 = compiler.compileExpression(left, type = compiler.currentType, Constraints.ConvImplicit | Constraints.MustWrap); } } else { - arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP); + arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit | Constraints.MustWrap); } let op: BinaryOp = -1; switch (type.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: { op = BinaryOp.GtI32; break; } - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: { op = BinaryOp.GtU32; break; } case TypeKind.I64: { op = BinaryOp.GtI64; break; } case TypeKind.U64: { op = BinaryOp.GtU64; break; } - case TypeKind.ISIZE: { op = BinaryOp.GtISize; break; } - case TypeKind.USIZE: { op = BinaryOp.GtUSize; break; } + case TypeKind.Isize: { op = BinaryOp.GtISize; break; } + case TypeKind.Usize: { op = BinaryOp.GtUSize; break; } case TypeKind.F32: return module.binary(BinaryOp.MaxF32, arg0, arg1); case TypeKind.F64: return module.binary(BinaryOp.MaxF64, arg0, arg1); } @@ -1738,9 +1738,9 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef { let flow = compiler.currentFlow; let typeRef = type.toRef(); let temp1 = flow.getTempLocal(type, findUsedLocals(arg1)); - flow.setLocalFlag(temp1.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp1.index, LocalFlags.Wrapped); let temp2 = flow.getTempLocal(type); - flow.setLocalFlag(temp2.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp2.index, LocalFlags.Wrapped); let ret = module.select( module.local_tee(temp1.index, arg0, false), // numeric module.local_tee(temp2.index, arg1, false), // numeric @@ -1775,32 +1775,32 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef { var typeArguments = ctx.typeArguments; var left = operands[0]; var arg0 = typeArguments - ? compiler.compileExpression(left, typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.auto, Constraints.MUST_WRAP); + ? compiler.compileExpression(left, typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.auto, Constraints.MustWrap); var type = compiler.currentType; if (type.isValue) { let arg1: ExpressionRef; if (!typeArguments && left.isNumericLiteral) { // prefer right type - arg1 = compiler.compileExpression(operands[1], type, Constraints.MUST_WRAP); + arg1 = compiler.compileExpression(operands[1], type, Constraints.MustWrap); if (compiler.currentType != type) { - arg0 = compiler.compileExpression(left, type = compiler.currentType, Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP); + arg0 = compiler.compileExpression(left, type = compiler.currentType, Constraints.ConvImplicit | Constraints.MustWrap); } } else { - arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP); + arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit | Constraints.MustWrap); } let op: BinaryOp = -1; switch (type.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: { op = BinaryOp.LtI32; break; } - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: { op = BinaryOp.LtU32; break; } case TypeKind.I64: { op = BinaryOp.LtI64; break; } case TypeKind.U64: { op = BinaryOp.LtU64; break; } - case TypeKind.ISIZE: { op = BinaryOp.LtISize; break; } - case TypeKind.USIZE: { op = BinaryOp.LtUSize; break; } + case TypeKind.Isize: { op = BinaryOp.LtISize; break; } + case TypeKind.Usize: { op = BinaryOp.LtUSize; break; } case TypeKind.F32: return module.binary(BinaryOp.MinF32, arg0, arg1); case TypeKind.F64: return module.binary(BinaryOp.MinF64, arg0, arg1); } @@ -1808,9 +1808,9 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef { let flow = compiler.currentFlow; let typeRef = type.toRef(); let temp1 = flow.getTempLocal(type, findUsedLocals(arg1)); - flow.setLocalFlag(temp1.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp1.index, LocalFlags.Wrapped); let temp2 = flow.getTempLocal(type); - flow.setLocalFlag(temp2.index, LocalFlags.WRAPPED); + flow.setLocalFlag(temp2.index, LocalFlags.Wrapped); let ret = module.select( module.local_tee(temp1.index, arg0, false), // numeric module.local_tee(temp2.index, arg1, false), // numeric @@ -1844,22 +1844,22 @@ function builtin_ceil(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.auto, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.auto, Constraints.None); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; // considered rounded + case TypeKind.Usize: return arg0; // considered rounded case TypeKind.F32: return module.unary(UnaryOp.CeilF32, arg0); case TypeKind.F64: return module.unary(UnaryOp.CeilF64, arg0); } @@ -1883,22 +1883,22 @@ function builtin_floor(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.auto, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.auto, Constraints.None); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; // considered rounded + case TypeKind.Usize: return arg0; // considered rounded case TypeKind.F32: return module.unary(UnaryOp.FloorF32, arg0); case TypeKind.F64: return module.unary(UnaryOp.FloorF64, arg0); } @@ -1922,11 +1922,11 @@ function builtin_copysign(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.f64, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.f64, Constraints.None); var type = compiler.currentType; if (type.isValue) { - let arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + let arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); switch (type.kind) { // TODO: does an integer version make sense? case TypeKind.F32: return module.binary(BinaryOp.CopysignF32, arg0, arg1); @@ -1952,22 +1952,22 @@ function builtin_nearest(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.auto, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.auto, Constraints.None); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; + case TypeKind.Usize: return arg0; case TypeKind.F32: return module.unary(UnaryOp.NearestF32, arg0); case TypeKind.F64: return module.unary(UnaryOp.NearestF64, arg0); } @@ -1995,22 +1995,22 @@ function builtin_reinterpret(ctx: BuiltinContext): ExpressionRef { switch (type.kind) { case TypeKind.I32: case TypeKind.U32: { - let arg0 = compiler.compileExpression(operands[0], Type.f32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.f32, Constraints.ConvImplicit); compiler.currentType = type; return module.unary(UnaryOp.ReinterpretF32ToI32, arg0); } case TypeKind.I64: case TypeKind.U64: { - let arg0 = compiler.compileExpression(operands[0], Type.f64, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.f64, Constraints.ConvImplicit); compiler.currentType = type; return module.unary(UnaryOp.ReinterpretF64ToI64, arg0); } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { let isWasm64 = compiler.options.isWasm64; let arg0 = compiler.compileExpression(operands[0], isWasm64 ? Type.f64 : Type.f32, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); compiler.currentType = type; return module.unary( @@ -2021,12 +2021,12 @@ function builtin_reinterpret(ctx: BuiltinContext): ExpressionRef { ); } case TypeKind.F32: { - let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.f32; return module.unary(UnaryOp.ReinterpretI32ToF32, arg0); } case TypeKind.F64: { - let arg0 = compiler.compileExpression(operands[0], Type.i64, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.i64, Constraints.ConvImplicit); compiler.currentType = Type.f64; return module.unary(UnaryOp.ReinterpretI64ToF64, arg0); } @@ -2051,8 +2051,8 @@ function builtin_sqrt(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.f64, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.f64, Constraints.None); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { @@ -2080,22 +2080,22 @@ function builtin_trunc(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) - : compiler.compileExpression(operands[0], Type.auto, Constraints.NONE); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) + : compiler.compileExpression(operands[0], Type.auto, Constraints.None); var type = compiler.currentType; if (type.isValue) { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; // considered truncated + case TypeKind.Usize: return arg0; // considered truncated case TypeKind.F32: return module.unary(UnaryOp.TruncF32, arg0); case TypeKind.F64: return module.unary(UnaryOp.TruncF64, arg0); } @@ -2122,7 +2122,7 @@ function builtin_isNaN(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; compiler.currentType = Type.bool; @@ -2133,12 +2133,12 @@ function builtin_isNaN(ctx: BuiltinContext): ExpressionRef { case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: { + case TypeKind.Usize: { return module.maybeDropCondition(arg0, module.i32(0)); } // (t = arg0) != t @@ -2198,7 +2198,7 @@ function builtin_isFinite(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; compiler.currentType = Type.bool; @@ -2209,12 +2209,12 @@ function builtin_isFinite(ctx: BuiltinContext): ExpressionRef { case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: { + case TypeKind.Usize: { return module.maybeDropCondition(arg0, module.i32(1)); } // (t = arg0) - t == 0 @@ -2303,7 +2303,7 @@ function builtin_load(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var numOperands = operands.length; var immOffset = 0; var immAlign = type.byteSize; @@ -2347,18 +2347,18 @@ function builtin_store(ctx: BuiltinContext): ExpressionRef { var typeArguments = ctx.typeArguments; var contextualType = ctx.contextualType; var type = typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var arg1 = ctx.contextIsExact ? compiler.compileExpression(operands[1], contextualType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression( operands[1], type, type.isIntegerValue - ? Constraints.NONE // no need to convert to small int (but now might result in a float) - : Constraints.CONV_IMPLICIT + ? Constraints.None // no need to convert to small int (but now might result in a float) + : Constraints.ConvImplicit ); var inType = compiler.currentType; if (!inType.isMemory) { @@ -2415,7 +2415,7 @@ function builtin_rem(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2431,14 +2431,14 @@ function builtin_rem(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isIntegerValue) { @@ -2469,7 +2469,7 @@ function builtin_add(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2485,14 +2485,14 @@ function builtin_add(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2523,7 +2523,7 @@ function builtin_sub(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2539,14 +2539,14 @@ function builtin_sub(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2577,7 +2577,7 @@ function builtin_mul(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2593,14 +2593,14 @@ function builtin_mul(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2631,7 +2631,7 @@ function builtin_div(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2647,14 +2647,14 @@ function builtin_div(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2685,7 +2685,7 @@ function builtin_eq(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2701,14 +2701,14 @@ function builtin_eq(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2740,7 +2740,7 @@ function builtin_ne(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; @@ -2756,14 +2756,14 @@ function builtin_ne(ctx: BuiltinContext): ExpressionRef { arg0 = compiler.compileExpression( left, (type = compiler.currentType), - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } } else { arg1 = compiler.compileExpression( operands[1], type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } if (type.isNumericValue) { @@ -2788,7 +2788,7 @@ function builtin_atomic_load(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 2) ) return module.unreachable(); @@ -2809,7 +2809,7 @@ function builtin_atomic_load(ctx: BuiltinContext): ExpressionRef { compiler.currentType = outType; return module.unreachable(); } - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var immOffset = operands.length == 2 ? evaluateImmediateOffset(operands[1], compiler) : 0; // reports if (immOffset < 0) { compiler.currentType = outType; @@ -2830,7 +2830,7 @@ function builtin_atomic_store(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx) | checkArgsOptional(ctx, 2, 3) ) return module.unreachable(); @@ -2846,19 +2846,19 @@ function builtin_atomic_store(ctx: BuiltinContext): ExpressionRef { compiler.currentType = Type.void; return module.unreachable(); } - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var arg1 = ctx.contextIsExact ? compiler.compileExpression( operands[1], contextualType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression( operands[1], type, type.isIntegerValue - ? Constraints.NONE // no need to convert to small int (but now might result in a float) - : Constraints.CONV_IMPLICIT + ? Constraints.None // no need to convert to small int (but now might result in a float) + : Constraints.ConvImplicit ); var inType = compiler.currentType; if ( @@ -2887,7 +2887,7 @@ function builtin_atomic_binary(ctx: BuiltinContext, op: AtomicRMWOp, opName: str var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 2, 3) ) return module.unreachable(); @@ -2904,19 +2904,19 @@ function builtin_atomic_binary(ctx: BuiltinContext, op: AtomicRMWOp, opName: str } var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); var arg1 = ctx.contextIsExact ? compiler.compileExpression(operands[1], contextualType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression( operands[1], type, type.isIntegerValue - ? Constraints.NONE // no need to convert to small int (but now might result in a float) - : Constraints.CONV_IMPLICIT + ? Constraints.None // no need to convert to small int (but now might result in a float) + : Constraints.ConvImplicit ); var inType = compiler.currentType; if ( @@ -2980,7 +2980,7 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 4) ) return module.unreachable(); @@ -2997,24 +2997,24 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef { } var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); var arg1 = ctx.contextIsExact ? compiler.compileExpression(operands[1], contextualType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression( operands[1], type, type.isIntegerValue - ? Constraints.NONE // no need to convert to small int (but now might result in a float) - : Constraints.CONV_IMPLICIT + ? Constraints.None // no need to convert to small int (but now might result in a float) + : Constraints.ConvImplicit ); var inType = compiler.currentType; var arg2 = compiler.compileExpression(operands[2], inType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); if ( type.isIntegerValue && @@ -3043,7 +3043,7 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx) | checkArgsOptional(ctx, 2, 3) ) { @@ -3053,19 +3053,19 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var type = typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); var arg2 = operands.length == 3 - ? compiler.compileExpression(operands[2], Type.i64, Constraints.CONV_IMPLICIT) + ? compiler.compileExpression(operands[2], Type.i64, Constraints.ConvImplicit) : module.i64(-1, -1); // Infinite timeout compiler.currentType = Type.i32; switch (type.kind) { case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return module.atomic_wait(arg0, arg1, arg2, type.toRef()); + case TypeKind.Usize: return module.atomic_wait(arg0, arg1, arg2, type.toRef()); } compiler.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, @@ -3080,7 +3080,7 @@ function builtin_atomic_notify(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeAbsent(ctx) | checkArgsOptional(ctx, 1, 2) ) { @@ -3088,9 +3088,9 @@ function builtin_atomic_notify(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var arg1 = operands.length == 2 - ? compiler.compileExpression(operands[1], Type.i32, Constraints.CONV_IMPLICIT) + ? compiler.compileExpression(operands[1], Type.i32, Constraints.ConvImplicit) : module.i32(-1); // Inifinity count of waiters compiler.currentType = Type.i32; return module.atomic_notify(arg0, arg1); @@ -3103,7 +3103,7 @@ function builtin_atomic_fence(ctx: BuiltinContext): ExpressionRef { var module = compiler.module; compiler.currentType = Type.void; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 0) ) return module.unreachable(); @@ -3124,17 +3124,17 @@ function builtin_select(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT) + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit) : compiler.compileExpression(operands[0], Type.auto); var type = compiler.currentType; - if (!type.isAny(TypeFlags.VALUE | TypeFlags.REFERENCE)) { + if (!type.isAny(TypeFlags.Value | TypeFlags.Reference)) { compiler.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, ctx.reportNode.typeArgumentsRange, "select", type.toString() ); return module.unreachable(); } - var arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + var arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); var arg2 = compiler.makeIsTrueish( compiler.compileExpression(operands[2], Type.bool), compiler.currentType, // ^ @@ -3177,7 +3177,7 @@ function builtin_memory_grow(ctx: BuiltinContext): ExpressionRef { checkTypeAbsent(ctx) | checkArgsRequired(ctx, 1) ) return module.unreachable(); - return module.memory_grow(compiler.compileExpression(ctx.operands[0], Type.i32, Constraints.CONV_IMPLICIT)); + return module.memory_grow(compiler.compileExpression(ctx.operands[0], Type.i32, Constraints.ConvImplicit)); } builtins.set(BuiltinNames.memory_grow, builtin_memory_grow); @@ -3191,7 +3191,7 @@ function builtin_memory_copy(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 3) ) return module.unreachable(); var operands = ctx.operands; - if (!compiler.options.hasFeature(Feature.BULK_MEMORY)) { + if (!compiler.options.hasFeature(Feature.BulkMemory)) { // use stdlib alternative if not supported let instance = compiler.resolver.resolveFunction(ctx.prototype, null); // reports compiler.currentType = Type.void; @@ -3199,9 +3199,9 @@ function builtin_memory_copy(ctx: BuiltinContext): ExpressionRef { return compiler.compileCallDirect(instance, operands, ctx.reportNode); } var usizeType = compiler.options.usizeType; - var arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], usizeType, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], usizeType, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.ConvImplicit); compiler.currentType = Type.void; return module.memory_copy(arg0, arg1, arg2); } @@ -3217,7 +3217,7 @@ function builtin_memory_fill(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 3) ) return module.unreachable(); var operands = ctx.operands; - if (!compiler.options.hasFeature(Feature.BULK_MEMORY)) { + if (!compiler.options.hasFeature(Feature.BulkMemory)) { // use stdlib alternative if not supported let instance = compiler.resolver.resolveFunction(ctx.prototype, null); // reports compiler.currentType = Type.void; @@ -3225,9 +3225,9 @@ function builtin_memory_fill(ctx: BuiltinContext): ExpressionRef { return compiler.compileCallDirect(instance, operands, ctx.reportNode); } var usizeType = compiler.options.usizeType; - var arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.ConvImplicit); compiler.currentType = Type.void; return module.memory_fill(arg0, arg1, arg2); } @@ -3259,7 +3259,7 @@ function builtin_memory_data(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let valuesOperand = operands[0]; - if (valuesOperand.kind != NodeKind.LITERAL || (valuesOperand).literalKind != LiteralKind.ARRAY) { + if (valuesOperand.kind != NodeKind.Literal || (valuesOperand).literalKind != LiteralKind.Array) { compiler.error( DiagnosticCode.Array_literal_expected, operands[0].range @@ -3273,8 +3273,8 @@ function builtin_memory_data(ctx: BuiltinContext): ExpressionRef { let isStatic = true; for (let i = 0; i < numElements; ++i) { let elementExpression = expressions[i]; - if (elementExpression.kind != NodeKind.OMITTED) { - let expr = compiler.compileExpression(elementExpression, elementType, Constraints.CONV_IMPLICIT); + if (elementExpression.kind != NodeKind.Omitted) { + let expr = compiler.compileExpression(elementExpression, elementType, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { expr = precomp; @@ -3306,7 +3306,7 @@ function builtin_memory_data(ctx: BuiltinContext): ExpressionRef { assert(compiler.writeStaticBuffer(buf, 0, elementType, exprs) == buf.byteLength); offset = compiler.addAlignedMemorySegment(buf, align).offset; } else { // data(size[, align]) - let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.ConvImplicit); let precomp = module.runExpression(arg0, ExpressionRunnerFlags.PreserveSideeffects); if (!precomp) { compiler.error( @@ -3356,7 +3356,7 @@ function builtin_i31_new(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.i31ref; return module.i31_new(arg0); } @@ -3370,8 +3370,8 @@ function builtin_i31_get(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.i31ref, Constraints.CONV_IMPLICIT); - if (ctx.contextualType.is(TypeFlags.UNSIGNED)) { + var arg0 = compiler.compileExpression(operands[0], Type.i31ref, Constraints.ConvImplicit); + if (ctx.contextualType.is(TypeFlags.Unsigned)) { compiler.currentType = Type.u32; return module.i31_get(arg0, false); } else { @@ -3426,8 +3426,8 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var contextualType = ctx.contextualType; var arg0 = typeArguments - ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP) - : compiler.compileExpression(operands[0], Type.bool, Constraints.MUST_WRAP); + ? compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit | Constraints.MustWrap) + : compiler.compileExpression(operands[0], Type.bool, Constraints.MustWrap); var type = compiler.currentType; compiler.currentType = type.nonNullableType; @@ -3473,7 +3473,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { if (contextualType == Type.void) { // simplify if dropped anyway compiler.currentType = Type.void; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -3482,24 +3482,24 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.if(module.unary(UnaryOp.EqzI32, arg0), abort); case TypeKind.I64: case TypeKind.U64: return module.if(module.unary(UnaryOp.EqzI64, arg0), abort); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.if(module.unary(UnaryOp.EqzSize, arg0), abort); + case TypeKind.Isize: + case TypeKind.Usize: return module.if(module.unary(UnaryOp.EqzSize, arg0), abort); // TODO: also check for NaN in float assertions, as in `Boolean(NaN) -> false`? case TypeKind.F32: return module.if(module.binary(BinaryOp.EqF32, arg0, module.f32(0)), abort); case TypeKind.F64: return module.if(module.binary(BinaryOp.EqF64, arg0, module.f64(0)), abort); - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.DATAREF: - case TypeKind.I31REF: return module.if(module.ref_is(RefIsOp.Null, arg0), abort); + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.Dataref: + case TypeKind.I31ref: return module.if(module.ref_is(RefIsOp.Null, arg0), abort); } } else { compiler.currentType = type.nonNullableType; let flow = compiler.currentFlow; switch (compiler.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -3507,7 +3507,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.U16: case TypeKind.U32: { let temp = flow.getTempLocal(type); - flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); // arg0 is wrapped + flow.setLocalFlag(temp.index, LocalFlags.Wrapped); // arg0 is wrapped let ret = module.if( module.local_tee(temp.index, arg0, false), // numeric module.local_get(temp.index, TypeRef.I32), @@ -3529,8 +3529,8 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { flow.freeTempLocal(temp); return ret; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { let temp = flow.getTempLocal(compiler.options.usizeType); let ret = module.if( module.unary( @@ -3569,12 +3569,12 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { flow.freeTempLocal(temp); return ret; } - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.DATAREF: - case TypeKind.I31REF: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.Dataref: + case TypeKind.I31ref: { let temp = flow.getTempLocal(type); let ret = module.if( module.ref_is(RefIsOp.Null, @@ -3606,11 +3606,11 @@ function builtin_unchecked(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); var flow = compiler.currentFlow; - var alreadyUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT); - flow.set(FlowFlags.UNCHECKED_CONTEXT); + var alreadyUnchecked = flow.is(FlowFlags.UncheckedContext); + flow.set(FlowFlags.UncheckedContext); // eliminate unnecessary tees by preferring contextualType(=void) var expr = compiler.compileExpression(ctx.operands[0], ctx.contextualType); - if (!alreadyUnchecked) flow.unset(FlowFlags.UNCHECKED_CONTEXT); + if (!alreadyUnchecked) flow.unset(FlowFlags.UncheckedContext); return expr; } builtins.set(BuiltinNames.unchecked, builtin_unchecked); @@ -3632,7 +3632,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { } else { returnType = ctx.contextualType; } - var indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + var indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.ConvImplicit); var numOperands = operands.length - 1; var operandExprs = new Array(numOperands); var paramTypeRefs = new Array(numOperands); @@ -3666,7 +3666,7 @@ function builtin_instantiate(ctx: BuiltinContext): ExpressionRef { compiler.currentType = classInstance.type; var ctor = compiler.ensureConstructor(classInstance, ctx.reportNode); compiler.checkFieldInitialization(classInstance, ctx.reportNode); - return compiler.compileInstantiate(ctor, operands, Constraints.NONE, ctx.reportNode); + return compiler.compileInstantiate(ctor, operands, Constraints.None, ctx.reportNode); } builtins.set(BuiltinNames.instantiate, builtin_instantiate); @@ -3687,26 +3687,26 @@ function builtin_diagnostic(ctx: BuiltinContext, category: DiagnosticCategory): ? operands[0].range.toString() : reportNode.range.toString() ); - return category == DiagnosticCategory.ERROR + return category == DiagnosticCategory.Error ? module.unreachable() : module.nop(); } // ERROR(message?) function builtin_error(ctx: BuiltinContext): ExpressionRef { - return builtin_diagnostic(ctx, DiagnosticCategory.ERROR); + return builtin_diagnostic(ctx, DiagnosticCategory.Error); } builtins.set(BuiltinNames.ERROR, builtin_error); // WARNING(message?) function builtin_warning(ctx: BuiltinContext): ExpressionRef { - return builtin_diagnostic(ctx, DiagnosticCategory.WARNING); + return builtin_diagnostic(ctx, DiagnosticCategory.Warning); } builtins.set(BuiltinNames.WARNING, builtin_warning); // INFO(message?) function builtin_info(ctx: BuiltinContext): ExpressionRef { - return builtin_diagnostic(ctx, DiagnosticCategory.INFO); + return builtin_diagnostic(ctx, DiagnosticCategory.Info); } builtins.set(BuiltinNames.INFO, builtin_info); @@ -3716,7 +3716,7 @@ builtins.set(BuiltinNames.INFO, builtin_info); function builtin_function_call(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var parent = ctx.prototype.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); var classInstance = parent; assert(classInstance.prototype == compiler.program.functionPrototype); var typeArguments = assert(classInstance.typeArguments); @@ -3731,13 +3731,13 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { compiler.currentType = returnType; return compiler.module.unreachable(); } - var functionArg = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); + var functionArg = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.ConvImplicit); var thisOperand = assert(ctx.operands.shift()); var thisType = signature.thisType; var thisArg: usize = 0; if (thisType) { - thisArg = compiler.compileExpression(thisOperand, thisType, Constraints.CONV_IMPLICIT); - } else if (thisOperand.kind != NodeKind.NULL) { + thisArg = compiler.compileExpression(thisOperand, thisType, Constraints.ConvImplicit); + } else if (thisOperand.kind != NodeKind.Null) { compiler.error( DiagnosticCode._this_cannot_be_referenced_in_current_location, thisOperand.range @@ -3772,7 +3772,7 @@ function builtin_conversion(ctx: BuiltinContext, toType: Type): ExpressionRef { compiler.currentType = toType; return compiler.module.unreachable(); } - return compiler.compileExpression(ctx.operands[0], toType, Constraints.CONV_EXPLICIT); + return compiler.compileExpression(ctx.operands[0], toType, Constraints.ConvExplicit); } // i8(*) -> i8 @@ -3866,7 +3866,7 @@ function builtin_i8x16(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 16) ) { @@ -3879,7 +3879,7 @@ function builtin_i8x16(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 16; ++i) { - let expr = compiler.compileExpression(operands[i], Type.i8, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.i8, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { writeI8(getConstValueI32(precomp), bytes, i); @@ -3916,7 +3916,7 @@ function builtin_i16x8(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 8) ) { @@ -3929,7 +3929,7 @@ function builtin_i16x8(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 8; ++i) { - let expr = compiler.compileExpression(operands[i], Type.i16, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.i16, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { writeI16(getConstValueI32(precomp), bytes, i << 1); @@ -3966,7 +3966,7 @@ function builtin_i32x4(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 4) ) { @@ -3979,7 +3979,7 @@ function builtin_i32x4(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 4; ++i) { - let expr = compiler.compileExpression(operands[i], Type.i32, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.i32, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { writeI32(getConstValueI32(precomp), bytes, i << 2); @@ -4016,7 +4016,7 @@ function builtin_i64x2(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4029,7 +4029,7 @@ function builtin_i64x2(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 2; ++i) { - let expr = compiler.compileExpression(operands[i], Type.i64, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.i64, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { let off = i << 3; @@ -4068,7 +4068,7 @@ function builtin_f32x4(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 4) ) { @@ -4081,7 +4081,7 @@ function builtin_f32x4(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 4; ++i) { - let expr = compiler.compileExpression(operands[i], Type.f32, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.f32, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { writeF32(getConstValueF32(precomp), bytes, i << 2); @@ -4118,7 +4118,7 @@ function builtin_f64x2(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4131,7 +4131,7 @@ function builtin_f64x2(ctx: BuiltinContext): ExpressionRef { var numVars = 0; for (let i = 0; i < 2; ++i) { - let expr = compiler.compileExpression(operands[i], Type.f64, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(operands[i], Type.f64, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { writeF64(getConstValueF64(precomp), bytes, i << 3); @@ -4168,7 +4168,7 @@ function builtin_v128_splat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -4178,7 +4178,7 @@ function builtin_v128_splat(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], type, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], type, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -4190,8 +4190,8 @@ function builtin_v128_splat(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.unary(UnaryOp.SplatI32x4, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.SplatI64x2, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.unary( compiler.options.isWasm64 ? UnaryOp.SplatI64x2 @@ -4216,15 +4216,15 @@ function builtin_v128_extract_lane(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsRequired(ctx, 2) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); compiler.currentType = type; var idx = 0; var precomp = module.runExpression(arg1, ExpressionRunnerFlags.PreserveSideeffects); @@ -4254,8 +4254,8 @@ function builtin_v128_extract_lane(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.simd_extract(SIMDExtractOp.ExtractLaneI32x4, arg0, idx); case TypeKind.I64: case TypeKind.U64: return module.simd_extract(SIMDExtractOp.ExtractLaneI64x2, arg0, idx); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_extract( compiler.options.isWasm64 ? SIMDExtractOp.ExtractLaneI64x2 @@ -4280,7 +4280,7 @@ function builtin_v128_replace_lane(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 3) ) { @@ -4290,9 +4290,9 @@ function builtin_v128_replace_lane(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], type, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], type, Constraints.ConvImplicit); compiler.currentType = Type.v128; var idx = 0; var precomp = module.runExpression(arg1, ExpressionRunnerFlags.PreserveSideeffects); @@ -4322,8 +4322,8 @@ function builtin_v128_replace_lane(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.simd_replace(SIMDReplaceOp.ReplaceLaneI32x4, arg0, idx, arg2); case TypeKind.I64: case TypeKind.U64: return module.simd_replace(SIMDReplaceOp.ReplaceLaneI64x2, arg0, idx, arg2); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_replace( compiler.options.isWasm64 ? SIMDReplaceOp.ReplaceLaneI64x2 @@ -4348,7 +4348,7 @@ function builtin_v128_shuffle(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) ) { compiler.currentType = Type.v128; @@ -4367,26 +4367,26 @@ function builtin_v128_shuffle(ctx: BuiltinContext): ExpressionRef { compiler.currentType = Type.v128; return module.unreachable(); } - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); switch (type.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: + case TypeKind.Usize: case TypeKind.F32: case TypeKind.F64: { let mask = new Uint8Array(16); let maxIdx = (laneCount << 1) - 1; for (let i = 0; i < laneCount; ++i) { let operand = operands[2 + i]; - let argN = compiler.compileExpression(operand, Type.u8, Constraints.CONV_IMPLICIT); + let argN = compiler.compileExpression(operand, Type.u8, Constraints.ConvImplicit); let precomp = module.runExpression(argN, ExpressionRunnerFlags.PreserveSideeffects); let idx = 0; if (precomp) { @@ -4460,7 +4460,7 @@ function builtin_v128_swizzle(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4468,8 +4468,8 @@ function builtin_v128_swizzle(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); return module.binary(BinaryOp.SwizzleI8x16, arg0, arg1); } builtins.set(BuiltinNames.v128_swizzle, builtin_v128_swizzle); @@ -4479,14 +4479,14 @@ function builtin_v128_load_splat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var numOperands = operands.length; var immOffset = 0; var immAlign = type.byteSize; @@ -4520,8 +4520,8 @@ function builtin_v128_load_splat(ctx: BuiltinContext): ExpressionRef { case TypeKind.F32: { return module.simd_load(SIMDLoadOp.Load32Splat, arg0, immOffset, immAlign); } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { if (!compiler.options.isWasm64) { return module.simd_load(SIMDLoadOp.Load32Splat, arg0, immOffset, immAlign); } @@ -4547,14 +4547,14 @@ function builtin_v128_load_ext(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var numOperands = operands.length; var immOffset = 0; var immAlign = type.byteSize; @@ -4579,12 +4579,12 @@ function builtin_v128_load_ext(ctx: BuiltinContext): ExpressionRef { case TypeKind.U8: return module.simd_load(SIMDLoadOp.Load8x8U, arg0, immOffset, immAlign); case TypeKind.I16: return module.simd_load(SIMDLoadOp.Load16x4S, arg0, immOffset, immAlign); case TypeKind.U16: return module.simd_load(SIMDLoadOp.Load16x4U, arg0, immOffset, immAlign); - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.simd_load(SIMDLoadOp.Load32x2S, arg0, immOffset, immAlign); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -4604,14 +4604,14 @@ function builtin_v128_load_zero(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); var numOperands = operands.length; var immOffset = 0; var immAlign = type.byteSize; @@ -4638,8 +4638,8 @@ function builtin_v128_load_zero(ctx: BuiltinContext): ExpressionRef { case TypeKind.I64: case TypeKind.U64: case TypeKind.F64: return module.simd_load(SIMDLoadOp.Load64Zero, arg0, immOffset, immAlign); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_load( compiler.options.isWasm64 ? SIMDLoadOp.Load64Zero @@ -4664,16 +4664,16 @@ function builtin_v128_load_lane(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 5) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.ConvImplicit); var idx = 0; var precomp = module.runExpression(arg2, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { @@ -4722,8 +4722,8 @@ function builtin_v128_load_lane(ctx: BuiltinContext): ExpressionRef { case TypeKind.I64: case TypeKind.U64: case TypeKind.F64: return module.simd_loadstorelane(SIMDLoadStoreLaneOp.Load64Lane, arg0, immOffset, immAlign, idx, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_loadstorelane( compiler.options.isWasm64 ? SIMDLoadStoreLaneOp.Load64Lane @@ -4750,16 +4750,16 @@ function builtin_v128_store_lane(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 5) ) return module.unreachable(); var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.ConvImplicit); var idx = 0; var precomp = module.runExpression(arg2, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { @@ -4808,8 +4808,8 @@ function builtin_v128_store_lane(ctx: BuiltinContext): ExpressionRef { case TypeKind.I64: case TypeKind.U64: case TypeKind.F64: return module.simd_loadstorelane(SIMDLoadStoreLaneOp.Store64Lane, arg0, immOffset, immAlign, idx, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_loadstorelane( compiler.options.isWasm64 ? SIMDLoadStoreLaneOp.Store64Lane @@ -4836,7 +4836,7 @@ function builtin_v128_add(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4846,8 +4846,8 @@ function builtin_v128_add(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -4858,8 +4858,8 @@ function builtin_v128_add(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.AddI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.AddI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.binary( compiler.options.isWasm64 ? BinaryOp.AddI64x2 @@ -4884,7 +4884,7 @@ function builtin_v128_sub(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4894,8 +4894,8 @@ function builtin_v128_sub(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -4906,8 +4906,8 @@ function builtin_v128_sub(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.SubI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.SubI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.binary( compiler.options.isWasm64 ? BinaryOp.SubI64x2 @@ -4932,7 +4932,7 @@ function builtin_v128_mul(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4942,8 +4942,8 @@ function builtin_v128_mul(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I16: @@ -4952,8 +4952,8 @@ function builtin_v128_mul(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.MulI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.MulI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.MulI64x2 : BinaryOp.MulI32x4, arg0, arg1); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(compiler.options.isWasm64 ? BinaryOp.MulI64x2 : BinaryOp.MulI32x4, arg0, arg1); case TypeKind.F32: return module.binary(BinaryOp.MulF32x4, arg0, arg1); case TypeKind.F64: return module.binary(BinaryOp.MulF64x2, arg0, arg1); } @@ -4971,7 +4971,7 @@ function builtin_v128_div(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4981,8 +4981,8 @@ function builtin_v128_div(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.DivF32x4, arg0, arg1); @@ -5002,7 +5002,7 @@ function builtin_v128_add_sat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5012,8 +5012,8 @@ function builtin_v128_add_sat(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.AddSatI8x16, arg0, arg1); @@ -5035,7 +5035,7 @@ function builtin_v128_sub_sat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5045,8 +5045,8 @@ function builtin_v128_sub_sat(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.SubSatI8x16, arg0, arg1); @@ -5068,7 +5068,7 @@ function builtin_v128_min(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5078,20 +5078,20 @@ function builtin_v128_min(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.MinI8x16, arg0, arg1); case TypeKind.U8: return module.binary(BinaryOp.MinU8x16, arg0, arg1); case TypeKind.I16: return module.binary(BinaryOp.MinI16x8, arg0, arg1); case TypeKind.U16: return module.binary(BinaryOp.MinU16x8, arg0, arg1); - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.binary(BinaryOp.MinI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5113,7 +5113,7 @@ function builtin_v128_max(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5123,20 +5123,20 @@ function builtin_v128_max(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.MaxI8x16, arg0, arg1); case TypeKind.U8: return module.binary(BinaryOp.MaxU8x16, arg0, arg1); case TypeKind.I16: return module.binary(BinaryOp.MaxI16x8, arg0, arg1); case TypeKind.U16: return module.binary(BinaryOp.MaxU16x8, arg0, arg1); - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.binary(BinaryOp.MaxI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5158,7 +5158,7 @@ function builtin_v128_pmin(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5168,8 +5168,8 @@ function builtin_v128_pmin(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.PminF32x4, arg0, arg1); @@ -5189,7 +5189,7 @@ function builtin_v128_pmax(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5199,8 +5199,8 @@ function builtin_v128_pmax(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.PmaxF32x4, arg0, arg1); @@ -5220,7 +5220,7 @@ function builtin_v128_dot(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5230,8 +5230,8 @@ function builtin_v128_dot(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.DotI16x8, arg0, arg1); @@ -5250,7 +5250,7 @@ function builtin_v128_avgr(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5260,8 +5260,8 @@ function builtin_v128_avgr(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.U8: return module.binary(BinaryOp.AvgrU8x16, arg0, arg1); @@ -5281,7 +5281,7 @@ function builtin_v128_eq(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5291,8 +5291,8 @@ function builtin_v128_eq(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5303,8 +5303,8 @@ function builtin_v128_eq(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.EqI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.EqI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.EqI64x2 : BinaryOp.EqI32x4, arg0, arg1); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(compiler.options.isWasm64 ? BinaryOp.EqI64x2 : BinaryOp.EqI32x4, arg0, arg1); case TypeKind.F32: return module.binary(BinaryOp.EqF32x4, arg0, arg1); case TypeKind.F64: return module.binary(BinaryOp.EqF64x2, arg0, arg1); } @@ -5322,7 +5322,7 @@ function builtin_v128_ne(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5332,8 +5332,8 @@ function builtin_v128_ne(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5344,8 +5344,8 @@ function builtin_v128_ne(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.NeI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.NeI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.NeI64x2 : BinaryOp.NeI32x4, arg0, arg1); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(compiler.options.isWasm64 ? BinaryOp.NeI64x2 : BinaryOp.NeI32x4, arg0, arg1); case TypeKind.F32: return module.binary(BinaryOp.NeF32x4, arg0, arg1); case TypeKind.F64: return module.binary(BinaryOp.NeF64x2, arg0, arg1); } @@ -5363,7 +5363,7 @@ function builtin_v128_lt(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5373,8 +5373,8 @@ function builtin_v128_lt(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.LtI8x16, arg0, arg1); @@ -5385,8 +5385,8 @@ function builtin_v128_lt(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.LtU32x4, arg0, arg1); case TypeKind.I64: return module.binary(BinaryOp.LtI64x2, arg0, arg1); // no LtU64x2 - case TypeKind.ISIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.LtI64x2 : BinaryOp.LtI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Isize: return module.binary(compiler.options.isWasm64 ? BinaryOp.LtI64x2 : BinaryOp.LtI32x4, arg0, arg1); + case TypeKind.Usize: { if (compiler.options.isWasm64) break; return module.binary(BinaryOp.LtU32x4, arg0, arg1); } @@ -5407,7 +5407,7 @@ function builtin_v128_le(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5417,8 +5417,8 @@ function builtin_v128_le(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.LeI8x16, arg0, arg1); @@ -5429,8 +5429,8 @@ function builtin_v128_le(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.LeU32x4, arg0, arg1); case TypeKind.I64: return module.binary(BinaryOp.LeI64x2, arg0, arg1); // no LeU64x2 - case TypeKind.ISIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.LeI64x2 : BinaryOp.LeI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Isize: return module.binary(compiler.options.isWasm64 ? BinaryOp.LeI64x2 : BinaryOp.LeI32x4, arg0, arg1); + case TypeKind.Usize: { if (compiler.options.isWasm64) break; return module.binary(BinaryOp.LeU32x4, arg0, arg1); } @@ -5451,7 +5451,7 @@ function builtin_v128_gt(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5461,8 +5461,8 @@ function builtin_v128_gt(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.GtI8x16, arg0, arg1); @@ -5473,8 +5473,8 @@ function builtin_v128_gt(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.GtU32x4, arg0, arg1); case TypeKind.I64: return module.binary(BinaryOp.GtI64x2, arg0, arg1); // no GtU64x2 - case TypeKind.ISIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.GtI64x2 : BinaryOp.GtI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Isize: return module.binary(compiler.options.isWasm64 ? BinaryOp.GtI64x2 : BinaryOp.GtI32x4, arg0, arg1); + case TypeKind.Usize: { if (compiler.options.isWasm64) break; return module.binary(BinaryOp.GtU32x4, arg0, arg1); } @@ -5495,7 +5495,7 @@ function builtin_v128_ge(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5505,8 +5505,8 @@ function builtin_v128_ge(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.GeI8x16, arg0, arg1); @@ -5517,8 +5517,8 @@ function builtin_v128_ge(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.binary(BinaryOp.GeU32x4, arg0, arg1); case TypeKind.I64: return module.binary(BinaryOp.GeI64x2, arg0, arg1); // no GeU64x2 - case TypeKind.ISIZE: return module.binary(compiler.options.isWasm64 ? BinaryOp.GeI64x2 : BinaryOp.GeI32x4, arg0, arg1); - case TypeKind.USIZE: { + case TypeKind.Isize: return module.binary(compiler.options.isWasm64 ? BinaryOp.GeI64x2 : BinaryOp.GeI32x4, arg0, arg1); + case TypeKind.Usize: { if (compiler.options.isWasm64) break; return module.binary(BinaryOp.GeU32x4, arg0, arg1); } @@ -5539,7 +5539,7 @@ function builtin_v128_narrow(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5549,8 +5549,8 @@ function builtin_v128_narrow(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.NarrowI16x8ToI8x16, arg0, arg1); @@ -5572,7 +5572,7 @@ function builtin_v128_neg(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5582,7 +5582,7 @@ function builtin_v128_neg(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5593,8 +5593,8 @@ function builtin_v128_neg(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.unary(UnaryOp.NegI32x4, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.NegI64x2, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.unary( compiler.options.isWasm64 ? UnaryOp.NegI64x2 @@ -5619,7 +5619,7 @@ function builtin_v128_abs(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5629,19 +5629,19 @@ function builtin_v128_abs(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.unary(UnaryOp.AbsI8x16, arg0); case TypeKind.I16: return module.unary(UnaryOp.AbsI16x8, arg0); case TypeKind.I32: return module.unary(UnaryOp.AbsI32x4, arg0); case TypeKind.I64: return module.unary(UnaryOp.AbsI64x2, arg0); - case TypeKind.ISIZE: return module.unary(compiler.options.isWasm64 ? UnaryOp.AbsI64x2 : UnaryOp.AbsI32x4, arg0); + case TypeKind.Isize: return module.unary(compiler.options.isWasm64 ? UnaryOp.AbsI64x2 : UnaryOp.AbsI32x4, arg0); case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: return arg0; + case TypeKind.Usize: return arg0; case TypeKind.F32: return module.unary(UnaryOp.AbsF32x4, arg0); case TypeKind.F64: return module.unary(UnaryOp.AbsF64x2, arg0); } @@ -5659,7 +5659,7 @@ function builtin_v128_sqrt(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5669,7 +5669,7 @@ function builtin_v128_sqrt(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.SqrtF32x4, arg0); @@ -5689,7 +5689,7 @@ function builtin_v128_ceil(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5699,7 +5699,7 @@ function builtin_v128_ceil(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.CeilF32x4, arg0); @@ -5719,7 +5719,7 @@ function builtin_v128_floor(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5729,7 +5729,7 @@ function builtin_v128_floor(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.FloorF32x4, arg0); @@ -5749,7 +5749,7 @@ function builtin_v128_trunc(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5759,7 +5759,7 @@ function builtin_v128_trunc(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.TruncF32x4, arg0); @@ -5779,7 +5779,7 @@ function builtin_v128_nearest(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5789,7 +5789,7 @@ function builtin_v128_nearest(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.NearestF32x4, arg0); @@ -5809,7 +5809,7 @@ function builtin_v128_convert(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5819,15 +5819,15 @@ function builtin_v128_convert(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.ConvertI32x4ToF32x4, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5847,7 +5847,7 @@ function builtin_v128_convert_low(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5857,15 +5857,15 @@ function builtin_v128_convert_low(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.ConvertLowI32x4ToF64x2, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5885,7 +5885,7 @@ function builtin_v128_trunc_sat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5895,15 +5895,15 @@ function builtin_v128_trunc_sat(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.TruncSatF32x4ToI32x4, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5923,7 +5923,7 @@ function builtin_v128_trunc_sat_zero(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5933,15 +5933,15 @@ function builtin_v128_trunc_sat_zero(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.TruncSatF64x2ToI32x4Zero, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -5961,7 +5961,7 @@ function builtin_v128_extend_low(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5971,19 +5971,19 @@ function builtin_v128_extend_low(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.unary(UnaryOp.ExtendLowI8x16ToI16x8, arg0); case TypeKind.U8: return module.unary(UnaryOp.ExtendLowU8x16ToU16x8, arg0); case TypeKind.I16: return module.unary(UnaryOp.ExtendLowI16x8ToI32x4, arg0); case TypeKind.U16: return module.unary(UnaryOp.ExtendLowU16x8ToU32x4, arg0); - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.ExtendLowI32x4ToI64x2, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -6003,7 +6003,7 @@ function builtin_v128_extend_high(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6013,19 +6013,19 @@ function builtin_v128_extend_high(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.unary(UnaryOp.ExtendHighI8x16ToI16x8, arg0); case TypeKind.U8: return module.unary(UnaryOp.ExtendHighU8x16ToU16x8, arg0); case TypeKind.I16: return module.unary(UnaryOp.ExtendHighI16x8ToI32x4, arg0); case TypeKind.U16: return module.unary(UnaryOp.ExtendHighU16x8ToU32x4, arg0); - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (compiler.options.isWasm64) break; // fall-through } case TypeKind.I32: return module.unary(UnaryOp.ExtendHighI32x4ToI64x2, arg0); - case TypeKind.USIZE: { + case TypeKind.Usize: { if (compiler.options.isWasm64) break; // fall-through } @@ -6045,7 +6045,7 @@ function builtin_v128_shl(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6054,8 +6054,8 @@ function builtin_v128_shl(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6067,8 +6067,8 @@ function builtin_v128_shl(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.simd_shift(SIMDShiftOp.ShlI32x4, arg0, arg1); case TypeKind.I64: case TypeKind.U64: return module.simd_shift(SIMDShiftOp.ShlI64x2, arg0, arg1); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.simd_shift( compiler.options.isWasm64 ? SIMDShiftOp.ShlI64x2 @@ -6091,7 +6091,7 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6100,8 +6100,8 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6113,7 +6113,7 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.simd_shift(SIMDShiftOp.ShrU32x4, arg0, arg1); case TypeKind.I64: return module.simd_shift(SIMDShiftOp.ShrI64x2, arg0, arg1); case TypeKind.U64: return module.simd_shift(SIMDShiftOp.ShrU64x2, arg0, arg1); - case TypeKind.ISIZE: { + case TypeKind.Isize: { return module.simd_shift( compiler.options.isWasm64 ? SIMDShiftOp.ShrI64x2 @@ -6121,7 +6121,7 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { arg0, arg1 ); } - case TypeKind.USIZE: { + case TypeKind.Usize: { return module.simd_shift( compiler.options.isWasm64 ? SIMDShiftOp.ShrU64x2 @@ -6143,7 +6143,7 @@ function builtin_v128_bitwise_binary(ctx: BuiltinContext, op: BinaryOp): Express var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6151,8 +6151,8 @@ function builtin_v128_bitwise_binary(ctx: BuiltinContext, op: BinaryOp): Express return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); return module.binary(op, arg0, arg1); } @@ -6184,7 +6184,7 @@ function builtin_v128_bitwise_unary(ctx: BuiltinContext, op: UnaryOp): Expressio var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6192,7 +6192,7 @@ function builtin_v128_bitwise_unary(ctx: BuiltinContext, op: UnaryOp): Expressio return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); return module.unary(op, arg0); } @@ -6206,7 +6206,7 @@ function builtin_v128_bitwise_ternary(ctx: BuiltinContext, op: SIMDTernaryOp): E var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 3) ) { @@ -6214,9 +6214,9 @@ function builtin_v128_bitwise_ternary(ctx: BuiltinContext, op: SIMDTernaryOp): E return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - var arg2 = compiler.compileExpression(operands[2], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); + var arg2 = compiler.compileExpression(operands[2], Type.v128, Constraints.ConvImplicit); return module.simd_ternary(op, arg0, arg1, arg2); } @@ -6231,7 +6231,7 @@ function builtin_v128_any_true(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6239,7 +6239,7 @@ function builtin_v128_any_true(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.bool; return module.unary(UnaryOp.AnyTrueV128, arg0); } @@ -6250,7 +6250,7 @@ function builtin_v128_all_true(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6259,7 +6259,7 @@ function builtin_v128_all_true(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.bool; if (type.isValue) { switch (type.kind) { @@ -6271,8 +6271,8 @@ function builtin_v128_all_true(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.unary(UnaryOp.AllTrueI32x4, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.AllTrueI64x2, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.unary( compiler.options.isWasm64 ? UnaryOp.AllTrueI64x2 @@ -6295,7 +6295,7 @@ function builtin_v128_bitmask(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6304,7 +6304,7 @@ function builtin_v128_bitmask(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.i32; if (type.isValue) { switch (type.kind) { @@ -6316,8 +6316,8 @@ function builtin_v128_bitmask(ctx: BuiltinContext): ExpressionRef { case TypeKind.U32: return module.unary(UnaryOp.BitmaskI32x4, arg0); case TypeKind.I64: case TypeKind.U64: return module.unary(UnaryOp.BitmaskI64x2, arg0); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return module.unary( compiler.options.isWasm64 ? UnaryOp.BitmaskI64x2 @@ -6340,7 +6340,7 @@ function builtin_v128_popcnt(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6349,7 +6349,7 @@ function builtin_v128_popcnt(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6370,7 +6370,7 @@ function builtin_v128_extadd_pairwise(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6379,7 +6379,7 @@ function builtin_v128_extadd_pairwise(ctx: BuiltinContext): ExpressionRef { } var operands = ctx.operands; var type = ctx.typeArguments![0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6402,7 +6402,7 @@ function builtin_v128_demote_zero(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeOptional(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6412,7 +6412,7 @@ function builtin_v128_demote_zero(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var type = typeArguments ? typeArguments[0] : Type.f64; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6432,7 +6432,7 @@ function builtin_v128_promote_low(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeOptional(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6442,7 +6442,7 @@ function builtin_v128_promote_low(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments; var type = typeArguments ? typeArguments[0] : Type.f32; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6462,7 +6462,7 @@ function builtin_v128_q15mulr_sat(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6472,8 +6472,8 @@ function builtin_v128_q15mulr_sat(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.Q15mulrSatI16x8, arg0, arg1); @@ -6492,7 +6492,7 @@ function builtin_v128_extmul_low(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6502,8 +6502,8 @@ function builtin_v128_extmul_low(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.ExtmulLowI16x8, arg0, arg1); @@ -6527,7 +6527,7 @@ function builtin_v128_extmul_high(ctx: BuiltinContext): ExpressionRef { var compiler = ctx.compiler; var module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6537,8 +6537,8 @@ function builtin_v128_extmul_high(ctx: BuiltinContext): ExpressionRef { var operands = ctx.operands; var typeArguments = ctx.typeArguments!; var type = typeArguments[0]; - var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.ExtmulHighI16x8, arg0, arg1); @@ -6571,7 +6571,7 @@ function builtin_visit_globals(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], Type.u32, Constraints.ConvImplicit); compiler.runtimeFeatures |= RuntimeFeatures.visitGlobals; compiler.currentType = Type.void; return module.call(BuiltinNames.visit_globals, [ arg0 ], TypeRef.None); @@ -6590,8 +6590,8 @@ function builtin_visit_members(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } var operands = ctx.operands; - var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - var arg1 = compiler.compileExpression(operands[1], Type.u32, Constraints.CONV_IMPLICIT); + var arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + var arg1 = compiler.compileExpression(operands[1], Type.u32, Constraints.ConvImplicit); compiler.runtimeFeatures |= RuntimeFeatures.visitMembers; compiler.currentType = Type.void; return module.call(BuiltinNames.visit_members, [ arg0, arg1 ], TypeRef.None); @@ -10171,16 +10171,16 @@ export function compileVisitGlobals(compiler: Compiler): void { // TODO: for (let element of compiler.program.elementsByName.values()) { for (let _values = Map_values(compiler.program.elementsByName), i = 0, k = _values.length; i < k; ++i) { let element = unchecked(_values[i]); - if (element.kind != ElementKind.GLOBAL) continue; + if (element.kind != ElementKind.Global) continue; let global = element; let globalType = global.type; let classReference = globalType.getClass(); if ( classReference && - !classReference.hasDecorator(DecoratorFlags.UNMANAGED) && - global.is(CommonFlags.COMPILED) + !classReference.hasDecorator(DecoratorFlags.Unmanaged) && + global.is(CommonFlags.Compiled) ) { - if (global.is(CommonFlags.INLINED)) { + if (global.is(CommonFlags.Inlined)) { let value = global.constantIntegerValue; if (i64_low(value) || i64_high(value)) { exprs.push( @@ -10248,7 +10248,7 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void { if (instance.isDeclaredInLibrary) { let visitPrototype = instance.getMember("__visit"); if (visitPrototype) { - assert(visitPrototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(visitPrototype.kind == ElementKind.FunctionPrototype); let visitInstance = program.resolver.resolveFunction(visitPrototype, null); if (!visitInstance || !compiler.compileFunction(visitInstance)) { body.push( @@ -10283,7 +10283,7 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void { // TODO: for (let member of members.values()) { for (let _values = Map_values(members), j = 0, l = _values.length; j < l; ++j) { let member = unchecked(_values[j]); - if (member.kind == ElementKind.FIELD) { + if (member.kind == ElementKind.Field) { if ((member).parent == instance) { let fieldType = (member).type; if (fieldType.isManaged) { @@ -10409,10 +10409,12 @@ export function compileVisitMembers(compiler: Compiler): void { function typeToRuntimeFlags(type: Type): TypeinfoFlags { var flags = TypeinfoFlags.VALUE_ALIGN_0 * (1 << type.alignLog2); - if (type.is(TypeFlags.SIGNED)) flags |= TypeinfoFlags.VALUE_SIGNED; - if (type.is(TypeFlags.FLOAT)) flags |= TypeinfoFlags.VALUE_FLOAT; - if (type.is(TypeFlags.NULLABLE)) flags |= TypeinfoFlags.VALUE_NULLABLE; - if (type.isManaged) flags |= TypeinfoFlags.VALUE_MANAGED; + + if (type.is(TypeFlags.Signed)) flags |= TypeinfoFlags.VALUE_SIGNED; + if (type.is(TypeFlags.Float)) flags |= TypeinfoFlags.VALUE_FLOAT; + if (type.is(TypeFlags.Nullable)) flags |= TypeinfoFlags.VALUE_NULLABLE; + if (type.isManaged) flags |= TypeinfoFlags.VALUE_MANAGED; + return flags / TypeinfoFlags.VALUE_ALIGN_0; } @@ -10457,7 +10459,7 @@ export function compileRTTI(compiler: Compiler): void { let typeArguments = assert(instance.getTypeArgumentsTo(mapPrototype)); assert(typeArguments.length == 2); flags |= TypeinfoFlags.MAP; - flags |= TypeinfoFlags.KEY_ALIGN_0 * typeToRuntimeFlags(typeArguments[0]); + flags |= TypeinfoFlags.KEY_ALIGN_0 * typeToRuntimeFlags(typeArguments[0]); flags |= TypeinfoFlags.VALUE_ALIGN_0 * typeToRuntimeFlags(typeArguments[1]); } else if (instance.extends(staticArrayPrototype)) { let valueType = instance.getArrayValueType(); @@ -10569,7 +10571,7 @@ function checkConstantType(ctx: BuiltinContext): Type | null { ); return null; } - checkConstantType_expr = compiler.compileExpression(operands[0], typeArguments[0], Constraints.CONV_IMPLICIT); + checkConstantType_expr = compiler.compileExpression(operands[0], typeArguments[0], Constraints.ConvImplicit); } else { checkConstantType_expr = compiler.compileExpression(operands[0], Type.auto); } @@ -10605,7 +10607,7 @@ function evaluateImmediateOffset(expression: Expression, compiler: Compiler): i3 var module = compiler.module; var value: i32; if (compiler.options.isWasm64) { - let expr = compiler.compileExpression(expression, Type.usize64, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(expression, Type.usize64, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { assert(getConstValueI64High(precomp) == 0); // TODO @@ -10618,7 +10620,7 @@ function evaluateImmediateOffset(expression: Expression, compiler: Compiler): i3 value = -1; } } else { - let expr = compiler.compileExpression(expression, Type.usize32, Constraints.CONV_IMPLICIT); + let expr = compiler.compileExpression(expression, Type.usize32, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { value = getConstValueI32(precomp); diff --git a/src/common.ts b/src/common.ts index 5ee875d89e..3c8f9409ad 100644 --- a/src/common.ts +++ b/src/common.ts @@ -6,82 +6,82 @@ /** Indicates traits of a {@link Node} or {@link Element}. */ export const enum CommonFlags { /** No flags set. */ - NONE = 0, + None = 0, // Basic modifiers /** Has an `import` modifier. */ - IMPORT = 1 << 0, + Import = 1 << 0, /** Has an `export` modifier. */ - EXPORT = 1 << 1, + Export = 1 << 1, /** Has a `declare` modifier. */ - DECLARE = 1 << 2, + Declare = 1 << 2, /** Has a `const` modifier. */ - CONST = 1 << 3, + Const = 1 << 3, /** Has a `let` modifier. */ - LET = 1 << 4, + Let = 1 << 4, /** Has a `static` modifier. */ - STATIC = 1 << 5, + Static = 1 << 5, /** Has a `readonly` modifier. */ - READONLY = 1 << 6, + Readonly = 1 << 6, /** Has an `abstract` modifier. */ - ABSTRACT = 1 << 7, + Abstract = 1 << 7, /** Has a `public` modifier. */ - PUBLIC = 1 << 8, + Public = 1 << 8, /** Has a `private` modifier. */ - PRIVATE = 1 << 9, + Private = 1 << 9, /** Has a `protected` modifier. */ - PROTECTED = 1 << 10, + Protected = 1 << 10, /** Has a `get` modifier. */ - GET = 1 << 11, + Get = 1 << 11, /** Has a `set` modifier. */ - SET = 1 << 12, + Set = 1 << 12, /** Has a `override` modifier. */ - OVERRIDE = 1 << 13, + Override = 1 << 13, /** Has a definite assignment assertion `!` as in `x!: i32;`. */ - DEFINITELY_ASSIGNED = 1 << 14, + DefinitelyAssigned = 1 << 14, // Extended modifiers usually derived from basic modifiers /** Is ambient, that is either declared or nested in a declared element. */ - AMBIENT = 1 << 15, + Ambient = 1 << 15, /** Is generic. */ - GENERIC = 1 << 16, + Generic = 1 << 16, /** Is part of a generic context. */ - GENERIC_CONTEXT = 1 << 17, + GenericContext = 1 << 17, /** Is an instance member. */ - INSTANCE = 1 << 18, + Instance = 1 << 18, /** Is a constructor. */ - CONSTRUCTOR = 1 << 19, + Constructor = 1 << 19, /** Is a module export. */ - MODULE_EXPORT = 1 << 20, + ModuleExport = 1 << 20, /** Is a module import. */ - MODULE_IMPORT = 1 << 21, + ModuleImport = 1 << 21, // Compilation states /** Is resolved. */ - RESOLVED = 1 << 22, + Resolved = 1 << 22, /** Is compiled. */ - COMPILED = 1 << 23, + Compiled = 1 << 23, /** Did error. */ - ERRORED = 1 << 24, + Errored = 1 << 24, /** Has a constant value and is therefore inlined. */ - INLINED = 1 << 25, + Inlined = 1 << 25, /** Is scoped. */ - SCOPED = 1 << 26, + Scoped = 1 << 26, /** Is a stub. */ - STUB = 1 << 27, + Stub = 1 << 27, /** Is a virtual method. */ - VIRTUAL = 1 << 28, + Virtual = 1 << 28, /** Is (part of) a closure. */ - CLOSURE = 1 << 29, + Closure = 1 << 29, // Other /** Is quoted. */ - QUOTED = 1 << 30 + Quoted = 1 << 30 } /** Path delimiter inserted between file system levels. */ @@ -110,7 +110,7 @@ export const STUB_DELIMITER = "@"; /** Common names. */ export namespace CommonNames { // special - export const EMPTY = ""; + export const Empty = ""; // types export const i8 = "i8"; export const i16 = "i16"; diff --git a/src/compiler.ts b/src/compiler.ts index ec149c560e..937261c96b 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -223,8 +223,8 @@ import { export class Options { constructor() { /* as internref */ } - /** WebAssembly target. Defaults to {@link Target.WASM32}. */ - target: Target = Target.WASM32; + /** WebAssembly target. Defaults to {@link Target.Wasm32}. */ + target: Target = Target.Wasm32; /** Runtime type. Defaults to Incremental GC. */ runtime: Runtime = Runtime.Incremental; /** If true, indicates that debug information will be emitted by Binaryen. */ @@ -258,10 +258,10 @@ export class Options { /** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */ globalAliases: Map | null = null; /** Features to activate by default. These are the finished proposals. */ - features: Feature = Feature.MUTABLE_GLOBALS - | Feature.SIGN_EXTENSION - | Feature.NONTRAPPING_F2I - | Feature.BULK_MEMORY; + features: Feature = Feature.MutableGlobals + | Feature.SignExtension + | Feature.NontrappingF2I + | Feature.BulkMemory; /** If true, disallows unsafe features in user code. */ noUnsafe: bool = false; /** If true, enables pedantic diagnostics. */ @@ -290,22 +290,22 @@ export class Options { /** Tests if the target is WASM64 or, otherwise, WASM32. */ get isWasm64(): bool { - return this.target == Target.WASM64; + return this.target == Target.Wasm64; } /** Gets the unsigned size type matching the target. */ get usizeType(): Type { - return this.target == Target.WASM64 ? Type.usize64 : Type.usize32; + return this.target == Target.Wasm64 ? Type.usize64 : Type.usize32; } /** Gets the signed size type matching the target. */ get isizeType(): Type { - return this.target == Target.WASM64 ? Type.isize64 : Type.isize32; + return this.target == Target.Wasm64 ? Type.isize64 : Type.isize32; } /** Gets the size type reference matching the target. */ get sizeTypeRef(): TypeRef { - return this.target == Target.WASM64 ? TypeRef.I64 : TypeRef.I32; + return this.target == Target.Wasm64 ? TypeRef.I64 : TypeRef.I32; } /** Gets if any optimizations will be performed. */ @@ -321,34 +321,34 @@ export class Options { /** Various constraints in expression compilation. */ export const enum Constraints { - NONE = 0, + None = 0, /** Must implicitly convert to the target type. */ - CONV_IMPLICIT = 1 << 0, + ConvImplicit = 1 << 0, /** Must explicitly convert to the target type. */ - CONV_EXPLICIT = 1 << 1, + ConvExplicit = 1 << 1, /** Must wrap small integer values to match the target type. */ - MUST_WRAP = 1 << 2, + MustWrap = 1 << 2, /** Indicates that the value will be dropped immediately. */ - WILL_DROP = 1 << 3, + WillDrop = 1 << 3, /** Indicates that static data is preferred. */ - PREFER_STATIC = 1 << 4, + PreferStatic = 1 << 4, /** Indicates that the value will become `this` of a property access or instance call. */ - IS_THIS = 1 << 5 + IsThis = 1 << 5 } /** Runtime features to be activated by the compiler. */ export const enum RuntimeFeatures { - NONE = 0, + None = 0, /** Requires data setup. */ - DATA = 1 << 0, + Data = 1 << 0, /** Requires a stack. */ - STACK = 1 << 1, + Stack = 1 << 1, /** Requires heap setup. */ - HEAP = 1 << 2, + Heap = 1 << 2, /** Requires runtime type information setup. */ - RTTI = 1 << 3, + Rtti = 1 << 3, /** Requires the built-in globals visitor. */ visitGlobals = 1 << 4, /** Requires the built-in members visitor. */ @@ -415,7 +415,7 @@ export class Compiler extends DiagnosticEmitter { /** Arguments length helper global. */ builtinArgumentsLength: GlobalRef = 0; /** Requires runtime features. */ - runtimeFeatures: RuntimeFeatures = RuntimeFeatures.NONE; + runtimeFeatures: RuntimeFeatures = RuntimeFeatures.None; /** Current inline functions stack. */ inlineStack: Function[] = []; /** Lazily compiled functions. */ @@ -460,21 +460,21 @@ export class Compiler extends DiagnosticEmitter { } } var featureFlags: FeatureFlags = 0; - if (options.hasFeature(Feature.SIGN_EXTENSION)) featureFlags |= FeatureFlags.SignExt; - if (options.hasFeature(Feature.MUTABLE_GLOBALS)) featureFlags |= FeatureFlags.MutableGlobals; - if (options.hasFeature(Feature.NONTRAPPING_F2I)) featureFlags |= FeatureFlags.TruncSat; - if (options.hasFeature(Feature.BULK_MEMORY)) featureFlags |= FeatureFlags.BulkMemory; - if (options.hasFeature(Feature.SIMD)) featureFlags |= FeatureFlags.SIMD; - if (options.hasFeature(Feature.THREADS)) featureFlags |= FeatureFlags.Atomics; - if (options.hasFeature(Feature.EXCEPTION_HANDLING)) featureFlags |= FeatureFlags.ExceptionHandling; - if (options.hasFeature(Feature.TAIL_CALLS)) featureFlags |= FeatureFlags.TailCall; - if (options.hasFeature(Feature.REFERENCE_TYPES)) featureFlags |= FeatureFlags.ReferenceTypes; - if (options.hasFeature(Feature.MULTI_VALUE)) featureFlags |= FeatureFlags.MultiValue; + if (options.hasFeature(Feature.SignExtension)) featureFlags |= FeatureFlags.SignExt; + if (options.hasFeature(Feature.MutableGlobals)) featureFlags |= FeatureFlags.MutableGlobals; + if (options.hasFeature(Feature.NontrappingF2I)) featureFlags |= FeatureFlags.TruncSat; + if (options.hasFeature(Feature.BulkMemory)) featureFlags |= FeatureFlags.BulkMemory; + if (options.hasFeature(Feature.Simd)) featureFlags |= FeatureFlags.Simd; + if (options.hasFeature(Feature.Threads)) featureFlags |= FeatureFlags.Atomics; + if (options.hasFeature(Feature.ExceptionHandling)) featureFlags |= FeatureFlags.ExceptionHandling; + if (options.hasFeature(Feature.TailCalls)) featureFlags |= FeatureFlags.TailCall; + if (options.hasFeature(Feature.ReferenceTypes)) featureFlags |= FeatureFlags.ReferenceTypes; + if (options.hasFeature(Feature.MultiValue)) featureFlags |= FeatureFlags.MultiValue; if (options.hasFeature(Feature.GC)) featureFlags |= FeatureFlags.GC; - if (options.hasFeature(Feature.MEMORY64)) featureFlags |= FeatureFlags.Memory64; - if (options.hasFeature(Feature.FUNCTION_REFERENCES)) featureFlags |= FeatureFlags.FunctionReferences; - if (options.hasFeature(Feature.RELAXED_SIMD)) featureFlags |= FeatureFlags.RelaxedSIMD; - if (options.hasFeature(Feature.EXTENDED_CONST)) featureFlags |= FeatureFlags.ExtendedConst; + if (options.hasFeature(Feature.Memory64)) featureFlags |= FeatureFlags.Memory64; + if (options.hasFeature(Feature.FunctionReferences)) featureFlags |= FeatureFlags.FunctionReferences; + if (options.hasFeature(Feature.RelaxedSimd)) featureFlags |= FeatureFlags.RelaxedSimd; + if (options.hasFeature(Feature.ExtendedConst)) featureFlags |= FeatureFlags.ExtendedConst; module.setFeatures(featureFlags); // set up the main start function @@ -569,8 +569,8 @@ export class Compiler extends DiagnosticEmitter { var virtualStubs = this.virtualStubs; for (let i = 0, k = functionTable.length; i < k; ++i) { let instance = functionTable[i]; - if (instance.is(CommonFlags.VIRTUAL)) { - assert(instance.is(CommonFlags.INSTANCE)); + if (instance.is(CommonFlags.Virtual)) { + assert(instance.is(CommonFlags.Instance)); functionTable[i] = this.ensureVirtualStub(instance); // includes varargs stub } else if (instance.signature.requiredParameters < instance.signature.parameterTypes.length) { functionTable[i] = this.ensureVarargsStub(instance); @@ -599,7 +599,7 @@ export class Compiler extends DiagnosticEmitter { // finalize runtime features module.removeGlobal(BuiltinNames.rtti_base); - if (this.runtimeFeatures & RuntimeFeatures.RTTI) compileRTTI(this); + if (this.runtimeFeatures & RuntimeFeatures.Rtti) compileRTTI(this); if (this.runtimeFeatures & RuntimeFeatures.visitGlobals) compileVisitGlobals(this); if (this.runtimeFeatures & RuntimeFeatures.visitMembers) compileVisitMembers(this); @@ -607,7 +607,7 @@ export class Compiler extends DiagnosticEmitter { // finalize data module.removeGlobal(BuiltinNames.data_end); - if ((this.runtimeFeatures & RuntimeFeatures.DATA) != 0 || hasShadowStack) { + if ((this.runtimeFeatures & RuntimeFeatures.Data) != 0 || hasShadowStack) { if (options.isWasm64) { module.addGlobal(BuiltinNames.data_end, TypeRef.I64, false, module.i64(i64_low(memoryOffset), i64_high(memoryOffset)) @@ -621,7 +621,7 @@ export class Compiler extends DiagnosticEmitter { // finalize stack (grows down from __heap_base to __data_end) module.removeGlobal(BuiltinNames.stack_pointer); - if ((this.runtimeFeatures & RuntimeFeatures.STACK) != 0 || hasShadowStack) { + if ((this.runtimeFeatures & RuntimeFeatures.Stack) != 0 || hasShadowStack) { memoryOffset = i64_align( i64_add(memoryOffset, i64_new(options.stackSize)), options.usizeType.byteSize @@ -639,7 +639,7 @@ export class Compiler extends DiagnosticEmitter { // finalize heap module.removeGlobal(BuiltinNames.heap_base); - if ((this.runtimeFeatures & RuntimeFeatures.HEAP) != 0 || hasShadowStack) { + if ((this.runtimeFeatures & RuntimeFeatures.Heap) != 0 || hasShadowStack) { if (options.isWasm64) { module.addGlobal(BuiltinNames.heap_base, TypeRef.I64, false, module.i64(i64_low(memoryOffset), i64_high(memoryOffset)) @@ -762,7 +762,7 @@ export class Compiler extends DiagnosticEmitter { ); isSharedMemory = false; } - if (!options.hasFeature(Feature.THREADS)) { + if (!options.hasFeature(Feature.Threads)) { this.error( DiagnosticCode.Shared_memory_requires_feature_threads_to_be_enabled, null @@ -888,10 +888,10 @@ export class Compiler extends DiagnosticEmitter { private compileModuleExport(name: string, element: DeclaredElement, prefix: string = ""): void { var module = this.module; switch (element.kind) { - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { // obtain the default instance let functionPrototype = element; - if (!functionPrototype.is(CommonFlags.GENERIC)) { + if (!functionPrototype.is(CommonFlags.Generic)) { let functionInstance = this.resolver.resolveFunction(functionPrototype, null); if (functionInstance) { this.compileModuleExport(name, functionInstance, prefix); @@ -900,9 +900,9 @@ export class Compiler extends DiagnosticEmitter { } break; } - case ElementKind.FUNCTION: { + case ElementKind.Function: { let functionInstance = element; - if (!functionInstance.hasDecorator(DecoratorFlags.BUILTIN)) { + if (!functionInstance.hasDecorator(DecoratorFlags.Builtin)) { let signature = functionInstance.signature; if (signature.requiredParameters < signature.parameterTypes.length) { // utilize varargs stub to fill in omitted arguments @@ -910,7 +910,7 @@ export class Compiler extends DiagnosticEmitter { this.runtimeFeatures |= RuntimeFeatures.setArgumentsLength; } this.compileFunction(functionInstance); - if (functionInstance.is(CommonFlags.COMPILED)) { + if (functionInstance.is(CommonFlags.Compiled)) { let exportName = prefix + name; if (!module.hasExport(exportName)) { module.addFunctionExport(functionInstance.internalName, exportName); @@ -942,10 +942,10 @@ export class Compiler extends DiagnosticEmitter { } break; } - case ElementKind.GLOBAL: { + case ElementKind.Global: { let global = element; - let isConst = global.is(CommonFlags.CONST) || global.is(CommonFlags.STATIC | CommonFlags.READONLY); - if (!isConst && !this.options.hasFeature(Feature.MUTABLE_GLOBALS)) { + let isConst = global.is(CommonFlags.Const) || global.is(CommonFlags.Static | CommonFlags.Readonly); + if (!isConst && !this.options.hasFeature(Feature.MutableGlobals)) { this.warning( DiagnosticCode.Feature_0_is_not_enabled, global.identifierNode.range, "mutable-globals" @@ -953,7 +953,7 @@ export class Compiler extends DiagnosticEmitter { return; } this.compileGlobal(global); - if (global.is(CommonFlags.COMPILED)) { + if (global.is(CommonFlags.Compiled)) { let exportName = prefix + name; if (!module.hasExport(exportName)) { module.addGlobalExport(element.internalName, exportName); @@ -961,7 +961,7 @@ export class Compiler extends DiagnosticEmitter { let type = global.type; if ( liftRequiresExportRuntime(type) || - !global.is(CommonFlags.CONST) && lowerRequiresExportRuntime(type) + !global.is(CommonFlags.Const) && lowerRequiresExportRuntime(type) ) { this.desiresExportRuntime = true; } @@ -980,7 +980,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case ElementKind.ENUM: { + case ElementKind.Enum: { this.compileEnum(element); let members = element.members; if (members) { @@ -988,23 +988,23 @@ export class Compiler extends DiagnosticEmitter { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberName = unchecked(_keys[i]); let member = assert(members.get(memberName)); - if (!member.is(CommonFlags.PRIVATE)) { + if (!member.is(CommonFlags.Private)) { this.compileModuleExport(memberName, member, subPrefix); } } } return; } - case ElementKind.ENUMVALUE: { + case ElementKind.EnumValue: { let enumValue = element; - if (!enumValue.isImmutable && !this.options.hasFeature(Feature.MUTABLE_GLOBALS)) { + if (!enumValue.isImmutable && !this.options.hasFeature(Feature.MutableGlobals)) { this.error( DiagnosticCode.Feature_0_is_not_enabled, enumValue.identifierNode.range, "mutable-globals" ); return; } - if (enumValue.is(CommonFlags.COMPILED)) { + if (enumValue.is(CommonFlags.Compiled)) { let exportName = prefix + name; if (!module.hasExport(exportName)) { module.addGlobalExport(element.internalName, exportName); @@ -1043,8 +1043,8 @@ export class Compiler extends DiagnosticEmitter { /** Compiles the specified file. */ compileFile(file: File): void { - if (file.is(CommonFlags.COMPILED)) return; - file.set(CommonFlags.COMPILED); + if (file.is(CommonFlags.Compiled)) return; + file.set(CommonFlags.Compiled); // compile top-level statements within the file's start function var startFunction = file.startFunction; @@ -1089,8 +1089,8 @@ export class Compiler extends DiagnosticEmitter { /** Compiles a global variable. */ compileGlobal(global: Global): bool { - if (global.is(CommonFlags.COMPILED)) return !global.is(CommonFlags.ERRORED); - global.set(CommonFlags.COMPILED); + if (global.is(CommonFlags.Compiled)) return !global.is(CommonFlags.Errored); + global.set(CommonFlags.Compiled); var pendingElements = this.pendingElements; pendingElements.add(global); @@ -1100,13 +1100,13 @@ export class Compiler extends DiagnosticEmitter { var typeNode = global.typeNode; var initializerNode = global.initializerNode; - if (!global.is(CommonFlags.RESOLVED)) { + if (!global.is(CommonFlags.Resolved)) { // Resolve type if annotated if (typeNode) { let resolvedType = this.resolver.resolveType(typeNode, global.parent); // reports if (!resolvedType) { - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } @@ -1115,7 +1115,7 @@ export class Compiler extends DiagnosticEmitter { DiagnosticCode.Type_expected, typeNode.range ); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } @@ -1125,11 +1125,11 @@ export class Compiler extends DiagnosticEmitter { // Otherwise infer type from initializer } else if (initializerNode) { let previousFlow = this.currentFlow; - if (global.hasDecorator(DecoratorFlags.LAZY)) { + if (global.hasDecorator(DecoratorFlags.Lazy)) { this.currentFlow = global.file.startFunction.flow; } initExpr = this.compileExpression(initializerNode, Type.auto, // reports - Constraints.MUST_WRAP | Constraints.PREFER_STATIC + Constraints.MustWrap | Constraints.PreferStatic ); this.currentFlow = previousFlow; if (this.currentType == Type.void) { @@ -1137,7 +1137,7 @@ export class Compiler extends DiagnosticEmitter { DiagnosticCode.Type_0_is_not_assignable_to_type_1, initializerNode.range, this.currentType.toString(), "" ); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } @@ -1149,33 +1149,33 @@ export class Compiler extends DiagnosticEmitter { DiagnosticCode.Type_expected, global.identifierNode.range.atEnd ); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } } // Handle ambient builtins like '__heap_base' that need to be resolved but are added explicitly - if (global.is(CommonFlags.AMBIENT) && global.hasDecorator(DecoratorFlags.BUILTIN)) { + if (global.is(CommonFlags.Ambient) && global.hasDecorator(DecoratorFlags.Builtin)) { let internalName = global.internalName; - if (internalName == BuiltinNames.data_end) this.runtimeFeatures |= RuntimeFeatures.DATA; - else if (internalName == BuiltinNames.stack_pointer) this.runtimeFeatures |= RuntimeFeatures.STACK; - else if (internalName == BuiltinNames.heap_base) this.runtimeFeatures |= RuntimeFeatures.HEAP; - else if (internalName == BuiltinNames.rtti_base) this.runtimeFeatures |= RuntimeFeatures.RTTI; + if (internalName == BuiltinNames.data_end) this.runtimeFeatures |= RuntimeFeatures.Data; + else if (internalName == BuiltinNames.stack_pointer) this.runtimeFeatures |= RuntimeFeatures.Stack; + else if (internalName == BuiltinNames.heap_base) this.runtimeFeatures |= RuntimeFeatures.Heap; + else if (internalName == BuiltinNames.rtti_base) this.runtimeFeatures |= RuntimeFeatures.Rtti; pendingElements.delete(global); return true; } var type = global.type; var typeRef = type.toRef(); - var isDeclaredConstant = global.is(CommonFlags.CONST) || global.is(CommonFlags.STATIC | CommonFlags.READONLY); - var isDeclaredInline = global.hasDecorator(DecoratorFlags.INLINE); + var isDeclaredConstant = global.is(CommonFlags.Const) || global.is(CommonFlags.Static | CommonFlags.Readonly); + var isDeclaredInline = global.hasDecorator(DecoratorFlags.Inline); // Handle imports - if (global.is(CommonFlags.AMBIENT)) { + if (global.is(CommonFlags.Ambient)) { // Constant global or mutable globals enabled - if (isDeclaredConstant || this.options.hasFeature(Feature.MUTABLE_GLOBALS)) { + if (isDeclaredConstant || this.options.hasFeature(Feature.MutableGlobals)) { mangleImportName(global, global.declaration); this.program.markModuleImport(mangleImportName_moduleName, mangleImportName_elementName, global); module.addGlobalImport( @@ -1197,7 +1197,7 @@ export class Compiler extends DiagnosticEmitter { DiagnosticCode.Feature_0_is_not_enabled, global.declaration.range, "mutable-globals" ); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } @@ -1210,11 +1210,11 @@ export class Compiler extends DiagnosticEmitter { if (initializerNode) { if (!initExpr) { let previousFlow = this.currentFlow; - if (global.hasDecorator(DecoratorFlags.LAZY)) { + if (global.hasDecorator(DecoratorFlags.Lazy)) { this.currentFlow = global.file.startFunction.flow; } initExpr = this.compileExpression(initializerNode, type, - Constraints.CONV_IMPLICIT | Constraints.MUST_WRAP | Constraints.PREFER_STATIC + Constraints.ConvImplicit | Constraints.MustWrap | Constraints.PreferStatic ); this.currentFlow = previousFlow; } @@ -1240,7 +1240,7 @@ export class Compiler extends DiagnosticEmitter { let elementsByName = this.program.elementsByName; if (elementsByName.has(fromName)) { let global = assert(elementsByName.get(fromName)); - if (global.is(CommonFlags.AMBIENT)) initializeInStart = false; + if (global.is(CommonFlags.Ambient)) initializeInStart = false; } } } @@ -1257,12 +1257,12 @@ export class Compiler extends DiagnosticEmitter { let exprType = getExpressionType(initExpr); switch (exprType) { case TypeRef.I32: { - global.constantValueKind = ConstantValueKind.INTEGER; + global.constantValueKind = ConstantValueKind.Integer; global.constantIntegerValue = i64_new(getConstValueI32(initExpr), 0); break; } case TypeRef.I64: { - global.constantValueKind = ConstantValueKind.INTEGER; + global.constantValueKind = ConstantValueKind.Integer; global.constantIntegerValue = i64_new( getConstValueI64Low(initExpr), getConstValueI64High(initExpr) @@ -1270,30 +1270,30 @@ export class Compiler extends DiagnosticEmitter { break; } case TypeRef.F32: { - global.constantValueKind = ConstantValueKind.FLOAT; + global.constantValueKind = ConstantValueKind.Float; global.constantFloatValue = getConstValueF32(initExpr); break; } case TypeRef.F64: { - global.constantValueKind = ConstantValueKind.FLOAT; + global.constantValueKind = ConstantValueKind.Float; global.constantFloatValue = getConstValueF64(initExpr); break; } default: { assert(false); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } } - global.set(CommonFlags.INLINED); // inline the value from now on + global.set(CommonFlags.Inlined); // inline the value from now on } } // Initialize to zero if there's no initializer } else { - if (global.is(CommonFlags.INLINED)) { - initExpr = this.compileInlineConstant(global, global.type, Constraints.PREFER_STATIC); + if (global.is(CommonFlags.Inlined)) { + initExpr = this.compileInlineConstant(global, global.type, Constraints.PreferStatic); } else { initExpr = this.makeZero(type); } @@ -1305,7 +1305,7 @@ export class Compiler extends DiagnosticEmitter { if (isDeclaredInline) { this.error( DiagnosticCode.Decorator_0_is_not_valid_here, - findDecorator(DecoratorKind.INLINE, global.decoratorNodes)!.range, "inline" + findDecorator(DecoratorKind.Inline, global.decoratorNodes)!.range, "inline" ); } module.addGlobal(internalName, typeRef, true, this.makeZero(type)); @@ -1323,8 +1323,8 @@ export class Compiler extends DiagnosticEmitter { /** Compiles an enum. */ compileEnum(element: Enum): bool { - if (element.is(CommonFlags.COMPILED)) return !element.is(CommonFlags.ERRORED); - element.set(CommonFlags.COMPILED); + if (element.is(CommonFlags.Compiled)) return !element.is(CommonFlags.Errored); + element.set(CommonFlags.Compiled); var pendingElements = this.pendingElements; pendingElements.add(element); @@ -1334,33 +1334,33 @@ export class Compiler extends DiagnosticEmitter { this.currentParent = element; var previousValue: EnumValue | null = null; var previousValueIsMut = false; - var isInline = element.is(CommonFlags.CONST) || element.hasDecorator(DecoratorFlags.INLINE); + var isInline = element.is(CommonFlags.Const) || element.hasDecorator(DecoratorFlags.Inline); var members = element.members; if (members) { // TODO: for (let member of element.members.values()) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = unchecked(_values[i]); - if (member.kind != ElementKind.ENUMVALUE) continue; // happens if an enum is also a namespace + if (member.kind != ElementKind.EnumValue) continue; // happens if an enum is also a namespace let initInStart = false; let enumValue = member; let valueNode = enumValue.valueNode; - enumValue.set(CommonFlags.COMPILED); + enumValue.set(CommonFlags.Compiled); let previousFlow = this.currentFlow; - if (element.hasDecorator(DecoratorFlags.LAZY)) { + if (element.hasDecorator(DecoratorFlags.Lazy)) { this.currentFlow = element.file.startFunction.flow; } let initExpr: ExpressionRef; if (valueNode) { initExpr = this.compileExpression(valueNode, Type.i32, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); if (getExpressionId(initExpr) != ExpressionId.Const) { let precomp = module.runExpression(initExpr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { initExpr = precomp; } else { - if (element.is(CommonFlags.CONST)) { + if (element.is(CommonFlags.Const)) { this.error( DiagnosticCode.In_const_enum_declarations_member_initializer_must_be_constant_expression, valueNode.range @@ -1391,7 +1391,7 @@ export class Compiler extends DiagnosticEmitter { if (precomp) { initExpr = precomp; } else { - if (element.is(CommonFlags.CONST)) { + if (element.is(CommonFlags.Const)) { this.error( DiagnosticCode.In_const_enum_declarations_member_initializer_must_be_constant_expression, member.declaration.range @@ -1411,7 +1411,7 @@ export class Compiler extends DiagnosticEmitter { } else { if (isInline) { enumValue.setConstantIntegerValue(i64_new(getConstValueI32(initExpr)), Type.i32); - if (enumValue.is(CommonFlags.MODULE_EXPORT)) { + if (enumValue.is(CommonFlags.ModuleExport)) { module.addGlobal(enumValue.internalName, TypeRef.I32, false, initExpr); } } else { @@ -1437,11 +1437,11 @@ export class Compiler extends DiagnosticEmitter { /** Force compilation of stdlib alternative if a builtin. */ forceStdAlternative: bool = false ): bool { - if (instance.is(CommonFlags.COMPILED)) return !instance.is(CommonFlags.ERRORED); + if (instance.is(CommonFlags.Compiled)) return !instance.is(CommonFlags.Errored); if (!forceStdAlternative) { - if (instance.hasDecorator(DecoratorFlags.BUILTIN)) return true; - if (instance.hasDecorator(DecoratorFlags.LAZY)) { + if (instance.hasDecorator(DecoratorFlags.Builtin)) return true; + if (instance.hasDecorator(DecoratorFlags.Lazy)) { this.lazyFunctions.add(instance); return true; } @@ -1467,7 +1467,7 @@ export class Compiler extends DiagnosticEmitter { } } - instance.set(CommonFlags.COMPILED); + instance.set(CommonFlags.Compiled); var pendingElements = this.pendingElements; pendingElements.add(instance); @@ -1476,7 +1476,7 @@ export class Compiler extends DiagnosticEmitter { var signature = instance.signature; var bodyNode = instance.prototype.bodyNode; var declarationNode = instance.declaration; - assert(declarationNode.kind == NodeKind.FUNCTIONDECLARATION || declarationNode.kind == NodeKind.METHODDECLARATION); + assert(declarationNode.kind == NodeKind.FunctionDeclaration || declarationNode.kind == NodeKind.MethodDeclaration); this.checkSignatureSupported(instance.signature, (declarationNode).signature); var funcRef: FunctionRef; @@ -1485,7 +1485,7 @@ export class Compiler extends DiagnosticEmitter { if (bodyNode) { // must not be ambient - if (instance.is(CommonFlags.AMBIENT)) { + if (instance.is(CommonFlags.Ambient)) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, instance.identifierNode.range @@ -1493,16 +1493,16 @@ export class Compiler extends DiagnosticEmitter { } // cannot have an annotated external name or code - if (instance.hasAnyDecorator(DecoratorFlags.EXTERNAL | DecoratorFlags.EXTERNAL_JS)) { + if (instance.hasAnyDecorator(DecoratorFlags.External | DecoratorFlags.ExternalJs)) { let decoratorNodes = instance.decoratorNodes; let decorator: DecoratorNode | null; - if (decorator = findDecorator(DecoratorKind.EXTERNAL, decoratorNodes)) { + if (decorator = findDecorator(DecoratorKind.External, decoratorNodes)) { this.error( DiagnosticCode.Decorator_0_is_not_valid_here, decorator.range, "external" ); } - if (decorator = findDecorator(DecoratorKind.EXTERNAL_JS, decoratorNodes)) { + if (decorator = findDecorator(DecoratorKind.ExternalJs, decoratorNodes)) { this.error( DiagnosticCode.Decorator_0_is_not_valid_here, decorator.range, "external.js" @@ -1532,7 +1532,7 @@ export class Compiler extends DiagnosticEmitter { ); // imported function - } else if (instance.is(CommonFlags.AMBIENT)) { + } else if (instance.is(CommonFlags.Ambient)) { mangleImportName(instance, declarationNode); // TODO: check for duplicates this.program.markModuleImport(mangleImportName_moduleName, mangleImportName_elementName, instance); module.addFunctionImport( @@ -1562,7 +1562,7 @@ export class Compiler extends DiagnosticEmitter { } // abstract or interface function - } else if (instance.is(CommonFlags.ABSTRACT) || instance.parent.kind == ElementKind.INTERFACE) { + } else if (instance.is(CommonFlags.Abstract) || instance.parent.kind == ElementKind.Interface) { funcRef = module.addFunction( instance.internalName, signature.paramRefs, @@ -1576,10 +1576,10 @@ export class Compiler extends DiagnosticEmitter { instance.identifierNode.range ); funcRef = 0; // TODO? - instance.set(CommonFlags.ERRORED); + instance.set(CommonFlags.Errored); } - if (instance.is(CommonFlags.AMBIENT) || instance.is(CommonFlags.EXPORT)) { + if (instance.is(CommonFlags.Ambient) || instance.is(CommonFlags.Export)) { // Verify and print warn if signature has v128 type for imported or exported functions let hasVectorValueOperands = signature.hasVectorValueOperands; if (hasVectorValueOperands) { @@ -1621,42 +1621,42 @@ export class Compiler extends DiagnosticEmitter { var bodyStartIndex = stmts.length; // compile statements - if (bodyNode.kind == NodeKind.BLOCK) { + if (bodyNode.kind == NodeKind.Block) { stmts = this.compileStatements((bodyNode).statements, true, stmts); } else { // must be an expression statement if not a block - assert(bodyNode.kind == NodeKind.EXPRESSION); + assert(bodyNode.kind == NodeKind.Expression); // must be an arrow function assert(instance.prototype.arrowKind); // none of the following can be an arrow function - assert(!instance.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.GET | CommonFlags.SET)); + assert(!instance.isAny(CommonFlags.Constructor | CommonFlags.Get | CommonFlags.Set)); - let expr = this.compileExpression((bodyNode).expression, returnType, Constraints.CONV_IMPLICIT); - if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); - if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.RETURNS_NONNULL); + let expr = this.compileExpression((bodyNode).expression, returnType, Constraints.ConvImplicit); + if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.ReturnsWrapped); + if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.ReturnsNonNull); if (!stmts) stmts = [ expr ]; else stmts.push(expr); - if (!flow.is(FlowFlags.TERMINATES)) { - if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); - if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.RETURNS_NONNULL); - flow.set(FlowFlags.RETURNS | FlowFlags.TERMINATES); + if (!flow.is(FlowFlags.Terminates)) { + if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.ReturnsWrapped); + if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.ReturnsNonNull); + flow.set(FlowFlags.Returns | FlowFlags.Terminates); } } // Make constructors return their instance pointer, and prepend a conditional // allocation if any code path accesses `this`. - if (instance.is(CommonFlags.CONSTRUCTOR)) { - assert(instance.is(CommonFlags.INSTANCE)); + if (instance.is(CommonFlags.Constructor)) { + assert(instance.is(CommonFlags.Instance)); thisLocal = assert(thisLocal); let parent = assert(instance.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; - if (flow.isAny(FlowFlags.ACCESSES_THIS | FlowFlags.CONDITIONALLY_ACCESSES_THIS) || !flow.is(FlowFlags.TERMINATES)) { + if (flow.isAny(FlowFlags.AccessesThis | FlowFlags.ConditionallyAccessesThis) || !flow.is(FlowFlags.Terminates)) { // Allocate `this` if not a super call, and initialize fields let allocStmts = new Array(); @@ -1672,7 +1672,7 @@ export class Compiler extends DiagnosticEmitter { stmts[bodyStartIndex] = module.flatten(allocStmts, TypeRef.None); // Just prepended allocation is dropped when returning non-'this' - if (flow.is(FlowFlags.MAY_RETURN_NONTHIS)) { + if (flow.is(FlowFlags.MayReturnNonThis)) { if (this.options.pedantic) { this.pedantic( DiagnosticCode.Explicitly_returning_constructor_drops_this_allocation, @@ -1683,7 +1683,7 @@ export class Compiler extends DiagnosticEmitter { } // Returning something else than 'this' would break 'super()' calls - if (flow.is(FlowFlags.MAY_RETURN_NONTHIS) && !classInstance.hasDecorator(DecoratorFlags.FINAL)) { + if (flow.is(FlowFlags.MayReturnNonThis) && !classInstance.hasDecorator(DecoratorFlags.Final)) { this.error( DiagnosticCode.A_class_with_a_constructor_explicitly_returning_something_else_than_this_must_be_final, classInstance.identifierNode.range @@ -1691,15 +1691,15 @@ export class Compiler extends DiagnosticEmitter { } // Implicitly return `this` if the flow falls through - if (!flow.is(FlowFlags.TERMINATES)) { + if (!flow.is(FlowFlags.Terminates)) { stmts.push( module.local_get(thisLocal.index, this.options.sizeTypeRef) ); - flow.set(FlowFlags.RETURNS | FlowFlags.RETURNS_NONNULL | FlowFlags.TERMINATES); + flow.set(FlowFlags.Returns | FlowFlags.ReturnsNonNull | FlowFlags.Terminates); } // check that super has been called if this is a derived class - if (classInstance.base && !flow.is(FlowFlags.CALLS_SUPER)) { + if (classInstance.base && !flow.is(FlowFlags.CallsSuper)) { this.error( DiagnosticCode.Constructors_for_derived_classes_must_contain_a_super_call, instance.prototype.declaration.range @@ -1707,7 +1707,7 @@ export class Compiler extends DiagnosticEmitter { } // if this is a normal function, make sure that all branches terminate - } else if (returnType != Type.void && !flow.is(FlowFlags.TERMINATES)) { + } else if (returnType != Type.void && !flow.is(FlowFlags.Terminates)) { this.error( DiagnosticCode.A_function_whose_declared_type_is_not_void_must_return_a_value, instance.prototype.functionTypeNode.returnType.range @@ -1722,7 +1722,7 @@ export class Compiler extends DiagnosticEmitter { compileField(instance: Field): bool { this.compileFieldGetter(instance); this.compileFieldSetter(instance); - return instance.is(CommonFlags.COMPILED); + return instance.is(CommonFlags.Compiled); } /** Compiles the getter of the specified instance field. */ @@ -1740,7 +1740,7 @@ export class Compiler extends DiagnosticEmitter { ) ); if (instance.setterRef) { - instance.set(CommonFlags.COMPILED); + instance.set(CommonFlags.Compiled); } else { let typeNode = instance.typeNode; if (typeNode) this.checkTypeSupported(instance.type, typeNode); @@ -1763,7 +1763,7 @@ export class Compiler extends DiagnosticEmitter { ); if (type.isManaged) { let parent = instance.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); if ((parent).type.isManaged) { let linkInstance = this.program.linkInstance; this.compileFunction(linkInstance); @@ -1777,11 +1777,15 @@ export class Compiler extends DiagnosticEmitter { ], TypeRef.None); } } - instance.setterRef = module.addFunction(instance.internalSetterName, createType([ thisTypeRef, valueTypeRef ]), TypeRef.None, null, + instance.setterRef = module.addFunction( + instance.internalSetterName, + createType([ thisTypeRef, valueTypeRef ]), + TypeRef.None, + null, bodyExpr ); if (instance.getterRef) { - instance.set(CommonFlags.COMPILED); + instance.set(CommonFlags.Compiled); } else { let typeNode = instance.typeNode; if (typeNode) this.checkTypeSupported(instance.type, typeNode); @@ -1965,7 +1969,7 @@ export class Compiler extends DiagnosticEmitter { /** Ensures that a runtime counterpart of the specified function exists and returns its address. */ ensureRuntimeFunction(instance: Function): i64 { - assert(instance.is(CommonFlags.COMPILED) && !instance.is(CommonFlags.STUB)); + assert(instance.is(CommonFlags.Compiled) && !instance.is(CommonFlags.Stub)); var program = this.program; var memorySegment = instance.memorySegment; if (!memorySegment) { @@ -1992,22 +1996,22 @@ export class Compiler extends DiagnosticEmitter { /** Compiles a top level statement (incl. function declarations etc.) to the specified body. */ compileTopLevelStatement(statement: Statement, body: ExpressionRef[]): void { switch (statement.kind) { - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { let memberStatements = (statement).members; for (let i = 0, k = memberStatements.length; i < k; ++i) { this.compileTopLevelStatement(memberStatements[i], body); } break; } - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { let element = this.program.getElementByDeclaration(statement); if (element) { - assert(element.kind == ElementKind.ENUM); - if (!element.hasDecorator(DecoratorFlags.LAZY)) this.compileEnum(element); + assert(element.kind == ElementKind.Enum); + if (!element.hasDecorator(DecoratorFlags.Lazy)) this.compileEnum(element); } break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { let declaration = statement; let element = this.program.getElementByDeclaration(declaration); if (element) { @@ -2022,28 +2026,28 @@ export class Compiler extends DiagnosticEmitter { } break; } - case NodeKind.VARIABLE: { + case NodeKind.Variable: { let declarations = (statement).declarations; for (let i = 0, k = declarations.length; i < k; ++i) { let element = this.program.getElementByDeclaration(declarations[i]); if (element) { - assert(element.kind == ElementKind.GLOBAL); + assert(element.kind == ElementKind.Global); if ( - !element.is(CommonFlags.AMBIENT) && // delay imports - !element.hasDecorator(DecoratorFlags.LAZY) + !element.is(CommonFlags.Ambient) && // delay imports + !element.hasDecorator(DecoratorFlags.Lazy) ) this.compileGlobal(element); } } break; } - case NodeKind.FIELDDECLARATION: { + case NodeKind.FieldDeclaration: { let element = this.program.getElementByDeclaration(statement); - if (element && element.kind == ElementKind.GLOBAL) { // static - if (!element.hasDecorator(DecoratorFlags.LAZY)) this.compileGlobal(element); + if (element && element.kind == ElementKind.Global) { // static + if (!element.hasDecorator(DecoratorFlags.Lazy)) this.compileGlobal(element); } break; } - case NodeKind.EXPORT: { + case NodeKind.Export: { let exportStatement = statement; let internalPath = exportStatement.internalPath; if (internalPath != null) { @@ -2051,20 +2055,20 @@ export class Compiler extends DiagnosticEmitter { } break; } - case NodeKind.EXPORTDEFAULT: { + case NodeKind.ExportDefault: { this.compileTopLevelStatement((statement).declaration, body); break; } - case NodeKind.IMPORT: { + case NodeKind.Import: { let importStatement = statement; this.compileFileByPath(importStatement.internalPath, importStatement.path); break; } - case NodeKind.FUNCTIONDECLARATION: - case NodeKind.METHODDECLARATION: - case NodeKind.INTERFACEDECLARATION: - case NodeKind.INDEXSIGNATURE: - case NodeKind.TYPEDECLARATION: break; + case NodeKind.FunctionDeclaration: + case NodeKind.MethodDeclaration: + case NodeKind.InterfaceDeclaration: + case NodeKind.IndexSignature: + case NodeKind.TypeDeclaration: break; default: { // otherwise a top-level statement that is part of the start function's body let stmt = this.compileStatement(statement); if (getExpressionId(stmt) != ExpressionId.Nop) body.push(stmt); @@ -2083,72 +2087,72 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var stmt: ExpressionRef; switch (statement.kind) { - case NodeKind.BLOCK: { + case NodeKind.Block: { stmt = this.compileBlockStatement(statement); break; } - case NodeKind.BREAK: { + case NodeKind.Break: { stmt = this.compileBreakStatement(statement); break; } - case NodeKind.CONTINUE: { + case NodeKind.Continue: { stmt = this.compileContinueStatement(statement); break; } - case NodeKind.DO: { + case NodeKind.Do: { stmt = this.compileDoStatement(statement); break; } - case NodeKind.EMPTY: { + case NodeKind.Empty: { stmt = this.compileEmptyStatement(statement); break; } - case NodeKind.EXPRESSION: { + case NodeKind.Expression: { stmt = this.compileExpressionStatement(statement); break; } - case NodeKind.FOR: { + case NodeKind.For: { stmt = this.compileForStatement(statement); break; } - case NodeKind.FOROF: { + case NodeKind.ForOf: { stmt = this.compileForOfStatement(statement); break; } - case NodeKind.IF: { + case NodeKind.If: { stmt = this.compileIfStatement(statement); break; } - case NodeKind.RETURN: { + case NodeKind.Return: { stmt = this.compileReturnStatement(statement, isLastInBody); break; } - case NodeKind.SWITCH: { + case NodeKind.Switch: { stmt = this.compileSwitchStatement(statement); break; } - case NodeKind.THROW: { + case NodeKind.Throw: { stmt = this.compileThrowStatement(statement); break; } - case NodeKind.TRY: { + case NodeKind.Try: { stmt = this.compileTryStatement(statement); break; } - case NodeKind.VARIABLE: { + case NodeKind.Variable: { stmt = this.compileVariableStatement(statement); if (!stmt) stmt = module.nop(); break; } - case NodeKind.VOID: { + case NodeKind.Void: { stmt = this.compileVoidStatement(statement); break; } - case NodeKind.WHILE: { + case NodeKind.While: { stmt = this.compileWhileStatement(statement); break; } - case NodeKind.TYPEDECLARATION: { + case NodeKind.TypeDeclaration: { // TODO: integrate inner type declaration into flow this.error( DiagnosticCode.Not_implemented_0, @@ -2158,7 +2162,7 @@ export class Compiler extends DiagnosticEmitter { stmt = module.unreachable(); break; } - case NodeKind.MODULE: { + case NodeKind.Module: { stmt = module.nop(); break; } @@ -2200,7 +2204,7 @@ export class Compiler extends DiagnosticEmitter { default: stmts.push(stmt); case ExpressionId.Nop: } - if (flow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS)) { + if (flow.isAny(FlowFlags.Terminates | FlowFlags.Breaks)) { if (needsExplicitUnreachable(stmt)) stmts.push(module.unreachable()); break; } @@ -2246,7 +2250,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } flow.freeScopedLocals(); - flow.set(FlowFlags.BREAKS); + flow.set(FlowFlags.Breaks); return module.br(breakLabel); } @@ -2273,7 +2277,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - flow.set(FlowFlags.CONTINUES | FlowFlags.TERMINATES); + flow.set(FlowFlags.Continues | FlowFlags.Terminates); flow.freeScopedLocals(); return module.br(continueLabel); } @@ -2324,15 +2328,15 @@ export class Compiler extends DiagnosticEmitter { this.currentFlow = bodyFlow; var bodyStmts = new Array(); var body = statement.body; - if (body.kind == NodeKind.BLOCK) { + if (body.kind == NodeKind.Block) { this.compileStatements((body).statements, false, bodyStmts); } else { bodyStmts.push(this.compileStatement(body)); } // Shortcut if body never falls through - var possiblyContinues = bodyFlow.isAny(FlowFlags.CONTINUES | FlowFlags.CONDITIONALLY_CONTINUES); - if (bodyFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS) && !possiblyContinues) { + var possiblyContinues = bodyFlow.isAny(FlowFlags.Continues | FlowFlags.ConditionallyContinues); + if (bodyFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks) && !possiblyContinues) { bodyStmts.push( module.unreachable() ); @@ -2356,21 +2360,21 @@ export class Compiler extends DiagnosticEmitter { } // Shortcut if condition is always false - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { bodyStmts.push( module.drop(condExpr) ); flow.inherit(bodyFlow); // Terminate if condition is always true and body never breaks - } else if (condKind == ConditionKind.TRUE && !bodyFlow.isAny(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) { + } else if (condKind == ConditionKind.True && !bodyFlow.isAny(FlowFlags.Breaks | FlowFlags.ConditionallyBreaks)) { bodyStmts.push( module.drop(condExpr) ); bodyStmts.push( module.br(loopLabel) ); - flow.set(FlowFlags.TERMINATES); + flow.set(FlowFlags.Terminates); } else { bodyStmts.push( @@ -2401,7 +2405,7 @@ export class Compiler extends DiagnosticEmitter { module.flatten(bodyStmts) ) ]); - if (outerFlow.is(FlowFlags.TERMINATES)) { + if (outerFlow.is(FlowFlags.Terminates)) { expr = module.block(null, [ expr, module.unreachable() ]); } return expr; @@ -2416,7 +2420,7 @@ export class Compiler extends DiagnosticEmitter { private compileExpressionStatement( statement: ExpressionStatement ): ExpressionRef { - return this.compileExpression(statement.expression, Type.void, Constraints.CONV_IMPLICIT); + return this.compileExpression(statement.expression, Type.void, Constraints.ConvImplicit); } private compileForStatement( @@ -2469,8 +2473,8 @@ export class Compiler extends DiagnosticEmitter { var initializer = statement.initializer; if (initializer) { assert( - initializer.kind == NodeKind.EXPRESSION || - initializer.kind == NodeKind.VARIABLE + initializer.kind == NodeKind.Expression || + initializer.kind == NodeKind.Variable ); stmts.push(this.compileStatement(initializer)); } @@ -2493,7 +2497,7 @@ export class Compiler extends DiagnosticEmitter { condKind = this.evaluateCondition(condExpr); // Shortcut if condition is always false (body never runs) - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { stmts.push( module.drop(condExpr) ); @@ -2507,7 +2511,7 @@ export class Compiler extends DiagnosticEmitter { } } else { condExpr = module.i32(1); - condKind = ConditionKind.TRUE; + condKind = ConditionKind.True; } // From here on condition is either always true or unknown @@ -2529,17 +2533,17 @@ export class Compiler extends DiagnosticEmitter { this.currentFlow = bodyFlow; var bodyStmts = new Array(); var body = statement.body; - if (body.kind == NodeKind.BLOCK) { + if (body.kind == NodeKind.Block) { this.compileStatements((body).statements, false, bodyStmts); } else { bodyStmts.push(this.compileStatement(body)); } // Check if body terminates - if (bodyFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS)) { + if (bodyFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks)) { bodyStmts.push(module.unreachable()); } - if (condKind == ConditionKind.TRUE) flow.inherit(bodyFlow); + if (condKind == ConditionKind.True) flow.inherit(bodyFlow); else flow.inheritBranch(bodyFlow); bodyFlow.freeScopedLocals(); @@ -2550,13 +2554,13 @@ export class Compiler extends DiagnosticEmitter { // Compile the incrementor if it runs // Can still fall through to here if body continues, hence is already known to terminate - if (!bodyFlow.is(FlowFlags.TERMINATES) || bodyFlow.isAny(FlowFlags.CONTINUES | FlowFlags.CONDITIONALLY_CONTINUES)) { + if (!bodyFlow.is(FlowFlags.Terminates) || bodyFlow.isAny(FlowFlags.Continues | FlowFlags.ConditionallyContinues)) { let incrementor = statement.incrementor; if (incrementor) { let incrFlow = flow.fork(); this.currentFlow = incrFlow; ifStmts.push( - this.compileExpression(incrementor, Type.void, Constraints.CONV_IMPLICIT | Constraints.WILL_DROP) + this.compileExpression(incrementor, Type.void, Constraints.ConvImplicit | Constraints.WillDrop) ); incrFlow.freeScopedLocals(); flow.inherit(incrFlow); // mostly local flags, also covers late termination by throwing @@ -2598,7 +2602,7 @@ export class Compiler extends DiagnosticEmitter { flow.freeScopedLocals(); outerFlow.inherit(flow); outerFlow.popBreakLabel(); - if (outerFlow.is(FlowFlags.TERMINATES)) { + if (outerFlow.is(FlowFlags.Terminates)) { stmts.push(module.unreachable()); } this.currentFlow = outerFlow; @@ -2646,13 +2650,13 @@ export class Compiler extends DiagnosticEmitter { // Shortcut if the condition is constant switch (condKind) { - case ConditionKind.TRUE: { + case ConditionKind.True: { return module.block(null, [ module.drop(condExpr), this.compileStatement(ifTrue) ]); } - case ConditionKind.FALSE: { + case ConditionKind.False: { return ifFalse ? module.block(null, [ module.drop(condExpr), @@ -2671,12 +2675,12 @@ export class Compiler extends DiagnosticEmitter { var thenFlow = flow.fork(); this.currentFlow = thenFlow; thenFlow.inheritNonnullIfTrue(condExpr); - if (ifTrue.kind == NodeKind.BLOCK) { + if (ifTrue.kind == NodeKind.Block) { this.compileStatements((ifTrue).statements, false, thenStmts); } else { thenStmts.push(this.compileStatement(ifTrue)); } - var thenTerminates = thenFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS); + var thenTerminates = thenFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks); if (thenTerminates) { thenStmts.push(module.unreachable()); } @@ -2689,12 +2693,12 @@ export class Compiler extends DiagnosticEmitter { let elseFlow = flow.fork(); this.currentFlow = elseFlow; elseFlow.inheritNonnullIfFalse(condExpr); - if (ifFalse.kind == NodeKind.BLOCK) { + if (ifFalse.kind == NodeKind.Block) { this.compileStatements((ifFalse).statements, false, elseStmts); } else { elseStmts.push(this.compileStatement(ifFalse)); } - let elseTerminates = elseFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS); + let elseTerminates = elseFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks); if (elseTerminates) { elseStmts.push(module.unreachable()); } @@ -2708,7 +2712,7 @@ export class Compiler extends DiagnosticEmitter { } else { flow.inheritBranch(thenFlow); flow.inheritNonnullIfFalse(condExpr, - thenFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS) + thenFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks) ? null // thenFlow terminates: just inherit : thenFlow // must become nonnull in thenFlow otherwise ); @@ -2729,14 +2733,14 @@ export class Compiler extends DiagnosticEmitter { var valueExpression = statement.value; if (valueExpression) { - let constraints = Constraints.CONV_IMPLICIT; - if (flow.actualFunction.is(CommonFlags.MODULE_EXPORT)) constraints |= Constraints.MUST_WRAP; + let constraints = Constraints.ConvImplicit; + if (flow.actualFunction.is(CommonFlags.ModuleExport)) constraints |= Constraints.MustWrap; expr = this.compileExpression(valueExpression, returnType, constraints); - if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); - if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.RETURNS_NONNULL); - if (flow.actualFunction.is(CommonFlags.CONSTRUCTOR) && valueExpression.kind != NodeKind.THIS) { - flow.set(FlowFlags.MAY_RETURN_NONTHIS); + if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.ReturnsWrapped); + if (flow.isNonnull(expr, returnType)) flow.set(FlowFlags.ReturnsNonNull); + if (flow.actualFunction.is(CommonFlags.Constructor) && valueExpression.kind != NodeKind.This) { + flow.set(FlowFlags.MayReturnNonThis); } } else if (returnType != Type.void) { this.error( @@ -2749,7 +2753,7 @@ export class Compiler extends DiagnosticEmitter { flow.freeScopedLocals(); // Remember that this flow returns - flow.set(FlowFlags.RETURNS | FlowFlags.TERMINATES); + flow.set(FlowFlags.Returns | FlowFlags.Terminates); // Handle inline return if (flow.isInline) { @@ -2785,7 +2789,7 @@ export class Compiler extends DiagnosticEmitter { var numCases = cases.length; if (!numCases) { return this.compileExpression(statement.condition, Type.void, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } @@ -2802,7 +2806,7 @@ export class Compiler extends DiagnosticEmitter { breaks[0] = module.local_set( // initializer tempLocalIndex, this.compileExpression(statement.condition, Type.u32, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ), false // u32 ); @@ -2818,7 +2822,7 @@ export class Compiler extends DiagnosticEmitter { module.binary(BinaryOp.EqI32, module.local_get(tempLocalIndex, TypeRef.I32), this.compileExpression(label, Type.u32, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) ) ); @@ -2837,7 +2841,7 @@ export class Compiler extends DiagnosticEmitter { // nest blocks in order var currentBlock = module.block(`case0|${context}`, breaks, TypeRef.None); - var commonCategorical = FlowFlags.ANY_CATEGORICAL; + var commonCategorical = FlowFlags.AnyCategorical; var commonConditional = 0; for (let i = 0; i < numCases; ++i) { let case_ = cases[i]; @@ -2861,13 +2865,13 @@ export class Compiler extends DiagnosticEmitter { if (getExpressionId(stmt) != ExpressionId.Nop) { stmts[count++] = stmt; } - if (innerFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS)) { - if (innerFlow.is(FlowFlags.TERMINATES)) terminates = true; + if (innerFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks)) { + if (innerFlow.is(FlowFlags.Terminates)) terminates = true; break; } } stmts.length = count; - if (terminates || isLast || innerFlow.isAny(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) { + if (terminates || isLast || innerFlow.isAny(FlowFlags.Breaks | FlowFlags.ConditionallyBreaks)) { commonCategorical &= innerFlow.flags; } @@ -2875,8 +2879,8 @@ export class Compiler extends DiagnosticEmitter { // Switch back to the parent flow innerFlow.unset( - FlowFlags.BREAKS | - FlowFlags.CONDITIONALLY_BREAKS + FlowFlags.Breaks | + FlowFlags.ConditionallyBreaks ); innerFlow.freeScopedLocals(); this.currentFlow = outerFlow; @@ -2885,8 +2889,8 @@ export class Compiler extends DiagnosticEmitter { outerFlow.popBreakLabel(); // If the switch has a default (guaranteed to handle any value), propagate common flags - if (defaultIndex >= 0) outerFlow.flags |= commonCategorical & ~FlowFlags.BREAKS; - outerFlow.flags |= commonConditional & ~FlowFlags.CONDITIONALLY_BREAKS; + if (defaultIndex >= 0) outerFlow.flags |= commonCategorical & ~FlowFlags.Breaks; + outerFlow.flags |= commonConditional & ~FlowFlags.ConditionallyBreaks; // TODO: what about local states? return currentBlock; } @@ -2898,12 +2902,12 @@ export class Compiler extends DiagnosticEmitter { var flow = this.currentFlow; // Remember that this branch throws - flow.set(FlowFlags.THROWS | FlowFlags.TERMINATES); + flow.set(FlowFlags.Throws | FlowFlags.Terminates); var stmts = new Array(); var value = statement.value; var message: Expression | null = null; - if (value.kind == NodeKind.NEW) { + if (value.kind == NodeKind.New) { let newArgs = (value).args; if (newArgs.length) message = newArgs[0]; // FIXME: naively assumes type string } @@ -2961,7 +2965,7 @@ export class Compiler extends DiagnosticEmitter { let dummy = flow.addScopedDummyLocal(name, type, statement); // pending dummy pendingElements.add(dummy); initExpr = this.compileExpression(initializerNode, type, // reports - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); pendingElements.delete(dummy); flow.freeScopedDummyLocal(name); @@ -2995,7 +2999,7 @@ export class Compiler extends DiagnosticEmitter { } // Handle constants, and try to inline if value is static - let isConst = declaration.is(CommonFlags.CONST); + let isConst = declaration.is(CommonFlags.Const); let isStatic = false; if (isConst) { if (initExpr) { @@ -3067,7 +3071,7 @@ export class Compiler extends DiagnosticEmitter { if (!isStatic) { let local: Local; if ( - declaration.isAny(CommonFlags.LET | CommonFlags.CONST) || + declaration.isAny(CommonFlags.Let | CommonFlags.Const) || flow.isInline ) { // here: not top-level let existingLocal = flow.getScopedLocal(name); @@ -3089,7 +3093,7 @@ export class Compiler extends DiagnosticEmitter { } else { local = flow.addScopedLocal(name, type); } - if (isConst) flow.setLocalFlag(local.index, LocalFlags.CONSTANT); + if (isConst) flow.setLocalFlag(local.index, LocalFlags.Constant); } else { let existing = flow.lookupLocal(name); if (existing) { @@ -3102,7 +3106,7 @@ export class Compiler extends DiagnosticEmitter { continue; } local = flow.parentFunction.addLocal(type, name, declaration); - if (isConst) flow.setLocalFlag(local.index, LocalFlags.CONSTANT); + if (isConst) flow.setLocalFlag(local.index, LocalFlags.Constant); } if (initExpr) { initializers.push( @@ -3111,7 +3115,7 @@ export class Compiler extends DiagnosticEmitter { } else { // no need to assign zero if (local.type.isShortIntegerValue) { - flow.setLocalFlag(local.index, LocalFlags.WRAPPED); + flow.setLocalFlag(local.index, LocalFlags.Wrapped); } } } @@ -3126,7 +3130,7 @@ export class Compiler extends DiagnosticEmitter { statement: VoidStatement ): ExpressionRef { return this.compileExpression(statement.expression, Type.void, - Constraints.CONV_EXPLICIT | Constraints.WILL_DROP + Constraints.ConvExplicit | Constraints.WillDrop ); } @@ -3182,7 +3186,7 @@ export class Compiler extends DiagnosticEmitter { var condKind = this.evaluateCondition(condExpr); // Shortcut if condition is always false (body never runs) - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { stmts.push( module.drop(condExpr) ); @@ -3210,29 +3214,29 @@ export class Compiler extends DiagnosticEmitter { this.currentFlow = bodyFlow; var bodyStmts = new Array(); var body = statement.body; - if (body.kind == NodeKind.BLOCK) { + if (body.kind == NodeKind.Block) { this.compileStatements((body).statements, false, bodyStmts); } else { bodyStmts.push(this.compileStatement(body)); } // Simplify if body always terminates - if (bodyFlow.is(FlowFlags.TERMINATES)) { + if (bodyFlow.is(FlowFlags.Terminates)) { bodyStmts.push( module.unreachable() ); - if (condKind == ConditionKind.TRUE) flow.inherit(bodyFlow); + if (condKind == ConditionKind.True) flow.inherit(bodyFlow); else flow.inheritBranch(bodyFlow); // Terminate if condition is always true and body never breaks - } else if (condKind == ConditionKind.TRUE && !bodyFlow.isAny(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) { + } else if (condKind == ConditionKind.True && !bodyFlow.isAny(FlowFlags.Breaks | FlowFlags.ConditionallyBreaks)) { bodyStmts.push( module.br(continueLabel) ); - flow.set(FlowFlags.TERMINATES); + flow.set(FlowFlags.Terminates); } else { - let breaks = bodyFlow.is(FlowFlags.BREAKS); + let breaks = bodyFlow.is(FlowFlags.Breaks); if (breaks) { bodyStmts.push( module.unreachable() @@ -3242,7 +3246,7 @@ export class Compiler extends DiagnosticEmitter { module.br(continueLabel) ); } - if (condKind == ConditionKind.TRUE) flow.inherit(bodyFlow); + if (condKind == ConditionKind.True) flow.inherit(bodyFlow); else flow.inheritBranch(bodyFlow); // Detect if local flags are incompatible before and after looping, and @@ -3274,7 +3278,7 @@ export class Compiler extends DiagnosticEmitter { module.flatten(stmts) ) ]); - if (condKind == ConditionKind.TRUE && outerFlow.is(FlowFlags.TERMINATES)) { + if (condKind == ConditionKind.True && outerFlow.is(FlowFlags.Terminates)) { expr = module.block(null, [ expr, module.unreachable() ]); } return expr; @@ -3288,13 +3292,13 @@ export class Compiler extends DiagnosticEmitter { contextualType: Type, constraints: Constraints ): ExpressionRef { - assert(element.is(CommonFlags.INLINED | CommonFlags.RESOLVED)); + assert(element.is(CommonFlags.Inlined | CommonFlags.Resolved)); var type = element.type; this.currentType = type; switch (type.kind) { - case TypeKind.BOOL: { + case TypeKind.Bool: { return this.module.i32( - element.constantValueKind == ConstantValueKind.INTEGER + element.constantValueKind == ConstantValueKind.Integer // @ts-ignore ? i64_ne(element.constantIntegerValue, i64_zero) : 0 @@ -3304,7 +3308,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.I16: { let shift = type.computeSmallIntegerShift(Type.i32); return this.module.i32( - element.constantValueKind == ConstantValueKind.INTEGER + element.constantValueKind == ConstantValueKind.Integer ? i64_low(element.constantIntegerValue) << shift >> shift : 0 ); // recognized by canOverflow @@ -3313,7 +3317,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U16: { let mask = element.type.computeSmallIntegerMask(Type.i32); return this.module.i32( - element.constantValueKind == ConstantValueKind.INTEGER + element.constantValueKind == ConstantValueKind.Integer ? i64_low(element.constantIntegerValue) & mask : 0 ); // recognized by canOverflow @@ -3321,16 +3325,16 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.I32: case TypeKind.U32: { return this.module.i32( - element.constantValueKind == ConstantValueKind.INTEGER + element.constantValueKind == ConstantValueKind.Integer ? i64_low(element.constantIntegerValue) : 0 ); } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { if (!element.program.options.isWasm64) { return this.module.i32( - element.constantValueKind == ConstantValueKind.INTEGER + element.constantValueKind == ConstantValueKind.Integer ? i64_low(element.constantIntegerValue) : 0 ); @@ -3339,7 +3343,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I64: case TypeKind.U64: { - return element.constantValueKind == ConstantValueKind.INTEGER + return element.constantValueKind == ConstantValueKind.Integer ? this.module.i64( i64_low(element.constantIntegerValue), i64_high(element.constantIntegerValue) @@ -3348,7 +3352,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.F64: { // monkey-patch for converting built-in floats to f32 implicitly - if (!(element.hasDecorator(DecoratorFlags.BUILTIN) && contextualType == Type.f32)) { + if (!(element.hasDecorator(DecoratorFlags.Builtin) && contextualType == Type.f32)) { return this.module.f64(element.constantFloatValue); } // otherwise fall-through: basically precomputes f32.demote/f64 of NaN / Infinity @@ -3367,83 +3371,83 @@ export class Compiler extends DiagnosticEmitter { compileExpression( expression: Expression, contextualType: Type, - constraints: Constraints = Constraints.NONE + constraints: Constraints = Constraints.None ): ExpressionRef { - while (expression.kind == NodeKind.PARENTHESIZED) { // skip + while (expression.kind == NodeKind.Parenthesized) { // skip expression = (expression).expression; } this.currentType = contextualType; - if (contextualType == Type.void) constraints |= Constraints.WILL_DROP; + if (contextualType == Type.void) constraints |= Constraints.WillDrop; var expr: ExpressionRef; switch (expression.kind) { - case NodeKind.ASSERTION: { + case NodeKind.Assertion: { expr = this.compileAssertionExpression(expression, contextualType, constraints); break; } - case NodeKind.BINARY: { + case NodeKind.Binary: { expr = this.compileBinaryExpression(expression, contextualType, constraints); break; } - case NodeKind.CALL: { + case NodeKind.Call: { expr = this.compileCallExpression(expression, contextualType, constraints); break; } - case NodeKind.COMMA: { + case NodeKind.Comma: { expr = this.compileCommaExpression(expression, contextualType, constraints); break; } - case NodeKind.ELEMENTACCESS: { + case NodeKind.ElementAccess: { expr = this.compileElementAccessExpression(expression, contextualType, constraints); break; } - case NodeKind.FUNCTION: { + case NodeKind.Function: { expr = this.compileFunctionExpression(expression, contextualType, constraints); break; } - case NodeKind.IDENTIFIER: - case NodeKind.FALSE: - case NodeKind.NULL: - case NodeKind.THIS: - case NodeKind.SUPER: - case NodeKind.TRUE: { + case NodeKind.Identifier: + case NodeKind.False: + case NodeKind.Null: + case NodeKind.This: + case NodeKind.Super: + case NodeKind.True: { expr = this.compileIdentifierExpression(expression, contextualType, constraints); break; } - case NodeKind.INSTANCEOF: { + case NodeKind.InstanceOf: { expr = this.compileInstanceOfExpression(expression, contextualType, constraints); break; } - case NodeKind.LITERAL: { + case NodeKind.Literal: { expr = this.compileLiteralExpression(expression, contextualType, constraints); break; } - case NodeKind.NEW: { + case NodeKind.New: { expr = this.compileNewExpression(expression, contextualType, constraints); break; } - case NodeKind.PROPERTYACCESS: { + case NodeKind.PropertyAccess: { expr = this.compilePropertyAccessExpression(expression, contextualType, constraints); break; } - case NodeKind.TERNARY: { + case NodeKind.Ternary: { expr = this.compileTernaryExpression(expression, contextualType, constraints); break; } - case NodeKind.UNARYPOSTFIX: { + case NodeKind.UnaryPostfix: { expr = this.compileUnaryPostfixExpression(expression, contextualType, constraints); break; } - case NodeKind.UNARYPREFIX: { + case NodeKind.UnaryPrefix: { expr = this.compileUnaryPrefixExpression(expression, contextualType, constraints); break; } - case NodeKind.COMPILED: { + case NodeKind.Compiled: { let compiled = expression; expr = compiled.expr; this.currentType = compiled.type; break; } - case NodeKind.CLASS: { + case NodeKind.Class: { // TODO: compile as class expression this.error( DiagnosticCode.Not_implemented_0, @@ -3460,12 +3464,12 @@ export class Compiler extends DiagnosticEmitter { } // ensure conversion and wrapping in case the respective function doesn't on its own var currentType = this.currentType; - var wrap = (constraints & Constraints.MUST_WRAP) != 0; + var wrap = (constraints & Constraints.MustWrap) != 0; if (currentType != contextualType.nonNullableType) { // allow assigning non-nullable to nullable - if (constraints & Constraints.CONV_EXPLICIT) { + if (constraints & Constraints.ConvExplicit) { expr = this.convertExpression(expr, currentType, contextualType, true, expression); this.currentType = currentType = contextualType; - } else if (constraints & Constraints.CONV_IMPLICIT) { + } else if (constraints & Constraints.ConvImplicit) { expr = this.convertExpression(expr, currentType, contextualType, false, expression); this.currentType = currentType = contextualType; } @@ -3491,8 +3495,8 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { var module = this.module; - if (fromType.kind == TypeKind.VOID) { - if (toType.kind == TypeKind.VOID) { + if (fromType.kind == TypeKind.Void) { + if (toType.kind == TypeKind.Void) { // void to void: Can happen as a result of a foregoing error. Since we // have an `expr` here that is already supposed to be void, return it. return expr; @@ -3506,7 +3510,7 @@ export class Compiler extends DiagnosticEmitter { } // any to void - if (toType.kind == TypeKind.VOID) return module.drop(expr); + if (toType.kind == TypeKind.Void) return module.drop(expr); // reference involved if (fromType.isReference || toType.isReference) { @@ -3613,14 +3617,14 @@ export class Compiler extends DiagnosticEmitter { if (toType.isBooleanValue) { expr = this.makeIsTrueish(expr, Type.f32, reportNode); } else if (toType.isSignedIntegerValue) { - let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I); + let saturating = this.options.hasFeature(Feature.NontrappingF2I); if (toType.isLongIntegerValue) { expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI64 : UnaryOp.TruncF32ToI64, expr); } else { expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI32 : UnaryOp.TruncF32ToI32, expr); } } else { - let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I); + let saturating = this.options.hasFeature(Feature.NontrappingF2I); if (toType.isLongIntegerValue) { expr = module.unary(saturating ? UnaryOp.TruncSatF32ToU64 : UnaryOp.TruncF32ToU64, expr); } else { @@ -3633,14 +3637,14 @@ export class Compiler extends DiagnosticEmitter { if (toType.isBooleanValue) { expr = this.makeIsTrueish(expr, Type.f64, reportNode); } else if (toType.isSignedIntegerValue) { - let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I); + let saturating = this.options.hasFeature(Feature.NontrappingF2I); if (toType.isLongIntegerValue) { expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI64 : UnaryOp.TruncF64ToI64, expr); } else { expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI32 : UnaryOp.TruncF64ToI32, expr); } } else { - let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I); + let saturating = this.options.hasFeature(Feature.NontrappingF2I); if (toType.isLongIntegerValue) { expr = module.unary(saturating ? UnaryOp.TruncSatF64ToU64 : UnaryOp.TruncF64ToU64, expr); } else { @@ -3651,7 +3655,7 @@ export class Compiler extends DiagnosticEmitter { // float to void } else { - assert(toType.flags == TypeFlags.NONE, "void type expected"); + assert(toType.flags == TypeFlags.None, "void type expected"); expr = module.drop(expr); } @@ -3747,10 +3751,10 @@ export class Compiler extends DiagnosticEmitter { contextualType: Type, constraints: Constraints ): ExpressionRef { - var inheritedConstraints = constraints & ~(Constraints.CONV_IMPLICIT | Constraints.CONV_EXPLICIT); + var inheritedConstraints = constraints & ~(Constraints.ConvImplicit | Constraints.ConvExplicit); switch (expression.assertionKind) { - case AssertionKind.PREFIX: - case AssertionKind.AS: { + case AssertionKind.Prefix: + case AssertionKind.As: { let flow = this.currentFlow; let toType = this.resolver.resolveType( // reports assert(expression.toType), @@ -3758,9 +3762,9 @@ export class Compiler extends DiagnosticEmitter { cloneMap(flow.contextualTypeArguments) ); if (!toType) return this.module.unreachable(); - return this.compileExpression(expression.expression, toType, inheritedConstraints | Constraints.CONV_EXPLICIT); + return this.compileExpression(expression.expression, toType, inheritedConstraints | Constraints.ConvExplicit); } - case AssertionKind.NONNULL: { + case AssertionKind.NonNull: { assert(!expression.toType); let expr = this.compileExpression(expression.expression, contextualType.exceptVoid, inheritedConstraints); let type = this.currentType; @@ -3775,13 +3779,13 @@ export class Compiler extends DiagnosticEmitter { this.currentType = type.nonNullableType; return expr; } - case AssertionKind.CONST: { + case AssertionKind.Const: { // TODO: decide on the layout of ReadonlyArray first // let operand = expression.expression; - // if (operand.kind == NodeKind.LITERAL && (operand).literalKind == LiteralKind.ARRAY) { + // if (operand.kind == NodeKind.Literal && (operand).literalKind == LiteralKind.Array) { // let element = this.resolver.lookupExpression(expression /* ! */, this.currentFlow, contextualType); // if (!element) return this.module.unreachable(); - // if (element.kind == ElementKind.CLASS) { + // if (element.kind == ElementKind.Class) { // let arrayInstance = element; // if (arrayInstance.extends(this.program.readonlyArrayPrototype)) { // return this.compileStaticArrayLiteral(operand, arrayInstance.type, constraints); @@ -4097,7 +4101,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4142,7 +4146,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4187,7 +4191,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4232,7 +4236,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4277,7 +4281,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4322,7 +4326,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4365,7 +4369,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = this.currentType; expr = this.makeShl(leftExpr, rightExpr, rightType); @@ -4393,7 +4397,7 @@ export class Compiler extends DiagnosticEmitter { return this.module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = this.currentType; expr = this.makeShr(leftExpr, rightExpr, rightType); @@ -4420,7 +4424,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = this.currentType; expr = this.makeShru(leftExpr, rightExpr, rightType); @@ -4449,7 +4453,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4494,7 +4498,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4539,7 +4543,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - rightExpr = this.compileExpression(right, leftType, Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, Constraints.ConvImplicit); rightType = commonType = this.currentType; } else { rightExpr = this.compileExpression(right, leftType); @@ -4566,7 +4570,7 @@ export class Compiler extends DiagnosticEmitter { case Token.AMPERSAND_AMPERSAND: { // left && right -> (t = left) ? right : t let flow = this.currentFlow; - let inheritedConstraints = constraints & Constraints.MUST_WRAP; + let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); leftType = this.currentType; @@ -4580,7 +4584,7 @@ export class Compiler extends DiagnosticEmitter { // shortcut if lhs is always false let condKind = this.evaluateCondition(leftExpr); - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { expr = leftExpr; } else { rightExpr = this.compileExpression(right, leftType, inheritedConstraints); @@ -4589,7 +4593,7 @@ export class Compiler extends DiagnosticEmitter { rightExpr = this.makeIsTrueish(rightExpr, rightType, right); // simplify if lhs is always true - if (condKind == ConditionKind.TRUE) { + if (condKind == ConditionKind.True) { expr = rightExpr; } else { expr = module.if(leftExpr, rightExpr, module.i32(0)); @@ -4599,7 +4603,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; } else { - rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.ConvImplicit); rightType = this.currentType; rightFlow.freeScopedLocals(); this.currentFlow = flow; @@ -4615,8 +4619,8 @@ export class Compiler extends DiagnosticEmitter { // if not possible, tee left to a temp } else { let tempLocal = flow.getTempLocal(leftType); - if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(tempLocal.index, LocalFlags.WRAPPED); - if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(tempLocal.index, LocalFlags.NONNULL); + if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(tempLocal.index, LocalFlags.Wrapped); + if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(tempLocal.index, LocalFlags.NonNull); expr = module.if( this.makeIsTrueish(module.local_tee(tempLocal.index, leftExpr, leftType.isManaged), leftType, left), rightExpr, @@ -4630,7 +4634,7 @@ export class Compiler extends DiagnosticEmitter { } case Token.BAR_BAR: { // left || right -> ((t = left) ? t : right) let flow = this.currentFlow; - let inheritedConstraints = constraints & Constraints.MUST_WRAP; + let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); leftType = this.currentType; @@ -4644,7 +4648,7 @@ export class Compiler extends DiagnosticEmitter { // shortcut if lhs is always true let condKind = this.evaluateCondition(leftExpr); - if (condKind == ConditionKind.TRUE) { + if (condKind == ConditionKind.True) { expr = leftExpr; } else { rightExpr = this.compileExpression(right, leftType, inheritedConstraints); @@ -4653,7 +4657,7 @@ export class Compiler extends DiagnosticEmitter { rightExpr = this.makeIsTrueish(rightExpr, rightType, right); // simplify if lhs is always false - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { expr = rightExpr; } else { expr = module.if(leftExpr, module.i32(1), rightExpr); @@ -4663,7 +4667,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; } else { - rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT); + rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.ConvImplicit); rightType = this.currentType; rightFlow.freeScopedLocals(); this.currentFlow = flow; @@ -4679,8 +4683,8 @@ export class Compiler extends DiagnosticEmitter { // if not possible, tee left to a temp. local } else { let temp = flow.getTempLocal(leftType); - if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); - if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.NONNULL); + if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.Wrapped); + if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.NonNull); expr = module.if( this.makeIsTrueish(module.local_tee(temp.index, leftExpr, leftType.isManaged), leftType, left), module.local_get(temp.index, leftType.toRef()), @@ -4733,8 +4737,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.LtI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.LtI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.LtISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.LtISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -4743,7 +4747,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.LtU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.LtU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.LtUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.LtUSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.LtF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.LtF64, leftExpr, rightExpr); } @@ -4763,8 +4767,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.GtI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.GtI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.GtISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.GtISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -4773,7 +4777,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.GtU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.GtU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.GtUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.GtUSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.GtF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.GtF64, leftExpr, rightExpr); } @@ -4793,8 +4797,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.LeI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.LeI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.LeISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.LeISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -4803,7 +4807,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.LeU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.LeU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.LeUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.LeUSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.LeF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.LeF64, leftExpr, rightExpr); } @@ -4823,8 +4827,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.GeI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.GeI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.GeISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.GeISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -4833,7 +4837,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.GeU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.GeU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.GeUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.GeUSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.GeF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.GeF64, leftExpr, rightExpr); } @@ -4845,7 +4849,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4858,8 +4862,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.EqI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.EqI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.EqSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.EqSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.EqF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.EqF64, leftExpr, rightExpr); case TypeKind.V128: { @@ -4867,12 +4871,12 @@ export class Compiler extends DiagnosticEmitter { module.binary(BinaryOp.EqI8x16, leftExpr, rightExpr) ); } - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: return module.ref_eq(leftExpr, rightExpr); - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: { + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: return module.ref_eq(leftExpr, rightExpr); + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: { this.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, reportNode.range, @@ -4890,7 +4894,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4903,8 +4907,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.NeI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.NeI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.NeSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.NeSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.NeF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.NeF64, leftExpr, rightExpr); case TypeKind.V128: { @@ -4912,16 +4916,16 @@ export class Compiler extends DiagnosticEmitter { module.binary(BinaryOp.NeI8x16, leftExpr, rightExpr) ); } - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: { + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: { return module.unary(UnaryOp.EqzI32, module.ref_eq(leftExpr, rightExpr) ); } - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: { this.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, reportNode.range, @@ -4939,7 +4943,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4948,8 +4952,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.AddI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.AddI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.AddSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.AddSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.AddF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.AddF64, leftExpr, rightExpr); } @@ -4961,7 +4965,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4970,8 +4974,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.SubI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.SubI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.SubSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.SubSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.SubF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.SubF64, leftExpr, rightExpr); } @@ -4983,7 +4987,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4992,8 +4996,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.MulI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.MulI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.MulSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.MulSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.MulF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.MulF64, leftExpr, rightExpr); } @@ -5005,7 +5009,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits let module = this.module; switch (type.kind) { - case TypeKind.BOOL: { + case TypeKind.Bool: { return module.select( module.i32(1), module.binary(BinaryOp.EqI32, rightExpr, module.i32(0)), @@ -5049,7 +5053,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.i32PowInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5089,7 +5093,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.i64PowInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5097,8 +5101,8 @@ export class Compiler extends DiagnosticEmitter { } return this.makeCallDirect(instance, [ leftExpr, rightExpr ], reportNode); } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { let isWasm64 = this.options.isWasm64; if (this.options.willOptimize) { // Precompute power if LHS and RHS constants @@ -5139,7 +5143,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); instance = this.resolver.resolveFunction(prototype, null); if (isWasm64) { this.i64PowInstance = instance; @@ -5185,7 +5189,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let prototype = assert(namespaceMembers.get(CommonNames.pow)); - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.f32PowInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5227,7 +5231,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let prototype = assert(namespaceMembers.get(CommonNames.pow)); - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.f64PowInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5252,8 +5256,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.DivI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.DivI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.DivISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.DivISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -5262,7 +5266,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.DivU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.DivU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.DivUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.DivUSize, leftExpr, rightExpr); case TypeKind.F32: return module.binary(BinaryOp.DivF32, leftExpr, rightExpr); case TypeKind.F64: return module.binary(BinaryOp.DivF64, leftExpr, rightExpr); } @@ -5282,8 +5286,8 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.RemI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.RemI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.RemISize, leftExpr, rightExpr); - case TypeKind.BOOL: + case TypeKind.Isize: return module.binary(BinaryOp.RemISize, leftExpr, rightExpr); + case TypeKind.Bool: case TypeKind.U8: case TypeKind.U16: { leftExpr = this.ensureSmallIntegerWrap(leftExpr, type); @@ -5292,7 +5296,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U32: return module.binary(BinaryOp.RemU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.RemU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.RemUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.RemUSize, leftExpr, rightExpr); case TypeKind.F32: { let instance = this.f32ModInstance; if (!instance) { @@ -5313,7 +5317,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let prototype = assert(namespaceMembers.get(CommonNames.mod)); - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.f32ModInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5341,7 +5345,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let prototype = assert(namespaceMembers.get(CommonNames.mod)); - assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(prototype.kind == ElementKind.FunctionPrototype); this.f64ModInstance = instance = this.resolver.resolveFunction(prototype, null); } if (!instance || !this.compileFunction(instance)) { @@ -5358,7 +5362,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits on the RHS, but only for types smaller than 5 bits var module = this.module; switch (type.kind) { - case TypeKind.BOOL: return leftExpr; + case TypeKind.Bool: return leftExpr; case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5378,8 +5382,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.ShlI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.ShlI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.ShlSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.ShlSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5390,7 +5394,7 @@ export class Compiler extends DiagnosticEmitter { // and signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: return leftExpr; + case TypeKind.Bool: return leftExpr; case TypeKind.I8: case TypeKind.I16: { // leftExpr >> (rightExpr & (7|15)) @@ -5419,10 +5423,10 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I32: return module.binary(BinaryOp.ShrI32, leftExpr, rightExpr); case TypeKind.I64: return module.binary(BinaryOp.ShrI64, leftExpr, rightExpr); - case TypeKind.ISIZE: return module.binary(BinaryOp.ShrISize, leftExpr, rightExpr); + case TypeKind.Isize: return module.binary(BinaryOp.ShrISize, leftExpr, rightExpr); case TypeKind.U32: return module.binary(BinaryOp.ShrU32, leftExpr, rightExpr); case TypeKind.U64: return module.binary(BinaryOp.ShrU64, leftExpr, rightExpr); - case TypeKind.USIZE: return module.binary(BinaryOp.ShrUSize, leftExpr, rightExpr); + case TypeKind.Usize: return module.binary(BinaryOp.ShrUSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5432,7 +5436,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits on the LHS, but on the RHS only for types smaller than 5 bits var module = this.module; switch (type.kind) { - case TypeKind.BOOL: return leftExpr; + case TypeKind.Bool: return leftExpr; case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5452,8 +5456,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.ShrU32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.ShrU64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.ShrUSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.ShrUSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5463,7 +5467,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -5472,8 +5476,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.AndI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.AndI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.AndSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.AndSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5483,7 +5487,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5492,8 +5496,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.OrI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.OrI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.OrSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.OrSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5503,7 +5507,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness var module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5512,8 +5516,8 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: return module.binary(BinaryOp.XorI32, leftExpr, rightExpr); case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.XorI64, leftExpr, rightExpr); - case TypeKind.ISIZE: - case TypeKind.USIZE: return module.binary(BinaryOp.XorSize, leftExpr, rightExpr); + case TypeKind.Isize: + case TypeKind.Usize: return module.binary(BinaryOp.XorSize, leftExpr, rightExpr); } assert(false); return module.unreachable(); @@ -5541,14 +5545,14 @@ export class Compiler extends DiagnosticEmitter { var rightType: Type; var signature = operatorInstance.signature; var parameterTypes = signature.parameterTypes; - if (operatorInstance.is(CommonFlags.INSTANCE)) { + if (operatorInstance.is(CommonFlags.Instance)) { leftExpr = this.convertExpression(leftExpr, leftType, assert(signature.thisType), false, left); rightType = parameterTypes[0]; } else { leftExpr = this.convertExpression(leftExpr, leftType, parameterTypes[0], false, left); rightType = parameterTypes[1]; } - var rightExpr = this.compileExpression(right, rightType, Constraints.CONV_IMPLICIT); + var rightExpr = this.compileExpression(right, rightType, Constraints.ConvImplicit); return this.makeCallDirect(operatorInstance, [ leftExpr, rightExpr ], reportNode); } @@ -5568,13 +5572,13 @@ export class Compiler extends DiagnosticEmitter { // to compile just the value, we need to know the target's type var targetType: Type; switch (target.kind) { - case ElementKind.GLOBAL: { + case ElementKind.Global: { // not yet compiled if a static field compiled as a global if (!this.compileGlobal(target)) return this.module.unreachable(); // reports // fall-through } - case ElementKind.LOCAL: - case ElementKind.FIELD: { + case ElementKind.Local: + case ElementKind.Field: { if (this.pendingElements.has(target)) { this.error( DiagnosticCode.Variable_0_used_before_its_declaration, @@ -5584,17 +5588,17 @@ export class Compiler extends DiagnosticEmitter { return this.module.unreachable(); } targetType = (target).type; - if (target.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression); + if (target.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(expression); break; } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let propertyPrototype = target; let propertyInstance = resolver.resolveProperty(propertyPrototype); if (!propertyInstance) return this.module.unreachable(); target = propertyInstance; // fall-through } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let propertyInstance = target; let setterInstance = propertyInstance.setterInstance; if (!setterInstance) { @@ -5606,14 +5610,14 @@ export class Compiler extends DiagnosticEmitter { } assert(setterInstance.signature.parameterTypes.length == 1); // parser must guarantee this targetType = setterInstance.signature.parameterTypes[0]; - if (setterInstance.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression); + if (setterInstance.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(expression); break; } - case ElementKind.INDEXSIGNATURE: { + case ElementKind.IndexSignature: { let parent = (target).parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; - let isUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT); + let isUnchecked = flow.is(FlowFlags.UncheckedContext); let indexedSet = classInstance.lookupOverload(OperatorKind.INDEXED_SET, isUnchecked); if (!indexedSet) { let indexedGet = classInstance.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); @@ -5635,7 +5639,7 @@ export class Compiler extends DiagnosticEmitter { assert(parameterTypes.length == 2); // parser must guarantee this targetType = parameterTypes[1]; // 2nd parameter is the element - if (indexedSet.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression); + if (indexedSet.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(expression); if (!isUnchecked && this.options.pedantic) { this.pedantic( DiagnosticCode.Indexed_access_may_involve_bounds_checking, @@ -5689,9 +5693,9 @@ export class Compiler extends DiagnosticEmitter { var flow = this.currentFlow; switch (target.kind) { - case ElementKind.LOCAL: { + case ElementKind.Local: { let local = target; - if (flow.isLocalFlag(local.index, LocalFlags.CONSTANT, true)) { + if (flow.isLocalFlag(local.index, LocalFlags.Constant, true)) { this.error( DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, valueExpression.range, target.internalName @@ -5701,10 +5705,10 @@ export class Compiler extends DiagnosticEmitter { } return this.makeLocalAssignment(local, valueExpr, valueType, tee); } - case ElementKind.GLOBAL: { + case ElementKind.Global: { let global = target; if (!this.compileGlobal(global)) return module.unreachable(); - if (target.isAny(CommonFlags.CONST | CommonFlags.READONLY)) { + if (target.isAny(CommonFlags.Const | CommonFlags.Readonly)) { this.error( DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, valueExpression.range, @@ -5715,13 +5719,13 @@ export class Compiler extends DiagnosticEmitter { } return this.makeGlobalAssignment(global, valueExpr, valueType, tee); } - case ElementKind.FIELD: { + case ElementKind.Field: { let fieldInstance = target; let initializerNode = fieldInstance.initializerNode; - let isConstructor = flow.actualFunction.is(CommonFlags.CONSTRUCTOR); + let isConstructor = flow.actualFunction.is(CommonFlags.Constructor); // Cannot assign to readonly fields except in constructors if there's no initializer - if (fieldInstance.is(CommonFlags.READONLY)) { + if (fieldInstance.is(CommonFlags.Readonly)) { if (!isConstructor || initializerNode) { this.error( DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, @@ -5733,24 +5737,24 @@ export class Compiler extends DiagnosticEmitter { // Mark initialized fields in constructors thisExpression = assert(thisExpression); - if (isConstructor && thisExpression.kind == NodeKind.THIS) { - flow.setThisFieldFlag(fieldInstance, FieldFlags.INITIALIZED); + if (isConstructor && thisExpression.kind == NodeKind.This) { + flow.setThisFieldFlag(fieldInstance, FieldFlags.Initialized); } let fieldParent = fieldInstance.parent; - assert(fieldParent.kind == ElementKind.CLASS); + assert(fieldParent.kind == ElementKind.Class); return this.makeFieldAssignment(fieldInstance, valueExpr, valueType, this.compileExpression( thisExpression, (fieldParent).type, - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ), tee ); } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let propertyInstance = target; let setterInstance = propertyInstance.setterInstance; if (!setterInstance) { @@ -5761,12 +5765,12 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } assert(setterInstance.signature.parameterTypes.length == 1); - if (propertyInstance.is(CommonFlags.INSTANCE)) { + if (propertyInstance.is(CommonFlags.Instance)) { let thisType = assert(setterInstance.signature.thisType); let thisExpr = this.compileExpression( assert(thisExpression), thisType, - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); if (!tee) return this.makeCallDirect(setterInstance, [ thisExpr, valueExpr ], valueExpression); let getterInstance = assert((target).getterInstance); @@ -5794,13 +5798,13 @@ export class Compiler extends DiagnosticEmitter { ], getterInstance.signature.returnType.toRef()); } } - case ElementKind.INDEXSIGNATURE: { + case ElementKind.IndexSignature: { let indexSignature = target; let parent = indexSignature.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; - assert(classInstance.kind == ElementKind.CLASS); - let isUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT); + assert(classInstance.kind == ElementKind.Class); + let isUnchecked = flow.is(FlowFlags.UncheckedContext); let getterInstance = classInstance.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); if (!getterInstance) { this.error( @@ -5823,7 +5827,7 @@ export class Compiler extends DiagnosticEmitter { let thisExpr = this.compileExpression( assert(thisExpression), thisType, - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); let setterIndexType = setterInstance.signature.parameterTypes[0]; let getterIndexType = getterInstance.signature.parameterTypes[0]; @@ -5837,7 +5841,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = tee ? getterInstance.signature.returnType : Type.void; return module.unreachable(); } - let elementExpr = this.compileExpression(assert(indexExpression), setterIndexType, Constraints.CONV_IMPLICIT); + let elementExpr = this.compileExpression(assert(indexExpression), setterIndexType, Constraints.ConvImplicit); let elementType = this.currentType; if (tee) { let tempTarget = flow.getTempLocal(thisType); @@ -5893,13 +5897,13 @@ export class Compiler extends DiagnosticEmitter { var localIndex = local.index; if (type.isNullableReference) { - if (!valueType.isNullableReference || flow.isNonnull(valueExpr, type)) flow.setLocalFlag(localIndex, LocalFlags.NONNULL); - else flow.unsetLocalFlag(localIndex, LocalFlags.NONNULL); + if (!valueType.isNullableReference || flow.isNonnull(valueExpr, type)) flow.setLocalFlag(localIndex, LocalFlags.NonNull); + else flow.unsetLocalFlag(localIndex, LocalFlags.NonNull); } - flow.setLocalFlag(localIndex, LocalFlags.INITIALIZED); + flow.setLocalFlag(localIndex, LocalFlags.Initialized); if (type.isShortIntegerValue) { - if (!flow.canOverflow(valueExpr, type)) flow.setLocalFlag(localIndex, LocalFlags.WRAPPED); - else flow.unsetLocalFlag(localIndex, LocalFlags.WRAPPED); + if (!flow.canOverflow(valueExpr, type)) flow.setLocalFlag(localIndex, LocalFlags.Wrapped); + else flow.unsetLocalFlag(localIndex, LocalFlags.Wrapped); } if (tee) { // local = value this.currentType = type; @@ -5958,11 +5962,11 @@ export class Compiler extends DiagnosticEmitter { var flow = this.currentFlow; var fieldType = field.type; var fieldTypeRef = fieldType.toRef(); - assert(field.parent.kind == ElementKind.CLASS); + assert(field.parent.kind == ElementKind.Class); var thisType = (field.parent).type; - if (!field.is(CommonFlags.COMPILED)) { - field.set(CommonFlags.COMPILED); + if (!field.is(CommonFlags.Compiled)) { + field.set(CommonFlags.Compiled); let typeNode = field.typeNode; if (typeNode) this.checkTypeSupported(field.type, typeNode); } @@ -5999,10 +6003,10 @@ export class Compiler extends DiagnosticEmitter { var flow = this.currentFlow; // handle call to super - if (expression.expression.kind == NodeKind.SUPER) { + if (expression.expression.kind == NodeKind.Super) { let flow = this.currentFlow; let actualFunction = flow.actualFunction; - if (!actualFunction.is(CommonFlags.CONSTRUCTOR)) { + if (!actualFunction.is(CommonFlags.Constructor)) { this.error( DiagnosticCode.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors, expression.range @@ -6011,7 +6015,7 @@ export class Compiler extends DiagnosticEmitter { } let parent = assert(actualFunction.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let baseClassInstance = classInstance.base; if (!baseClassInstance) { @@ -6035,8 +6039,8 @@ export class Compiler extends DiagnosticEmitter { // check that super had been called before accessing `this` if (flow.isAny( - FlowFlags.ACCESSES_THIS | - FlowFlags.CONDITIONALLY_ACCESSES_THIS + FlowFlags.AccessesThis | + FlowFlags.ConditionallyAccessesThis )) { this.error( DiagnosticCode._super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class, @@ -6044,7 +6048,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - flow.set(FlowFlags.ACCESSES_THIS | FlowFlags.CALLS_SUPER); + flow.set(FlowFlags.AccessesThis | FlowFlags.CallsSuper); this.currentType = Type.void; return module.local_set(thisLocal.index, superCall, classInstance.type.isManaged); } @@ -6059,9 +6063,9 @@ export class Compiler extends DiagnosticEmitter { switch (target.kind) { // direct call: concrete function - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let functionPrototype = target; - if (functionPrototype.hasDecorator(DecoratorFlags.BUILTIN)) { + if (functionPrototype.hasDecorator(DecoratorFlags.Builtin)) { // builtins handle present respectively omitted type arguments on their own return this.compileCallExpressionBuiltin(functionPrototype, expression, contextualType); } @@ -6070,14 +6074,14 @@ export class Compiler extends DiagnosticEmitter { target = functionInstance; // fall-through } - case ElementKind.FUNCTION: { + case ElementKind.Function: { let functionInstance = target; let thisArg: ExpressionRef = 0; - if (functionInstance.is(CommonFlags.INSTANCE)) { + if (functionInstance.is(CommonFlags.Instance)) { thisArg = this.compileExpression( assert(thisExpression), assert(functionInstance.signature.thisType), - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); } return this.compileCallDirect( @@ -6090,11 +6094,11 @@ export class Compiler extends DiagnosticEmitter { } // indirect call: first-class function (non-generic, can't be inlined) - case ElementKind.LOCAL: { + case ElementKind.Local: { let local = target; signature = local.type.signatureReference; if (signature) { - if (local.is(CommonFlags.INLINED)) { + if (local.is(CommonFlags.Inlined)) { let inlinedValue = local.constantIntegerValue; if (this.options.isWasm64) { functionArg = module.i64(i64_low(inlinedValue), i64_high(inlinedValue)); @@ -6113,7 +6117,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - case ElementKind.GLOBAL: { + case ElementKind.Global: { let global = target; signature = global.type.signatureReference; if (signature) { @@ -6126,19 +6130,19 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - case ElementKind.FIELD: { + case ElementKind.Field: { let fieldInstance = target; let fieldType = fieldInstance.type; signature = fieldType.signatureReference; if (signature) { let fieldParent = fieldInstance.parent; - assert(fieldParent.kind == ElementKind.CLASS); + assert(fieldParent.kind == ElementKind.Class); let usizeType = this.options.usizeType; functionArg = module.load(usizeType.byteSize, false, this.compileExpression( assert(thisExpression), (fieldParent).type, - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ), usizeType.toRef(), fieldInstance.memoryOffset @@ -6152,13 +6156,13 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let propertyInstance = this.resolver.resolveProperty(target); if (!propertyInstance) return module.unreachable(); target = propertyInstance; // fall-through } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let propertyInstance = target; let getterInstance = propertyInstance.getterInstance; let type = assert(this.resolver.getTypeOfElement(target)); @@ -6172,11 +6176,11 @@ export class Compiler extends DiagnosticEmitter { } let thisArg: ExpressionRef = 0; - if (propertyInstance.is(CommonFlags.INSTANCE)) { + if (propertyInstance.is(CommonFlags.Instance)) { thisArg = this.compileExpression( assert(thisExpression), assert(getterInstance.signature.thisType), - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); } functionArg = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); @@ -6190,13 +6194,13 @@ export class Compiler extends DiagnosticEmitter { } break; } - case ElementKind.CLASS: { + case ElementKind.Class: { let classInstance = target; let typeArguments = classInstance.getTypeArgumentsTo(this.program.functionPrototype); if (typeArguments && typeArguments.length > 0) { let ftype = typeArguments[0]; signature = ftype.getSignature(); - functionArg = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); + functionArg = this.compileExpression(expression.expression, ftype, Constraints.ConvImplicit); break; } // fall-through @@ -6242,7 +6246,7 @@ export class Compiler extends DiagnosticEmitter { /** Contextual type indicating the return type the caller expects, if any. */ contextualType: Type, /** Constraints indicating contextual conditions. */ - constraints: Constraints = Constraints.NONE + constraints: Constraints = Constraints.None ): ExpressionRef { // Desugaring like this can happen many times. Let's cache the intermediate allocation. var call = this._reusableCallExpression; @@ -6263,7 +6267,7 @@ export class Compiler extends DiagnosticEmitter { expression: CallExpression, contextualType: Type ): ExpressionRef { - if (prototype.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression); + if (prototype.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(expression); var typeArguments: Type[] | null = null; @@ -6272,7 +6276,7 @@ export class Compiler extends DiagnosticEmitter { var typeParameterNodes = prototype.typeParameterNodes; var typeArgumentNodes = expression.typeArguments; if (expression.typeArguments) { - if (!prototype.is(CommonFlags.GENERIC)) { + if (!prototype.is(CommonFlags.Generic)) { this.error( DiagnosticCode.Type_0_is_not_generic, expression.range, prototype.internalName @@ -6292,7 +6296,7 @@ export class Compiler extends DiagnosticEmitter { prototype, typeArguments, expression.args, - callee.kind == NodeKind.PROPERTYACCESS + callee.kind == NodeKind.PropertyAccess ? (callee).expression : null, contextualType, @@ -6307,7 +6311,7 @@ export class Compiler extends DiagnosticEmitter { } // class builtins var parent = prototype.parent; - if (parent.kind == ElementKind.CLASS) { + if (parent.kind == ElementKind.Class) { let classPrototype = (parent).prototype; if (classPrototype == this.program.functionPrototype) { let methodName = prototype.name; @@ -6402,7 +6406,7 @@ export class Compiler extends DiagnosticEmitter { argumentExpressions: Expression[], reportNode: Node, thisArg: ExpressionRef = 0, - constraints: Constraints = Constraints.NONE + constraints: Constraints = Constraints.None ): ExpressionRef { var numArguments = argumentExpressions.length; var signature = instance.signature; @@ -6415,19 +6419,19 @@ export class Compiler extends DiagnosticEmitter { this.currentType = signature.returnType; return this.module.unreachable(); } - if (instance.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(reportNode); + if (instance.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(reportNode); // handle call on `this` in constructors let actualFunction = this.currentFlow.actualFunction; - if (actualFunction.is(CommonFlags.CONSTRUCTOR) && reportNode.isAccessOnThis) { + if (actualFunction.is(CommonFlags.Constructor) && reportNode.isAccessOnThis) { let parent = actualFunction.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); this.checkFieldInitialization(parent, reportNode); } // Inline if explicitly requested - if (instance.hasDecorator(DecoratorFlags.INLINE) && (!instance.is(CommonFlags.VIRTUAL) || reportNode.isAccessOnSuper)) { - assert(!instance.is(CommonFlags.STUB)); // doesn't make sense + if (instance.hasDecorator(DecoratorFlags.Inline) && (!instance.is(CommonFlags.Virtual) || reportNode.isAccessOnSuper)) { + assert(!instance.is(CommonFlags.Stub)); // doesn't make sense let inlineStack = this.inlineStack; if (inlineStack.includes(instance)) { this.warning( @@ -6441,10 +6445,10 @@ export class Compiler extends DiagnosticEmitter { // compile argument expressions let args = new Array(numArguments); for (let i = 0; i < numArguments; ++i) { - args[i] = this.compileExpression(argumentExpressions[i], parameterTypes[i], Constraints.CONV_IMPLICIT); + args[i] = this.compileExpression(argumentExpressions[i], parameterTypes[i], Constraints.ConvImplicit); } // make the inlined call - let expr = this.makeCallInline(instance, args, thisArg, (constraints & Constraints.WILL_DROP) != 0); + let expr = this.makeCallInline(instance, args, thisArg, (constraints & Constraints.WillDrop) != 0); inlineStack.pop(); return expr; } @@ -6461,11 +6465,11 @@ export class Compiler extends DiagnosticEmitter { var parameterTypes = signature.parameterTypes; for (let i = 0; i < numArguments; ++i, ++index) { let paramType = parameterTypes[i]; - let paramExpr = this.compileExpression(argumentExpressions[i], paramType, Constraints.CONV_IMPLICIT); + let paramExpr = this.compileExpression(argumentExpressions[i], paramType, Constraints.ConvImplicit); operands[index] = paramExpr; } assert(index == numArgumentsInclThis); - return this.makeCallDirect(instance, operands, reportNode, (constraints & Constraints.WILL_DROP) != 0); + return this.makeCallDirect(instance, operands, reportNode, (constraints & Constraints.WillDrop) != 0); } makeCallInline( @@ -6498,15 +6502,15 @@ export class Compiler extends DiagnosticEmitter { let argumentLocal = flow.addScopedLocal(instance.getParameterName(i), paramType, usedLocals); findUsedLocals(paramExpr, usedLocals); // inlining is aware of wrap/nonnull states: - if (!previousFlow.canOverflow(paramExpr, paramType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.WRAPPED); - if (flow.isNonnull(paramExpr, paramType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.NONNULL); + if (!previousFlow.canOverflow(paramExpr, paramType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.Wrapped); + if (flow.isNonnull(paramExpr, paramType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.NonNull); body.unshift( module.local_set(argumentLocal.index, paramExpr, paramType.isManaged) ); } if (thisArg) { let parent = assert(instance.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let thisType = assert(instance.signature.thisType); let thisLocal = flow.addScopedLocal(CommonNames.this_, thisType, usedLocals); @@ -6522,21 +6526,21 @@ export class Compiler extends DiagnosticEmitter { // Compile omitted arguments with final argument locals blocked. Doesn't need to take care of // side-effects within earlier expressions because these already happened on set. this.currentFlow = flow; - var isConstructor = instance.is(CommonFlags.CONSTRUCTOR); - if (isConstructor) flow.set(FlowFlags.CTORPARAM_CONTEXT); + var isConstructor = instance.is(CommonFlags.Constructor); + if (isConstructor) flow.set(FlowFlags.CtorParamContext); for (let i = numArguments; i < numParameters; ++i) { let initType = parameterTypes[i]; let initExpr = this.compileExpression( assert(instance.prototype.functionTypeNode.parameters[i].initializer), initType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); let argumentLocal = flow.addScopedLocal(instance.getParameterName(i), initType); body.push( this.makeLocalAssignment(argumentLocal, initExpr, initType, false) ); } - flow.unset(FlowFlags.CTORPARAM_CONTEXT); + flow.unset(FlowFlags.CtorParamContext); // Compile the called function's body in the scope of the inlined flow this.compileFunctionBody(instance, body); @@ -6544,7 +6548,7 @@ export class Compiler extends DiagnosticEmitter { // If a constructor, perform field init checks on its flow directly if (isConstructor) { let parent = instance.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); this.checkFieldInitializationInFlow(parent, flow); } @@ -6582,7 +6586,7 @@ export class Compiler extends DiagnosticEmitter { var originalParameterTypes = originalSignature.parameterTypes; var originalParameterDeclarations = original.prototype.functionTypeNode.parameters; var returnType = originalSignature.returnType; - var isInstance = original.is(CommonFlags.INSTANCE); + var isInstance = original.is(CommonFlags.Instance); // arguments excl. `this`, operands incl. `this` var minArguments = originalSignature.requiredParameters; @@ -6623,7 +6627,7 @@ export class Compiler extends DiagnosticEmitter { // accounting for additional locals and a proper `this` context. var previousFlow = this.currentFlow; var flow = stub.flow; - if (original.is(CommonFlags.CONSTRUCTOR)) flow.set(FlowFlags.CTORPARAM_CONTEXT); + if (original.is(CommonFlags.Constructor)) flow.set(FlowFlags.CtorParamContext); this.currentFlow = flow; // create a br_table switching over the number of optional parameters provided @@ -6658,7 +6662,7 @@ export class Compiler extends DiagnosticEmitter { initExpr = this.compileExpression( initializer, type, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); initExpr = module.local_set(operandIndex, initExpr, type.isManaged); } else { @@ -6693,7 +6697,7 @@ export class Compiler extends DiagnosticEmitter { typesToRefs(stub.additionalLocals), module.flatten(stmts, returnType.toRef()) ); - stub.set(CommonFlags.COMPILED); + stub.set(CommonFlags.Compiled); stub.finalize(module, funcRef); return stub; } @@ -6724,9 +6728,9 @@ export class Compiler extends DiagnosticEmitter { /** Finalizes the virtual stub of the specified function. */ private finalizeVirtualStub(instance: Function): void { var stub = this.ensureVirtualStub(instance); - if (stub.is(CommonFlags.COMPILED)) return; + if (stub.is(CommonFlags.Compiled)) return; - assert(instance.parent.kind == ElementKind.CLASS || instance.parent.kind == ElementKind.INTERFACE); + assert(instance.parent.kind == ElementKind.Class || instance.parent.kind == ElementKind.Interface); var module = this.module; var usizeType = this.options.usizeType; var sizeTypeRef = usizeType.toRef(); @@ -6754,7 +6758,7 @@ export class Compiler extends DiagnosticEmitter { if (overloadInstances) { for (let i = 0, k = overloadInstances.length; i < k; ++i) { let overloadInstance = overloadInstances[i]; - if (!overloadInstance.is(CommonFlags.COMPILED)) continue; // errored + if (!overloadInstance.is(CommonFlags.Compiled)) continue; // errored let overloadType = overloadInstance.type; let originalType = instance.type; if (!overloadType.isAssignableTo(originalType)) { @@ -6844,7 +6848,7 @@ export class Compiler extends DiagnosticEmitter { body ], returnType.toRef()) ); - stub.set(CommonFlags.COMPILED); + stub.set(CommonFlags.Compiled); } /** Marks managed call operands for the shadow stack. */ @@ -6887,9 +6891,9 @@ export class Compiler extends DiagnosticEmitter { reportNode: Node, immediatelyDropped: bool = false ): ExpressionRef { - if (instance.hasDecorator(DecoratorFlags.INLINE)) { - if (!instance.is(CommonFlags.VIRTUAL)) { - assert(!instance.is(CommonFlags.STUB)); // doesn't make sense + if (instance.hasDecorator(DecoratorFlags.Inline)) { + if (!instance.is(CommonFlags.Virtual)) { + assert(!instance.is(CommonFlags.Stub)); // doesn't make sense let inlineStack = this.inlineStack; if (inlineStack.includes(instance)) { this.warning( @@ -6899,7 +6903,7 @@ export class Compiler extends DiagnosticEmitter { } else { inlineStack.push(instance); let expr: ExpressionRef; - if (instance.is(CommonFlags.INSTANCE)) { + if (instance.is(CommonFlags.Instance)) { let theOperands = assert(operands); assert(theOperands.length); expr = this.makeCallInline(instance, theOperands.slice(1), theOperands[0], immediatelyDropped); @@ -6924,7 +6928,7 @@ export class Compiler extends DiagnosticEmitter { var parameterTypes = instance.signature.parameterTypes; var maxArguments = parameterTypes.length; var maxOperands = maxArguments; - if (instance.is(CommonFlags.INSTANCE)) { + if (instance.is(CommonFlags.Instance)) { ++minOperands; ++maxOperands; --numArguments; @@ -6950,18 +6954,18 @@ export class Compiler extends DiagnosticEmitter { operands.push(this.compileExpression( initializer, parameterTypes[i], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit )); continue; } - let resolved = this.resolver.lookupExpression(initializer, instance.flow, parameterTypes[i], ReportMode.SWALLOW); + let resolved = this.resolver.lookupExpression(initializer, instance.flow, parameterTypes[i], ReportMode.Swallow); if (resolved) { - if (resolved.kind == ElementKind.GLOBAL) { + if (resolved.kind == ElementKind.Global) { let global = resolved; if (this.compileGlobal(global)) { - if (global.is(CommonFlags.INLINED)) { + if (global.is(CommonFlags.Inlined)) { operands.push( - this.compileInlineConstant(global, parameterTypes[i], Constraints.CONV_IMPLICIT) + this.compileInlineConstant(global, parameterTypes[i], Constraints.ConvImplicit) ); } else { operands.push( @@ -6979,7 +6983,7 @@ export class Compiler extends DiagnosticEmitter { operands.push(this.makeZero(parameterTypes[i])); allOptionalsAreConstant = false; } - if (!allOptionalsAreConstant && !instance.is(CommonFlags.MODULE_IMPORT)) { + if (!allOptionalsAreConstant && !instance.is(CommonFlags.ModuleImport)) { let original = instance; instance = this.ensureVarargsStub(instance); if (!this.compileFunction(instance)) return module.unreachable(); @@ -7007,7 +7011,7 @@ export class Compiler extends DiagnosticEmitter { } // Call the virtual stub with the vtable if the function has overloads - if (instance.is(CommonFlags.VIRTUAL) && !reportNode.isAccessOnSuper) { + if (instance.is(CommonFlags.Virtual) && !reportNode.isAccessOnSuper) { instance = this.ensureVirtualStub(instance); } @@ -7047,7 +7051,7 @@ export class Compiler extends DiagnosticEmitter { var parameterTypes = signature.parameterTypes; for (let i = 0; i < numArguments; ++i, ++index) { operands[index] = this.compileExpression(argumentExpressions[i], parameterTypes[i], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } assert(index == numArgumentsInclThis); @@ -7132,7 +7136,7 @@ export class Compiler extends DiagnosticEmitter { var exprs = new Array(numExpressions--); for (let i = 0; i < numExpressions; ++i) { exprs[i] = this.compileExpression(expressions[i], Type.void, // drop all except last - Constraints.CONV_IMPLICIT | Constraints.WILL_DROP + Constraints.ConvImplicit | Constraints.WillDrop ); } exprs[numExpressions] = this.compileExpression(expressions[numExpressions], contextualType, constraints); @@ -7150,12 +7154,12 @@ export class Compiler extends DiagnosticEmitter { if (targetType) { let classReference = targetType.getClassOrWrapper(this.program); if (classReference) { - let isUnchecked = this.currentFlow.is(FlowFlags.UNCHECKED_CONTEXT); + let isUnchecked = this.currentFlow.is(FlowFlags.UncheckedContext); let indexedGet = classReference.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); if (indexedGet) { let thisType = assert(indexedGet.signature.thisType); let thisArg = this.compileExpression(targetExpression, thisType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); if (!isUnchecked && this.options.pedantic) { this.pedantic( @@ -7193,7 +7197,7 @@ export class Compiler extends DiagnosticEmitter { : declaration.name.text, actualFunction, declaration, - DecoratorFlags.NONE + DecoratorFlags.None ); var instance: Function | null; var contextualTypeArguments = cloneMap(flow.contextualTypeArguments); @@ -7337,7 +7341,7 @@ export class Compiler extends DiagnosticEmitter { } else { let ftype = instance.type; let local = flow.addScopedLocal(instance.name, ftype); - flow.setLocalFlag(local.index, LocalFlags.CONSTANT); + flow.setLocalFlag(local.index, LocalFlags.Constant); expr = module.local_tee(local.index, expr, ftype.isManaged); } } @@ -7351,7 +7355,7 @@ export class Compiler extends DiagnosticEmitter { var filesByName = this.program.filesByName; assert(filesByName.has(internalPath)); var enclosingFile = assert(filesByName.get(internalPath)); - if (!enclosingFile.is(CommonFlags.COMPILED)) { + if (!enclosingFile.is(CommonFlags.Compiled)) { this.compileFileByPath(internalPath, expression); } } @@ -7367,7 +7371,7 @@ export class Compiler extends DiagnosticEmitter { // check special keywords first switch (expression.kind) { - case NodeKind.NULL: { + case NodeKind.Null: { let options = this.options; if (contextualType.isReference) { let classReference = contextualType.getClass(); @@ -7391,15 +7395,15 @@ export class Compiler extends DiagnosticEmitter { ? module.i64(0) : module.i32(0); } - case NodeKind.TRUE: { + case NodeKind.True: { this.currentType = Type.bool; return module.i32(1); } - case NodeKind.FALSE: { + case NodeKind.False: { this.currentType = Type.bool; return module.i32(0); } - case NodeKind.THIS: { + case NodeKind.This: { let thisType = actualFunction.signature.thisType; if (!thisType) { this.error( @@ -7409,32 +7413,32 @@ export class Compiler extends DiagnosticEmitter { this.currentType = this.options.usizeType; return module.unreachable(); } - if (actualFunction.is(CommonFlags.CONSTRUCTOR)) { - if (flow.is(FlowFlags.CTORPARAM_CONTEXT)) { + if (actualFunction.is(CommonFlags.Constructor)) { + if (flow.is(FlowFlags.CtorParamContext)) { this.error( DiagnosticCode._this_cannot_be_referenced_in_constructor_arguments, expression.range ); } - if (!(constraints & Constraints.IS_THIS)) { + if (!(constraints & Constraints.IsThis)) { let parent = actualFunction.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); this.checkFieldInitialization(parent, expression); } } let thisLocal = assert(flow.lookupLocal(CommonNames.this_)); - flow.set(FlowFlags.ACCESSES_THIS); + flow.set(FlowFlags.AccessesThis); this.currentType = thisType; return module.local_get(thisLocal.index, thisType.toRef()); } - case NodeKind.SUPER: { - if (actualFunction.is(CommonFlags.CONSTRUCTOR)) { - if (flow.is(FlowFlags.CTORPARAM_CONTEXT)) { + case NodeKind.Super: { + if (actualFunction.is(CommonFlags.Constructor)) { + if (flow.is(FlowFlags.CtorParamContext)) { this.error( DiagnosticCode._super_cannot_be_referenced_in_constructor_arguments, expression.range ); - } else if (!flow.is(FlowFlags.CALLS_SUPER)) { + } else if (!flow.is(FlowFlags.CallsSuper)) { // TS1034 in the parser effectively limits this to property accesses this.error( DiagnosticCode._super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class, @@ -7453,9 +7457,9 @@ export class Compiler extends DiagnosticEmitter { } } } - if (actualFunction.is(CommonFlags.INSTANCE)) { + if (actualFunction.is(CommonFlags.Instance)) { let parent = assert(actualFunction.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let baseClassInstance = classInstance.base; if (baseClassInstance) { @@ -7490,7 +7494,7 @@ export class Compiler extends DiagnosticEmitter { } switch (target.kind) { - case ElementKind.LOCAL: { + case ElementKind.Local: { let local = target; let localType = local.type; assert(localType != Type.void); @@ -7503,12 +7507,12 @@ export class Compiler extends DiagnosticEmitter { this.currentType = localType; return module.unreachable(); } - if (local.is(CommonFlags.INLINED)) { + if (local.is(CommonFlags.Inlined)) { return this.compileInlineConstant(local, contextualType, constraints); } let localIndex = local.index; assert(localIndex >= 0); - if (localType.isNullableReference && flow.isLocalFlag(localIndex, LocalFlags.NONNULL, false)) { + if (localType.isNullableReference && flow.isLocalFlag(localIndex, LocalFlags.NonNull, false)) { localType = localType.nonNullableType; } this.currentType = localType; @@ -7524,7 +7528,7 @@ export class Compiler extends DiagnosticEmitter { } return module.local_get(localIndex, localType.toRef()); } - case ElementKind.GLOBAL: { + case ElementKind.Global: { let global = target; if (!this.compileGlobal(global)) { // reports; not yet compiled if a static field return module.unreachable(); @@ -7540,15 +7544,15 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } assert(globalType != Type.void); - if (global.is(CommonFlags.INLINED)) { + if (global.is(CommonFlags.Inlined)) { return this.compileInlineConstant(global, contextualType, constraints); } this.currentType = globalType; return module.global_get(global.internalName, globalType.toRef()); } - case ElementKind.ENUMVALUE: { // here: if referenced from within the same enum + case ElementKind.EnumValue: { // here: if referenced from within the same enum let enumValue = target; - if (!target.is(CommonFlags.COMPILED)) { + if (!target.is(CommonFlags.Compiled)) { this.error( DiagnosticCode.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums, expression.range @@ -7557,13 +7561,13 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } this.currentType = Type.i32; - if (enumValue.is(CommonFlags.INLINED)) { - assert(enumValue.constantValueKind == ConstantValueKind.INTEGER); + if (enumValue.is(CommonFlags.Inlined)) { + assert(enumValue.constantValueKind == ConstantValueKind.Integer); return module.i32(i64_low(enumValue.constantIntegerValue)); } return module.global_get(enumValue.internalName, TypeRef.I32); } - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let functionPrototype = target; let typeParameterNodes = functionPrototype.typeParameterNodes; @@ -7581,7 +7585,7 @@ export class Compiler extends DiagnosticEmitter { cloneMap(flow.contextualTypeArguments) ); if (!functionInstance || !this.compileFunction(functionInstance)) return module.unreachable(); - if (functionInstance.hasDecorator(DecoratorFlags.BUILTIN)) { + if (functionInstance.hasDecorator(DecoratorFlags.Builtin)) { this.error( DiagnosticCode.Not_implemented_0, expression.range, "First-class built-ins" @@ -7616,13 +7620,13 @@ export class Compiler extends DiagnosticEmitter { var isType = expression.isType; // Mimic `instanceof CLASS` - if (isType.kind == NodeKind.NAMEDTYPE) { + if (isType.kind == NodeKind.NamedType) { let namedType = isType; if (!(namedType.isNullable || namedType.hasTypeArguments)) { - let element = this.resolver.resolveTypeName(namedType.name, flow.actualFunction, ReportMode.SWALLOW); - if (element && element.kind == ElementKind.CLASS_PROTOTYPE) { + let element = this.resolver.resolveTypeName(namedType.name, flow.actualFunction, ReportMode.Swallow); + if (element && element.kind == ElementKind.ClassPrototype) { let prototype = element; - if (prototype.is(CommonFlags.GENERIC)) { + if (prototype.is(CommonFlags.Generic)) { return this.makeInstanceofClass(expression, prototype); } } @@ -7806,7 +7810,7 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { var module = this.module; switch (expression.literalKind) { - case LiteralKind.ARRAY: { + case LiteralKind.Array: { assert(!implicitlyNegate); return this.compileArrayLiteral( expression, @@ -7814,7 +7818,7 @@ export class Compiler extends DiagnosticEmitter { constraints ); } - case LiteralKind.FLOAT: { + case LiteralKind.Float: { let floatValue = (expression).value; if (implicitlyNegate) { floatValue = -floatValue; @@ -7825,7 +7829,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.f64; return module.f64(floatValue); } - case LiteralKind.INTEGER: { + case LiteralKind.Integer: { let expr = expression; let type = this.resolver.determineIntegerLiteralType(expr, implicitlyNegate, contextualType); this.currentType = type; @@ -7839,28 +7843,28 @@ export class Compiler extends DiagnosticEmitter { } } switch (type.kind) { - case TypeKind.ISIZE: if (!this.options.isWasm64) return module.i32(i64_low(intValue)); + case TypeKind.Isize: if (!this.options.isWasm64) return module.i32(i64_low(intValue)); case TypeKind.I64: return module.i64(i64_low(intValue), i64_high(intValue)); - case TypeKind.USIZE: if (!this.options.isWasm64) return module.i32(i64_low(intValue)); + case TypeKind.Usize: if (!this.options.isWasm64) return module.i32(i64_low(intValue)); case TypeKind.U64: return module.i64(i64_low(intValue), i64_high(intValue)); case TypeKind.F32: return module.f32(sign * i64_to_f32(intValue)); case TypeKind.F64: return module.f64(sign * i64_to_f64(intValue)); default: return module.i32(i64_low(intValue)); } } - case LiteralKind.STRING: { + case LiteralKind.String: { assert(!implicitlyNegate); return this.compileStringLiteral(expression, constraints); } - case LiteralKind.TEMPLATE: { + case LiteralKind.Template: { assert(!implicitlyNegate); return this.compileTemplateLiteral(expression, constraints); } - case LiteralKind.OBJECT: { + case LiteralKind.Object: { assert(!implicitlyNegate); return this.compileObjectLiteral(expression, contextualType); } - case LiteralKind.REGEXP: { + case LiteralKind.RegExp: { this.error( DiagnosticCode.Not_implemented_0, expression.range, @@ -8009,21 +8013,21 @@ export class Compiler extends DiagnosticEmitter { // to avoid generating unnecessary static data that is not explicitly signaled to be used. var tsaArrayInstance = this.program.templateStringsArrayInstance; var arrayInstance = tsaArrayInstance; - var target = this.resolver.lookupExpression(tag, this.currentFlow, Type.auto, ReportMode.SWALLOW); + var target = this.resolver.lookupExpression(tag, this.currentFlow, Type.auto, ReportMode.Swallow); if (target) { switch (target.kind) { - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let instance = this.resolver.resolveFunction( target, null, new Map(), - ReportMode.SWALLOW + ReportMode.Swallow ); if (!instance) break; target = instance; // fall-through } - case ElementKind.FUNCTION: { + case ElementKind.Function: { let instance = target; let parameterTypes = instance.signature.parameterTypes; if (parameterTypes.length) { @@ -8103,7 +8107,7 @@ export class Compiler extends DiagnosticEmitter { // handle normal arrays var element = this.resolver.lookupExpression(expression, flow, this.currentType); if (!element) return module.unreachable(); - assert(element.kind == ElementKind.CLASS); + assert(element.kind == ElementKind.Class); var arrayInstance = element; var arrayType = arrayInstance.type; var elementType = arrayInstance.getTypeArgumentsTo(program.arrayPrototype)![0]; @@ -8120,8 +8124,8 @@ export class Compiler extends DiagnosticEmitter { var isStatic = !elementType.isExternalReference; for (let i = 0; i < length; ++i) { let elementExpression = expressions[i]; - if (elementExpression.kind != NodeKind.OMITTED) { - let expr = this.compileExpression(elementExpression, elementType, Constraints.CONV_IMPLICIT); + if (elementExpression.kind != NodeKind.Omitted) { + let expr = this.compileExpression(elementExpression, elementType, Constraints.ConvImplicit); if (getExpressionType(expr) != elementType.toRef()) { isStatic = false; } else { @@ -8149,7 +8153,7 @@ export class Compiler extends DiagnosticEmitter { // make both the buffer and array header static if assigned to a global. this can't be done // if inside of a function because each invocation must create a new array reference then. - if (constraints & Constraints.PREFER_STATIC) { + if (constraints & Constraints.PreferStatic) { let arraySegment = this.addStaticArrayHeader(elementType, bufferSegment); let arrayAddress = i64_add(arraySegment.offset, i64_new(totalOverhead)); this.currentType = arrayType; @@ -8187,7 +8191,7 @@ export class Compiler extends DiagnosticEmitter { ); // tempData = tempThis.dataStart var dataStartMember = assert(arrayInstance.getMember("dataStart")); - assert(dataStartMember.kind == ElementKind.FIELD); + assert(dataStartMember.kind == ElementKind.Field); stmts.push( module.local_set(tempDataStart.index, module.load(arrayType.byteSize, false, @@ -8276,8 +8280,8 @@ export class Compiler extends DiagnosticEmitter { var isStatic = !elementType.isExternalReference; for (let i = 0; i < length; ++i) { let elementExpression = expressions[i]; - if (elementExpression.kind != NodeKind.OMITTED) { - let expr = this.compileExpression(elementExpression, elementType, Constraints.CONV_IMPLICIT); + if (elementExpression.kind != NodeKind.Omitted) { + let expr = this.compileExpression(elementExpression, elementType, Constraints.ConvImplicit); let precomp = module.runExpression(expr, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { expr = precomp; @@ -8301,7 +8305,7 @@ export class Compiler extends DiagnosticEmitter { let bufferAddress = i64_add(bufferSegment.offset, i64_new(program.totalOverhead)); // return the static buffer directly if assigned to a global - if (constraints & Constraints.PREFER_STATIC) { + if (constraints & Constraints.PreferStatic) { let expr = this.options.isWasm64 ? module.i64(i64_low(bufferAddress), i64_high(bufferAddress)) : module.i32(i64_low(bufferAddress)); @@ -8385,14 +8389,14 @@ export class Compiler extends DiagnosticEmitter { } var classType = classReference.type; this.currentType = classType.nonNullableType; - if (classReference.kind == ElementKind.INTERFACE) { + if (classReference.kind == ElementKind.Interface) { this.error( DiagnosticCode.Not_implemented_0, expression.range, "Interface hidden classes" ); return module.unreachable(); } - if (classReference.is(CommonFlags.ABSTRACT)) { + if (classReference.is(CommonFlags.Abstract)) { this.error( DiagnosticCode.Cannot_create_an_instance_of_an_abstract_class, expression.range @@ -8412,7 +8416,7 @@ export class Compiler extends DiagnosticEmitter { var isManaged = classType.isManaged; if (!isManaged) { - this.checkUnsafe(expression, findDecorator(DecoratorKind.UNMANAGED, classReference.decoratorNodes)); + this.checkUnsafe(expression, findDecorator(DecoratorKind.Unmanaged, classReference.decoratorNodes)); } // check and compile field values @@ -8433,7 +8437,7 @@ export class Compiler extends DiagnosticEmitter { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberKey = _keys[i]; let member = assert(members.get(memberKey)); - if (member && member.kind == ElementKind.FIELD) { + if (member && member.kind == ElementKind.Field) { omittedFields.add(member); // incl. private/protected } } @@ -8443,7 +8447,7 @@ export class Compiler extends DiagnosticEmitter { for (let i = 0; i < numNames; ++i) { let memberName = names[i].text; let member = classReference.getMember(memberName); - if (!member || member.kind != ElementKind.FIELD) { + if (!member || member.kind != ElementKind.Field) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, names[i].range, memberName, classType.toString() @@ -8451,7 +8455,7 @@ export class Compiler extends DiagnosticEmitter { hasErrors = true; continue; } - if (member.is(CommonFlags.PRIVATE)) { + if (member.is(CommonFlags.Private)) { this.error( DiagnosticCode.Property_0_is_private_and_only_accessible_within_class_1, names[i].range, memberName, classType.toString() @@ -8459,7 +8463,7 @@ export class Compiler extends DiagnosticEmitter { hasErrors = true; continue; } - if (member.is(CommonFlags.PROTECTED)) { + if (member.is(CommonFlags.Protected)) { this.error( DiagnosticCode.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, names[i].range, memberName, classType.toString() @@ -8470,7 +8474,7 @@ export class Compiler extends DiagnosticEmitter { let fieldInstance = member; let fieldType = fieldInstance.type; - let expr = this.compileExpression(values[i], fieldType, Constraints.CONV_IMPLICIT); + let expr = this.compileExpression(values[i], fieldType, Constraints.ConvImplicit); exprs.push( module.call(fieldInstance.internalSetterName, [ module.local_get(tempLocal.index, classTypeRef), @@ -8507,17 +8511,17 @@ export class Compiler extends DiagnosticEmitter { switch (fieldType.kind) { // Number Types (and Number alias types) - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: + case TypeKind.Usize: case TypeKind.F32: case TypeKind.F64: { exprs.push( @@ -8548,7 +8552,7 @@ export class Compiler extends DiagnosticEmitter { // allocate a new instance first and assign 'this' to the temp. local exprs.unshift( module.local_set(tempLocal.index, - this.compileInstantiate(ctor, [], Constraints.NONE, expression), + this.compileInstantiate(ctor, [], Constraints.None, expression), classType.isManaged ) ); @@ -8574,14 +8578,14 @@ export class Compiler extends DiagnosticEmitter { // obtain the class being instantiated var target = this.resolver.resolveTypeName(expression.typeName, flow.actualFunction); if (!target) return module.unreachable(); - if (target.kind != ElementKind.CLASS_PROTOTYPE) { + if (target.kind != ElementKind.ClassPrototype) { this.error( DiagnosticCode.This_expression_is_not_constructable, expression.typeName.range ); return this.module.unreachable(); } - if (target.is(CommonFlags.ABSTRACT)) { + if (target.is(CommonFlags.Abstract)) { this.error( DiagnosticCode.Cannot_create_an_instance_of_an_abstract_class, expression.typeName.range @@ -8596,7 +8600,7 @@ export class Compiler extends DiagnosticEmitter { !typeArguments && (classReference = contextualType.classReference) && classReference.prototype == classPrototype && - classReference.is(CommonFlags.GENERIC) + classReference.is(CommonFlags.Generic) ) { // e.g. `arr: Array = new Array()` classInstance = this.resolver.resolveClass( @@ -8614,9 +8618,9 @@ export class Compiler extends DiagnosticEmitter { ); } if (!classInstance) return module.unreachable(); - if (contextualType == Type.void) constraints |= Constraints.WILL_DROP; + if (contextualType == Type.void) constraints |= Constraints.WillDrop; var ctor = this.ensureConstructor(classInstance, expression); - if (!ctor.hasDecorator(DecoratorFlags.INLINE)) { + if (!ctor.hasDecorator(DecoratorFlags.Inline)) { // Inlined ctors haven't been compiled yet and are checked upon inline // compilation of their body instead. this.checkFieldInitialization(classInstance, expression); @@ -8634,9 +8638,9 @@ export class Compiler extends DiagnosticEmitter { var instance = classInstance.constructorInstance; if (instance) { // shortcut if already compiled - if (instance.is(CommonFlags.COMPILED)) return instance; + if (instance.is(CommonFlags.Compiled)) return instance; // do not attempt to compile if inlined anyway - if (!instance.hasDecorator(DecoratorFlags.INLINE)) this.compileFunction(instance); + if (!instance.hasDecorator(DecoratorFlags.Inline)) this.compileFunction(instance); } else { // clone base constructor if a derived class. note that we cannot just // call the base ctor since the derived class may have additional fields. @@ -8666,7 +8670,7 @@ export class Compiler extends DiagnosticEmitter { CommonNames.constructor, classInstance, // bound this.program.makeNativeFunctionDeclaration(CommonNames.constructor, - CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR + CommonFlags.Instance | CommonFlags.Constructor ) ), null, @@ -8675,10 +8679,10 @@ export class Compiler extends DiagnosticEmitter { ); } - instance.set(CommonFlags.COMPILED); + instance.set(CommonFlags.Compiled); instance.prototype.setResolvedInstance("", instance); - if (classInstance.is(CommonFlags.MODULE_EXPORT)) { - instance.set(CommonFlags.MODULE_EXPORT); + if (classInstance.is(CommonFlags.ModuleExport)) { + instance.set(CommonFlags.ModuleExport); } classInstance.constructorInstance = instance; let members = classInstance.members; @@ -8762,10 +8766,10 @@ export class Compiler extends DiagnosticEmitter { if (members) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let element = _values[i]; - if (element.kind == ElementKind.FIELD && element.parent == classInstance) { + if (element.kind == ElementKind.Field && element.parent == classInstance) { let field = element; - if (!field.initializerNode && !flow.isThisFieldFlag(field, FieldFlags.INITIALIZED)) { - if (!field.is(CommonFlags.DEFINITELY_ASSIGNED)) { + if (!field.initializerNode && !flow.isThisFieldFlag(field, FieldFlags.Initialized)) { + if (!field.is(CommonFlags.DefinitelyAssigned)) { if (relatedNode) { this.errorRelated( DiagnosticCode.Property_0_has_no_initializer_and_is_not_assigned_in_the_constructor_before_this_is_used_or_returned, @@ -8781,7 +8785,7 @@ export class Compiler extends DiagnosticEmitter { ); } } - } else if (field.is(CommonFlags.DEFINITELY_ASSIGNED)) { + } else if (field.is(CommonFlags.DefinitelyAssigned)) { if (field.type.isReference) { this.warning( // involves a runtime check DiagnosticCode.Property_0_is_always_assigned_before_being_used, @@ -8810,11 +8814,11 @@ export class Compiler extends DiagnosticEmitter { /** Node to report on. */ reportNode: Node ): ExpressionRef { - assert(ctorInstance.is(CommonFlags.CONSTRUCTOR)); + assert(ctorInstance.is(CommonFlags.Constructor)); var parent = ctorInstance.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); var classInstance = parent; - if (classInstance.type.isUnmanaged || ctorInstance.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(reportNode); + if (classInstance.type.isUnmanaged || ctorInstance.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(reportNode); var expr = this.compileCallDirect( ctorInstance, argumentExpressions, @@ -8842,10 +8846,10 @@ export class Compiler extends DiagnosticEmitter { var target = resolver.lookupExpression(expression, flow, ctxType); // reports if (!target) return module.unreachable(); var thisExpression = resolver.currentThisExpression; - if (target.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression); + if (target.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(expression); switch (target.kind) { - case ElementKind.GLOBAL: { // static field + case ElementKind.Global: { // static field let global = target; if (!this.compileGlobal(global)) return module.unreachable(); // reports let globalType = global.type; @@ -8859,47 +8863,47 @@ export class Compiler extends DiagnosticEmitter { this.currentType = globalType; return module.unreachable(); } - if (global.is(CommonFlags.INLINED)) { + if (global.is(CommonFlags.Inlined)) { return this.compileInlineConstant(global, ctxType, constraints); } this.currentType = globalType; return module.global_get(global.internalName, globalType.toRef()); } - case ElementKind.ENUMVALUE: { // enum value + case ElementKind.EnumValue: { // enum value let enumValue = target; let parent = assert(enumValue.parent); - assert(parent.kind == ElementKind.ENUM); + assert(parent.kind == ElementKind.Enum); let parentEnum = parent; if (!this.compileEnum(parentEnum)) { this.currentType = Type.i32; return this.module.unreachable(); } this.currentType = Type.i32; - if (enumValue.is(CommonFlags.INLINED)) { - assert(enumValue.constantValueKind == ConstantValueKind.INTEGER); + if (enumValue.is(CommonFlags.Inlined)) { + assert(enumValue.constantValueKind == ConstantValueKind.Integer); return this.compileInlineConstant(enumValue, ctxType, constraints); } assert(enumValue.type == Type.i32); return module.global_get(enumValue.internalName, TypeRef.I32); } - case ElementKind.FIELD: { + case ElementKind.Field: { let fieldInstance = target; let fieldType = fieldInstance.type; assert(fieldInstance.memoryOffset >= 0); let fieldParent = fieldInstance.parent; - assert(fieldParent.kind == ElementKind.CLASS); + assert(fieldParent.kind == ElementKind.Class); thisExpression = assert(thisExpression); let thisExpr = this.compileExpression( thisExpression, (fieldParent).type, - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); let thisType = this.currentType; if ( - flow.actualFunction.is(CommonFlags.CONSTRUCTOR) && - thisExpression.kind == NodeKind.THIS && - !flow.isThisFieldFlag(fieldInstance, FieldFlags.INITIALIZED) && - !fieldInstance.is(CommonFlags.DEFINITELY_ASSIGNED) + flow.actualFunction.is(CommonFlags.Constructor) && + thisExpression.kind == NodeKind.This && + !flow.isThisFieldFlag(fieldInstance, FieldFlags.Initialized) && + !fieldInstance.is(CommonFlags.DefinitelyAssigned) ) { this.errorRelated( DiagnosticCode.Property_0_is_used_before_being_assigned, @@ -8916,8 +8920,8 @@ export class Compiler extends DiagnosticEmitter { ); } } - if (!fieldInstance.is(CommonFlags.COMPILED)) { - fieldInstance.set(CommonFlags.COMPILED); + if (!fieldInstance.is(CommonFlags.Compiled)) { + fieldInstance.set(CommonFlags.Compiled); let typeNode = fieldInstance.typeNode; if (typeNode) this.checkTypeSupported(fieldInstance.type, typeNode); } @@ -8929,33 +8933,33 @@ export class Compiler extends DiagnosticEmitter { fieldType.toRef(), fieldInstance.memoryOffset ); - if (fieldInstance.is(CommonFlags.DEFINITELY_ASSIGNED) && fieldType.isReference && !fieldType.isNullableReference) { + if (fieldInstance.is(CommonFlags.DefinitelyAssigned) && fieldType.isReference && !fieldType.isNullableReference) { ret = this.makeRuntimeNonNullCheck(ret, fieldType, expression); } return ret; } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let propertyPrototype = target; let propertyInstance = this.resolver.resolveProperty(propertyPrototype); if (!propertyInstance) return module.unreachable(); target = propertyInstance; // fall-through } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let propertyInstance = target; let getterInstance = propertyInstance.getterInstance; if (!getterInstance) return module.unreachable(); // failed earlier let thisArg: ExpressionRef = 0; - if (getterInstance.is(CommonFlags.INSTANCE)) { + if (getterInstance.is(CommonFlags.Instance)) { thisArg = this.compileExpression( assert(thisExpression), assert(getterInstance.signature.thisType), - Constraints.CONV_IMPLICIT | Constraints.IS_THIS + Constraints.ConvImplicit | Constraints.IsThis ); } return this.compileCallDirect(getterInstance, [], expression, thisArg); } - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let functionPrototype = target; let functionInstance = this.resolver.resolveFunction(functionPrototype, null); if (!functionInstance) return module.unreachable(); @@ -8991,10 +8995,10 @@ export class Compiler extends DiagnosticEmitter { // Try to eliminate unnecesssary branches if the condition is constant // FIXME: skips common denominator, inconsistently picking branch type var condKind = this.evaluateCondition(condExpr); - if (condKind == ConditionKind.TRUE) { + if (condKind == ConditionKind.True) { return module.maybeDropCondition(condExpr, this.compileExpression(ifThen, ctxType)); } - if (condKind == ConditionKind.FALSE) { + if (condKind == ConditionKind.False) { return module.maybeDropCondition(condExpr, this.compileExpression(ifElse, ctxType)); } @@ -9059,7 +9063,7 @@ export class Compiler extends DiagnosticEmitter { var getValue = this.compileExpression( // reports expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // if the value isn't dropped, a temp. local is required to remember the original value, @@ -9084,7 +9088,7 @@ export class Compiler extends DiagnosticEmitter { if (classReference) { let overload = classReference.lookupOverload(OperatorKind.POSTFIX_INC); if (overload) { - let isInstance = overload.is(CommonFlags.INSTANCE); + let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns getValue = getLocalSetValue(getValue); flow.freeTempLocal(tempLocal); @@ -9105,7 +9109,7 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9128,8 +9132,8 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.AddSize, getValue, @@ -9170,14 +9174,14 @@ export class Compiler extends DiagnosticEmitter { if (classReference) { let overload = classReference.lookupOverload(OperatorKind.POSTFIX_DEC); if (overload) { - let isInstance = overload.is(CommonFlags.INSTANCE); + let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns getValue = getLocalSetValue(getValue); flow.freeTempLocal(tempLocal); tempLocal = null; } expr = this.compileUnaryOverload(overload, expression.operand, getValue, expression); - if (overload.is(CommonFlags.INSTANCE)) break; + if (overload.is(CommonFlags.Instance)) break; return expr; // here } } @@ -9191,7 +9195,7 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9214,8 +9218,8 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.SubSize, getValue, @@ -9310,7 +9314,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9334,7 +9338,7 @@ export class Compiler extends DiagnosticEmitter { let operand = expression.operand; if (operand.isNumericLiteral) { // implicitly negate integer and float literals. also enables proper checking of literal ranges. - expr = this.compileLiteralExpression(operand, contextualType, Constraints.NONE, true); + expr = this.compileLiteralExpression(operand, contextualType, Constraints.None, true); // compileExpression normally does this: if (this.options.sourceMap) this.addDebugLocation(expr, expression.range); break; @@ -9343,7 +9347,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9361,7 +9365,7 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9376,8 +9380,8 @@ export class Compiler extends DiagnosticEmitter { expr = module.binary(BinaryOp.SubI64, module.i64(0), expr); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.SubSize, this.makeZero(this.currentType), @@ -9408,7 +9412,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9417,7 +9421,7 @@ export class Compiler extends DiagnosticEmitter { let overload = classReference.lookupOverload(OperatorKind.PREFIX_INC); if (overload) { expr = this.compileUnaryOverload(overload, expression.operand, expr, expression); - if (overload.is(CommonFlags.INSTANCE)) break; // re-assign + if (overload.is(CommonFlags.Instance)) break; // re-assign return expr; // skip re-assign } } @@ -9430,7 +9434,7 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9445,8 +9449,8 @@ export class Compiler extends DiagnosticEmitter { expr = module.binary(BinaryOp.AddI64, expr, module.i64(1)); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.AddSize, expr, @@ -9477,7 +9481,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9486,7 +9490,7 @@ export class Compiler extends DiagnosticEmitter { let overload = classReference.lookupOverload(OperatorKind.PREFIX_DEC); if (overload) { expr = this.compileUnaryOverload(overload, expression.operand, expr, expression); - if (overload.is(CommonFlags.INSTANCE)) break; // re-assign + if (overload.is(CommonFlags.Instance)) break; // re-assign return expr; // skip re-assign } } @@ -9499,7 +9503,7 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9514,8 +9518,8 @@ export class Compiler extends DiagnosticEmitter { expr = module.binary(BinaryOp.SubI64, expr, module.i64(1)); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.SubSize, expr, @@ -9545,7 +9549,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9568,7 +9572,7 @@ export class Compiler extends DiagnosticEmitter { : contextualType.isFloatValue ? Type.i64 : contextualType, - Constraints.NONE + Constraints.None ); // check operator overload @@ -9588,7 +9592,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.convertExpression(expr, this.currentType, this.currentType.intType, false, expression.operand); switch (this.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -9603,8 +9607,8 @@ export class Compiler extends DiagnosticEmitter { expr = module.binary(BinaryOp.XorI64, expr, module.i64(-1, -1)); break; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { expr = module.binary( BinaryOp.XorSize, expr, @@ -9661,19 +9665,19 @@ export class Compiler extends DiagnosticEmitter { var expr: ExpressionRef = 0; var stringInstance = this.program.stringInstance; var typeString: string; - if (operand.kind == NodeKind.NULL) { + if (operand.kind == NodeKind.Null) { typeString = "object"; // special since `null` without type context is usize } else { - let element = this.resolver.lookupExpression(operand, this.currentFlow, Type.auto, ReportMode.SWALLOW); + let element = this.resolver.lookupExpression(operand, this.currentFlow, Type.auto, ReportMode.Swallow); if (!element) { switch (operand.kind) { - case NodeKind.IDENTIFIER: break; // ignore error: typeof doesntExist -> undefined - case NodeKind.PROPERTYACCESS: - case NodeKind.ELEMENTACCESS: { - operand = operand.kind == NodeKind.PROPERTYACCESS + case NodeKind.Identifier: break; // ignore error: typeof doesntExist -> undefined + case NodeKind.PropertyAccess: + case NodeKind.ElementAccess: { + operand = operand.kind == NodeKind.PropertyAccess ? (operand).expression : (operand).expression; - let targetType = this.resolver.resolveExpression(operand, this.currentFlow, Type.auto, ReportMode.REPORT); + let targetType = this.resolver.resolveExpression(operand, this.currentFlow, Type.auto, ReportMode.Report); if (!targetType) { // access on non-object this.currentType = stringInstance.type; return this.module.unreachable(); @@ -9688,13 +9692,13 @@ export class Compiler extends DiagnosticEmitter { typeString = "undefined"; } else { switch (element.kind) { - case ElementKind.CLASS_PROTOTYPE: - case ElementKind.NAMESPACE: - case ElementKind.ENUM: { + case ElementKind.ClassPrototype: + case ElementKind.Namespace: + case ElementKind.Enum: { typeString = "object"; break; } - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { typeString = "function"; break; } @@ -9741,7 +9745,7 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var flow = this.currentFlow; switch (type.kind) { - case TypeKind.BOOL: { + case TypeKind.Bool: { if (flow.canOverflow(expr, type)) { // bool is special in that it compares to 0 instead of masking with 0x1 expr = module.binary(BinaryOp.NeI32, @@ -9753,7 +9757,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I8: { if (flow.canOverflow(expr, type)) { - expr = this.options.hasFeature(Feature.SIGN_EXTENSION) + expr = this.options.hasFeature(Feature.SignExtension) ? module.unary(UnaryOp.Extend8I32, expr) : module.binary(BinaryOp.ShrI32, module.binary(BinaryOp.ShlI32, @@ -9767,7 +9771,7 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.I16: { if (flow.canOverflow(expr, type)) { - expr = this.options.hasFeature(Feature.SIGN_EXTENSION) + expr = this.options.hasFeature(Feature.SignExtension) ? module.unary(UnaryOp.Extend16I32, expr) : module.binary(BinaryOp.ShrI32, module.binary(BinaryOp.ShlI32, @@ -9825,15 +9829,15 @@ export class Compiler extends DiagnosticEmitter { /** Checks whether a particular type is supported. */ checkTypeSupported(type: Type, reportNode: Node): bool { switch (type.kind) { - case TypeKind.V128: return this.checkFeatureEnabled(Feature.SIMD, reportNode); - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode); - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: { - return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode) + case TypeKind.V128: return this.checkFeatureEnabled(Feature.Simd, reportNode); + case TypeKind.Funcref: + case TypeKind.Externref: + return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode); + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: { + return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode) && this.checkFeatureEnabled(Feature.GC, reportNode); } } @@ -9903,17 +9907,17 @@ export class Compiler extends DiagnosticEmitter { evaluateCondition(expr: ExpressionRef): ConditionKind { let type = getExpressionType(expr); if (type == TypeRef.Unreachable) - return ConditionKind.UNKNOWN; + return ConditionKind.Unknown; assert(type == TypeRef.I32); var module = this.module; var evaled = module.runExpression(expr, ExpressionRunnerFlags.Default); if (evaled) { return getConstValueI32(evaled) - ? ConditionKind.TRUE - : ConditionKind.FALSE; + ? ConditionKind.True + : ConditionKind.False; } - return ConditionKind.UNKNOWN; + return ConditionKind.Unknown; } // === Specialized code generation ============================================================== @@ -9923,26 +9927,26 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; switch (type.kind) { default: assert(false); - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: return module.i32(0); - case TypeKind.ISIZE: - case TypeKind.USIZE: if (type.size != 64) return module.i32(0); + case TypeKind.Isize: + case TypeKind.Usize: if (type.size != 64) return module.i32(0); case TypeKind.I64: case TypeKind.U64: return module.i64(0); case TypeKind.F32: return module.f32(0); case TypeKind.F64: return module.f64(0); case TypeKind.V128: return module.v128(v128_zero); - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.DATAREF: return module.ref_null(type.toRef()); - case TypeKind.I31REF: return module.i31_new(module.i32(0)); + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.Dataref: return module.ref_null(type.toRef()); + case TypeKind.I31ref: return module.i31_new(module.i32(0)); } } @@ -9951,20 +9955,20 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; switch (type.kind) { default: assert(false); - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: return module.i32(1); - case TypeKind.ISIZE: - case TypeKind.USIZE: if (type.size != 64) return module.i32(1); + case TypeKind.Isize: + case TypeKind.Usize: if (type.size != 64) return module.i32(1); case TypeKind.I64: case TypeKind.U64: return module.i64(1); case TypeKind.F32: return module.f32(1); case TypeKind.F64: return module.f64(1); - case TypeKind.I31REF: return module.i31_new(module.i32(1)); + case TypeKind.I31ref: return module.i31_new(module.i32(1)); } } @@ -9979,14 +9983,14 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: return module.i32(-1); - case TypeKind.ISIZE: - case TypeKind.USIZE: if (type.size != 64) return module.i32(-1); + case TypeKind.Isize: + case TypeKind.Usize: if (type.size != 64) return module.i32(-1); case TypeKind.I64: case TypeKind.U64: return module.i64(-1, -1); case TypeKind.F32: return module.f32(-1); case TypeKind.F64: return module.f64(-1); case TypeKind.V128: return module.v128(v128_ones); - case TypeKind.I31REF: return module.i31_new(module.i32(-1)); + case TypeKind.I31ref: return module.i31_new(module.i32(-1)); } } @@ -10001,13 +10005,13 @@ export class Compiler extends DiagnosticEmitter { expr = this.ensureSmallIntegerWrap(expr, type); // fall-through } - case TypeKind.BOOL: // not a mask, just != 0 + case TypeKind.Bool: // not a mask, just != 0 case TypeKind.I32: case TypeKind.U32: return expr; case TypeKind.I64: case TypeKind.U64: return module.binary(BinaryOp.NeI64, expr, module.i64(0)); - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { return type.size == 64 ? module.binary(BinaryOp.NeI64, expr, module.i64(0)) : expr; @@ -10016,7 +10020,7 @@ export class Compiler extends DiagnosticEmitter { let options = this.options; if ( options.shrinkLevelHint > 1 && - options.hasFeature(Feature.NONTRAPPING_F2I) + options.hasFeature(Feature.NontrappingF2I) ) { // Use more compact but slower 5-byte (3 bytes in best case) approach // !!(i32.trunc_sat_f32_u(f32.ceil(f32.abs(x)))) @@ -10051,7 +10055,7 @@ export class Compiler extends DiagnosticEmitter { let options = this.options; if ( options.shrinkLevelHint > 1 && - options.hasFeature(Feature.NONTRAPPING_F2I) + options.hasFeature(Feature.NontrappingF2I) ) { // Use more compact but slower 5-byte (3 bytes in best case) approach // !!(i32.trunc_sat_f64_u(f64.ceil(f64.abs(x)))) @@ -10085,17 +10089,17 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.V128: { return module.unary(UnaryOp.AnyTrueV128, expr); } - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: { // Needs to be true (i.e. not zero) when the ref is _not_ null, // which means `ref.is_null` returns false (i.e. zero). return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr)); } - case TypeKind.VOID: + case TypeKind.Void: default: { this.error( DiagnosticCode.An_expression_of_type_0_cannot_be_tested_for_truthiness, @@ -10163,7 +10167,7 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var options = this.options; this.currentType = classInstance.type; - if (classInstance.hasDecorator(DecoratorFlags.UNMANAGED)) { + if (classInstance.hasDecorator(DecoratorFlags.Unmanaged)) { let allocInstance = program.allocInstance; this.compileFunction(allocInstance); return module.call(allocInstance.internalName, [ @@ -10224,11 +10228,11 @@ export class Compiler extends DiagnosticEmitter { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = unchecked(_values[i]); if ( - member.kind != ElementKind.FIELD || // not a field + member.kind != ElementKind.Field || // not a field member.parent != classInstance // inherited field ) continue; let field = member; - assert(!field.isAny(CommonFlags.CONST)); + assert(!field.isAny(CommonFlags.Const)); let fieldPrototype = field.prototype; let parameterIndex = fieldPrototype.parameterIndex; @@ -10270,7 +10274,7 @@ export class Compiler extends DiagnosticEmitter { module.call(field.internalSetterName, [ module.local_get(thisLocalIndex, sizeTypeRef), initializerNode // use initializer if present, otherwise initialize with zero - ? this.compileExpression(initializerNode, fieldType, Constraints.CONV_IMPLICIT) + ? this.compileExpression(initializerNode, fieldType, Constraints.ConvImplicit) : this.makeZero(fieldType) ], TypeRef.None) ); @@ -10295,7 +10299,7 @@ export class Compiler extends DiagnosticEmitter { var stringInstance = program.stringInstance; var messageArg: ExpressionRef; if (message) { - messageArg = this.compileExpression(message, stringInstance.type, Constraints.CONV_IMPLICIT); + messageArg = this.compileExpression(message, stringInstance.type, Constraints.ConvImplicit); } else { messageArg = this.makeZero(stringInstance.type); } @@ -10344,8 +10348,8 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var flow = this.currentFlow; var temp = flow.getTempLocal(type); - if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); - flow.setLocalFlag(temp.index, LocalFlags.NONNULL); + if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.Wrapped); + flow.setLocalFlag(temp.index, LocalFlags.NonNull); var staticAbortCallExpr = this.makeStaticAbort( this.ensureStaticString("unexpected null"), @@ -10439,26 +10443,26 @@ function mangleImportName( mangleImportName_moduleName = declaration.range.source.simplePath; // and the internal name of the element within that file as the element name mangleImportName_elementName = mangleInternalName( - element.name, element.parent, element.is(CommonFlags.INSTANCE), true + element.name, element.parent, element.is(CommonFlags.Instance), true ); // override module name if a `module` statement is present let overriddenModuleName = declaration.overriddenModuleName; if (overriddenModuleName) mangleImportName_moduleName = overriddenModuleName; - if (!element.hasDecorator(DecoratorFlags.EXTERNAL)) return; + if (!element.hasDecorator(DecoratorFlags.External)) return; var program = element.program; - var decorator = assert(findDecorator(DecoratorKind.EXTERNAL, declaration.decorators)); + var decorator = assert(findDecorator(DecoratorKind.External, declaration.decorators)); var args = decorator.args; if (args && args.length > 0) { let arg = args[0]; // if one argument is given, override just the element name // if two arguments are given, override both module and element name - if (arg.isLiteralKind(LiteralKind.STRING)) { + if (arg.isLiteralKind(LiteralKind.String)) { mangleImportName_elementName = (arg).value; if (args.length >= 2) { arg = args[1]; - if (arg.isLiteralKind(LiteralKind.STRING)) { + if (arg.isLiteralKind(LiteralKind.String)) { mangleImportName_moduleName = mangleImportName_elementName; mangleImportName_elementName = (arg).value; if (args.length > 2) { diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 59b58166a9..c82f0fb70a 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -33,13 +33,13 @@ export { /** Indicates the category of a {@link DiagnosticMessage}. */ export const enum DiagnosticCategory { /** Overly pedantic message. */ - PEDANTIC, + Pedantic, /** Informatory message. */ - INFO, + Info, /** Warning message. */ - WARNING, + Warning, /** Error message. */ - ERROR + Error } export class Range { @@ -87,10 +87,10 @@ export class Range { /** Returns the string representation of the specified diagnostic category. */ export function diagnosticCategoryToString(category: DiagnosticCategory): string { switch (category) { - case DiagnosticCategory.PEDANTIC: return "PEDANTIC"; - case DiagnosticCategory.INFO: return "INFO"; - case DiagnosticCategory.WARNING: return "WARNING"; - case DiagnosticCategory.ERROR: return "ERROR"; + case DiagnosticCategory.Pedantic: return "PEDANTIC"; + case DiagnosticCategory.Info: return "INFO"; + case DiagnosticCategory.Warning: return "WARNING"; + case DiagnosticCategory.Error: return "ERROR"; default: { assert(false); return ""; @@ -101,10 +101,10 @@ export function diagnosticCategoryToString(category: DiagnosticCategory): string /** Returns the ANSI escape sequence for the specified category. */ export function diagnosticCategoryToColor(category: DiagnosticCategory): string { switch (category) { - case DiagnosticCategory.PEDANTIC: return COLOR_MAGENTA; - case DiagnosticCategory.INFO: return COLOR_CYAN; - case DiagnosticCategory.WARNING: return COLOR_YELLOW; - case DiagnosticCategory.ERROR: return COLOR_RED; + case DiagnosticCategory.Pedantic: return COLOR_MAGENTA; + case DiagnosticCategory.Info: return COLOR_CYAN; + case DiagnosticCategory.Warning: return COLOR_YELLOW; + case DiagnosticCategory.Error: return COLOR_RED; default: { assert(false); return ""; @@ -377,7 +377,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.PEDANTIC, range, null, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Pedantic, range, null, arg0, arg1, arg2); } /** Emits an overly pedantic diagnostic message with a related range. */ @@ -389,7 +389,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.PEDANTIC, range, relatedRange, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Pedantic, range, relatedRange, arg0, arg1, arg2); } /** Emits an informatory diagnostic message. */ @@ -400,7 +400,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.INFO, range, null, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Info, range, null, arg0, arg1, arg2); } /** Emits an informatory diagnostic message with a related range. */ @@ -412,7 +412,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.INFO, range, relatedRange, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Info, range, relatedRange, arg0, arg1, arg2); } /** Emits a warning diagnostic message. */ @@ -423,7 +423,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.WARNING, range, null, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Warning, range, null, arg0, arg1, arg2); } /** Emits a warning diagnostic message with a related range. */ @@ -435,7 +435,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.WARNING, range, relatedRange, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Warning, range, relatedRange, arg0, arg1, arg2); } /** Emits an error diagnostic message. */ @@ -446,7 +446,7 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.ERROR, range, null, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Error, range, null, arg0, arg1, arg2); } /** Emits an error diagnostic message with a related range. */ @@ -458,6 +458,6 @@ export abstract class DiagnosticEmitter { arg1: string | null = null, arg2: string | null = null ): void { - this.emitDiagnostic(code, DiagnosticCategory.ERROR, range, relatedRange, arg0, arg1, arg2); + this.emitDiagnostic(code, DiagnosticCategory.Error, range, relatedRange, arg0, arg1, arg2); } } diff --git a/src/extra/ast.ts b/src/extra/ast.ts index 3743e1b149..b99e2de07a 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -119,248 +119,248 @@ export class ASTBuilder { visitNode(node: Node): void { switch (node.kind) { - case NodeKind.SOURCE: { + case NodeKind.Source: { this.visitSource(node); break; } // types - case NodeKind.NAMEDTYPE: { + case NodeKind.NamedType: { this.visitNamedTypeNode(node); break; } - case NodeKind.FUNCTIONTYPE: { + case NodeKind.FunctionType: { this.visitFunctionTypeNode(node); break; } - case NodeKind.TYPEPARAMETER: { + case NodeKind.TypeParameter: { this.visitTypeParameter(node); break; } // expressions - case NodeKind.FALSE: - case NodeKind.NULL: - case NodeKind.SUPER: - case NodeKind.THIS: - case NodeKind.TRUE: - case NodeKind.CONSTRUCTOR: - case NodeKind.IDENTIFIER: { + case NodeKind.False: + case NodeKind.Null: + case NodeKind.Super: + case NodeKind.This: + case NodeKind.True: + case NodeKind.Constructor: + case NodeKind.Identifier: { this.visitIdentifierExpression(node); break; } - case NodeKind.ASSERTION: { + case NodeKind.Assertion: { this.visitAssertionExpression(node); break; } - case NodeKind.BINARY: { + case NodeKind.Binary: { this.visitBinaryExpression(node); break; } - case NodeKind.CALL: { + case NodeKind.Call: { this.visitCallExpression(node); break; } - case NodeKind.CLASS: { + case NodeKind.Class: { this.visitClassExpression(node); break; } - case NodeKind.COMMA: { + case NodeKind.Comma: { this.visitCommaExpression(node); break; } - case NodeKind.ELEMENTACCESS: { + case NodeKind.ElementAccess: { this.visitElementAccessExpression(node); break; } - case NodeKind.FUNCTION: { + case NodeKind.Function: { this.visitFunctionExpression(node); break; } - case NodeKind.INSTANCEOF: { + case NodeKind.InstanceOf: { this.visitInstanceOfExpression(node); break; } - case NodeKind.LITERAL: { + case NodeKind.Literal: { this.visitLiteralExpression(node); break; } - case NodeKind.NEW: { + case NodeKind.New: { this.visitNewExpression(node); break; } - case NodeKind.PARENTHESIZED: { + case NodeKind.Parenthesized: { this.visitParenthesizedExpression(node); break; } - case NodeKind.PROPERTYACCESS: { + case NodeKind.PropertyAccess: { this.visitPropertyAccessExpression(node); break; } - case NodeKind.TERNARY: { + case NodeKind.Ternary: { this.visitTernaryExpression(node); break; } - case NodeKind.UNARYPOSTFIX: { + case NodeKind.UnaryPostfix: { this.visitUnaryPostfixExpression(node); break; } - case NodeKind.UNARYPREFIX: { + case NodeKind.UnaryPrefix: { this.visitUnaryPrefixExpression(node); break; } // statements - case NodeKind.BLOCK: { + case NodeKind.Block: { this.visitBlockStatement(node); break; } - case NodeKind.BREAK: { + case NodeKind.Break: { this.visitBreakStatement(node); break; } - case NodeKind.CONTINUE: { + case NodeKind.Continue: { this.visitContinueStatement(node); break; } - case NodeKind.DO: { + case NodeKind.Do: { this.visitDoStatement(node); break; } - case NodeKind.EMPTY: { + case NodeKind.Empty: { this.visitEmptyStatement(node); break; } - case NodeKind.EXPORT: { + case NodeKind.Export: { this.visitExportStatement(node); break; } - case NodeKind.EXPORTDEFAULT: { + case NodeKind.ExportDefault: { this.visitExportDefaultStatement(node); break; } - case NodeKind.EXPORTIMPORT: { + case NodeKind.ExportImport: { this.visitExportImportStatement(node); break; } - case NodeKind.EXPRESSION: { + case NodeKind.Expression: { this.visitExpressionStatement(node); break; } - case NodeKind.FOR: { + case NodeKind.For: { this.visitForStatement(node); break; } - case NodeKind.FOROF: { + case NodeKind.ForOf: { this.visitForOfStatement(node); break; } - case NodeKind.IF: { + case NodeKind.If: { this.visitIfStatement(node); break; } - case NodeKind.IMPORT: { + case NodeKind.Import: { this.visitImportStatement(node); break; } - case NodeKind.RETURN: { + case NodeKind.Return: { this.visitReturnStatement(node); break; } - case NodeKind.SWITCH: { + case NodeKind.Switch: { this.visitSwitchStatement(node); break; } - case NodeKind.THROW: { + case NodeKind.Throw: { this.visitThrowStatement(node); break; } - case NodeKind.TRY: { + case NodeKind.Try: { this.visitTryStatement(node); break; } - case NodeKind.VARIABLE: { + case NodeKind.Variable: { this.visitVariableStatement(node); break; } - case NodeKind.WHILE: { + case NodeKind.While: { this.visitWhileStatement(node); break; } - case NodeKind.MODULE: { + case NodeKind.Module: { this.visitModuleDeclaration(node); break; } // declaration statements - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { this.visitClassDeclaration(node); break; } - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { this.visitEnumDeclaration(node); break; } - case NodeKind.ENUMVALUEDECLARATION: { + case NodeKind.EnumValueDeclaration: { this.visitEnumValueDeclaration(node); break; } - case NodeKind.FIELDDECLARATION: { + case NodeKind.FieldDeclaration: { this.visitFieldDeclaration(node); break; } - case NodeKind.FUNCTIONDECLARATION: { + case NodeKind.FunctionDeclaration: { this.visitFunctionDeclaration(node); break; } - case NodeKind.IMPORTDECLARATION: { + case NodeKind.ImportDeclaration: { this.visitImportDeclaration(node); break; } - case NodeKind.INTERFACEDECLARATION: { + case NodeKind.InterfaceDeclaration: { this.visitInterfaceDeclaration(node); break; } - case NodeKind.METHODDECLARATION: { + case NodeKind.MethodDeclaration: { this.visitMethodDeclaration(node); break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { this.visitNamespaceDeclaration(node); break; } - case NodeKind.TYPEDECLARATION: { + case NodeKind.TypeDeclaration: { this.visitTypeDeclaration(node); break; } - case NodeKind.VARIABLEDECLARATION: { + case NodeKind.VariableDeclaration: { this.visitVariableDeclaration(node); break; } // other - case NodeKind.DECORATOR: { + case NodeKind.Decorator: { this.serializeDecorator(node); break; } - case NodeKind.EXPORTMEMBER: { + case NodeKind.ExportMember: { this.visitExportMember(node); break; } - case NodeKind.PARAMETER: { + case NodeKind.Parameter: { this.serializeParameter(node); break; } - case NodeKind.SWITCHCASE: { + case NodeKind.SwitchCase: { this.visitSwitchCase(node); break; } - case NodeKind.INDEXSIGNATURE: { + case NodeKind.IndexSignature: { this.visitIndexSignature(node); break; } @@ -379,11 +379,11 @@ export class ASTBuilder { visitTypeNode(node: TypeNode): void { switch (node.kind) { - case NodeKind.NAMEDTYPE: { + case NodeKind.NamedType: { this.visitNamedTypeNode(node); break; } - case NodeKind.FUNCTIONTYPE: { + case NodeKind.FunctionType: { this.visitFunctionTypeNode(node); break; } @@ -524,25 +524,25 @@ export class ASTBuilder { visitAssertionExpression(node: AssertionExpression): void { var sb = this.sb; switch (node.assertionKind) { - case AssertionKind.PREFIX: { + case AssertionKind.Prefix: { sb.push("<"); this.visitTypeNode(assert(node.toType)); sb.push(">"); this.visitNode(node.expression); break; } - case AssertionKind.AS: { + case AssertionKind.As: { this.visitNode(node.expression); sb.push(" as "); this.visitTypeNode(assert(node.toType)); break; } - case AssertionKind.NONNULL: { + case AssertionKind.NonNull: { this.visitNode(node.expression); sb.push("!"); break; } - case AssertionKind.CONST: { + case AssertionKind.Const: { this.visitNode(node.expression); sb.push(" as const"); break; @@ -632,31 +632,31 @@ export class ASTBuilder { visitLiteralExpression(node: LiteralExpression): void { switch (node.literalKind) { - case LiteralKind.FLOAT: { + case LiteralKind.Float: { this.visitFloatLiteralExpression(node); break; } - case LiteralKind.INTEGER: { + case LiteralKind.Integer: { this.visitIntegerLiteralExpression(node); break; } - case LiteralKind.STRING: { + case LiteralKind.String: { this.visitStringLiteralExpression(node); break; } - case LiteralKind.TEMPLATE: { + case LiteralKind.Template: { this.visitTemplateLiteralExpression(node); break; } - case LiteralKind.REGEXP: { + case LiteralKind.RegExp: { this.visitRegexpLiteralExpression(node); break; } - case LiteralKind.ARRAY: { + case LiteralKind.Array: { this.visitArrayLiteralExpression(node); break; } - case LiteralKind.OBJECT: { + case LiteralKind.Object: { this.visitObjectLiteralExpression(node); break; } @@ -750,11 +750,11 @@ export class ASTBuilder { visitUnaryExpression(node: UnaryExpression): void { switch (node.kind) { - case NodeKind.UNARYPOSTFIX: { + case NodeKind.UnaryPostfix: { this.visitUnaryPostfixExpression(node); break; } - case NodeKind.UNARYPREFIX: { + case NodeKind.UnaryPrefix: { this.visitUnaryPrefixExpression(node); break; } @@ -779,8 +779,8 @@ export class ASTBuilder { var sb = this.sb; if ( !sb.length || // leading EmptyStatement - node.kind == NodeKind.VARIABLE || // potentially assigns a FunctionExpression - node.kind == NodeKind.EXPRESSION // potentially assigns a FunctionExpression + node.kind == NodeKind.Variable || // potentially assigns a FunctionExpression + node.kind == NodeKind.Expression // potentially assigns a FunctionExpression ) { sb.push(";\n"); } else { @@ -848,7 +848,7 @@ export class ASTBuilder { } else { this.serializeExternalModifiers(node); } - if (node.is(CommonFlags.ABSTRACT)) sb.push("abstract "); + if (node.is(CommonFlags.Abstract)) sb.push("abstract "); if (node.name.text.length) { sb.push("class "); this.visitIdentifierExpression(node.name); @@ -894,7 +894,7 @@ export class ASTBuilder { } for (let i = 0, k = members.length; i < k; ++i) { let member = members[i]; - if (member.kind != NodeKind.FIELDDECLARATION || (member).parameterIndex < 0) { + if (member.kind != NodeKind.FieldDeclaration || (member).parameterIndex < 0) { indent(sb, indentLevel); this.visitNodeAndTerminate(member); } @@ -910,7 +910,7 @@ export class ASTBuilder { var sb = this.sb; sb.push("do "); this.visitNode(node.body); - if (node.body.kind == NodeKind.BLOCK) { + if (node.body.kind == NodeKind.Block) { sb.push(" while ("); } else { sb.push(";\n"); @@ -932,7 +932,7 @@ export class ASTBuilder { } else { this.serializeExternalModifiers(node); } - if (node.is(CommonFlags.CONST)) sb.push("const "); + if (node.is(CommonFlags.Const)) sb.push("const "); sb.push("enum "); this.visitIdentifierExpression(node.name); var values = node.values; @@ -1015,23 +1015,23 @@ export class ASTBuilder { visitExportDefaultStatement(node: ExportDefaultStatement): void { var declaration = node.declaration; switch (declaration.kind) { - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { this.visitEnumDeclaration(declaration, true); break; } - case NodeKind.FUNCTIONDECLARATION: { + case NodeKind.FunctionDeclaration: { this.visitFunctionDeclaration(declaration, true); break; } - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { this.visitClassDeclaration(declaration, true); break; } - case NodeKind.INTERFACEDECLARATION: { + case NodeKind.InterfaceDeclaration: { this.visitInterfaceDeclaration(declaration, true); break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { this.visitNamespaceDeclaration(declaration, true); break; } @@ -1053,7 +1053,7 @@ export class ASTBuilder { this.serializeAccessModifiers(node); this.visitIdentifierExpression(node.name); var sb = this.sb; - if (node.flags & CommonFlags.DEFINITELY_ASSIGNED) { + if (node.flags & CommonFlags.DefinitelyAssigned) { sb.push("!"); } var type = node.type; @@ -1142,7 +1142,7 @@ export class ASTBuilder { sb.push(">"); } } - if (node.arrowKind == ArrowKind.ARROW_SINGLE) { + if (node.arrowKind == ArrowKind.Single) { let parameters = signature.parameters; assert(parameters.length == 1); assert(!signature.explicitThisType); @@ -1169,7 +1169,7 @@ export class ASTBuilder { var returnType = signature.returnType; if (node.arrowKind) { if (body) { - if (node.arrowKind == ArrowKind.ARROW_SINGLE) { + if (node.arrowKind == ArrowKind.Single) { assert(isTypeOmitted(returnType)); } else { if (isTypeOmitted(returnType)) { @@ -1189,7 +1189,7 @@ export class ASTBuilder { } else { if ( !isTypeOmitted(returnType) && - !node.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.SET) + !node.isAny(CommonFlags.Constructor | CommonFlags.Set) ) { sb.push("): "); this.visitTypeNode(returnType); @@ -1210,12 +1210,12 @@ export class ASTBuilder { sb.push(") "); var ifTrue = node.ifTrue; this.visitNode(ifTrue); - if (ifTrue.kind != NodeKind.BLOCK) { + if (ifTrue.kind != NodeKind.Block) { sb.push(";\n"); } var ifFalse = node.ifFalse; if (ifFalse) { - if (ifTrue.kind == NodeKind.BLOCK) { + if (ifTrue.kind == NodeKind.Block) { sb.push(" else "); } else { sb.push("else "); @@ -1322,9 +1322,9 @@ export class ASTBuilder { } } this.serializeAccessModifiers(node); - if (node.is(CommonFlags.GET)) { + if (node.is(CommonFlags.Get)) { this.sb.push("get "); - } else if (node.is(CommonFlags.SET)) { + } else if (node.is(CommonFlags.Set)) { this.sb.push("set "); } this.visitFunctionCommon(node); @@ -1480,7 +1480,7 @@ export class ASTBuilder { visitModuleDeclaration(node: ModuleDeclaration): void { var sb = this.sb; - if (node.flags & CommonFlags.DECLARE) { + if (node.flags & CommonFlags.Declare) { sb.push("declare "); } sb.push("module \""); @@ -1492,7 +1492,7 @@ export class ASTBuilder { this.visitIdentifierExpression(node.name); var type = node.type; var sb = this.sb; - if (node.flags & CommonFlags.DEFINITELY_ASSIGNED) { + if (node.flags & CommonFlags.DefinitelyAssigned) { sb.push("!"); } if (type) { @@ -1518,7 +1518,7 @@ export class ASTBuilder { var numDeclarations = assert(declarations.length); var firstDeclaration = declarations[0]; this.serializeExternalModifiers(firstDeclaration); - sb.push(firstDeclaration.is(CommonFlags.CONST) ? "const " : firstDeclaration.is(CommonFlags.LET) ? "let " : "var "); + sb.push(firstDeclaration.is(CommonFlags.Const) ? "const " : firstDeclaration.is(CommonFlags.Let) ? "let " : "var "); this.visitVariableDeclaration(node.declarations[0]); for (let i = 1; i < numDeclarations; ++i) { sb.push(", "); @@ -1591,33 +1591,33 @@ export class ASTBuilder { serializeExternalModifiers(node: DeclarationStatement): void { var sb = this.sb; - if (node.is(CommonFlags.EXPORT)) { + if (node.is(CommonFlags.Export)) { sb.push("export "); - } else if (node.is(CommonFlags.IMPORT)) { + } else if (node.is(CommonFlags.Import)) { sb.push("import "); - } else if (node.is(CommonFlags.DECLARE)) { + } else if (node.is(CommonFlags.Declare)) { sb.push("declare "); } } serializeAccessModifiers(node: DeclarationStatement): void { var sb = this.sb; - if (node.is(CommonFlags.DECLARE)) { + if (node.is(CommonFlags.Declare)) { sb.push("declare "); } - if (node.is(CommonFlags.PUBLIC)) { + if (node.is(CommonFlags.Public)) { sb.push("public "); - } else if (node.is(CommonFlags.PRIVATE)) { + } else if (node.is(CommonFlags.Private)) { sb.push("private "); - } else if (node.is(CommonFlags.PROTECTED)) { + } else if (node.is(CommonFlags.Protected)) { sb.push("protected "); } - if (node.is(CommonFlags.STATIC)) { + if (node.is(CommonFlags.Static)) { sb.push("static "); - } else if (node.is(CommonFlags.ABSTRACT)) { + } else if (node.is(CommonFlags.Abstract)) { sb.push("abstract "); } - if (node.is(CommonFlags.READONLY)) { + if (node.is(CommonFlags.Readonly)) { sb.push("readonly "); } } diff --git a/src/flow.ts b/src/flow.ts index 12f8e0ea16..a4ef7c2a4e 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -95,101 +95,101 @@ import { /** Control flow flags indicating specific conditions. */ export const enum FlowFlags { /** No specific conditions. */ - NONE = 0, + None = 0, // categorical /** This flow always returns. */ - RETURNS = 1 << 0, + Returns = 1 << 0, /** This flow always returns a wrapped value. */ - RETURNS_WRAPPED = 1 << 1, + ReturnsWrapped = 1 << 1, /** This flow always returns a non-null value. */ - RETURNS_NONNULL = 1 << 2, + ReturnsNonNull = 1 << 2, /** This flow always throws. */ - THROWS = 1 << 3, + Throws = 1 << 3, /** This flow always breaks. */ - BREAKS = 1 << 4, + Breaks = 1 << 4, /** This flow always continues. */ - CONTINUES = 1 << 5, + Continues = 1 << 5, /** This flow always accesses `this`. Constructors only. */ - ACCESSES_THIS = 1 << 6, + AccessesThis = 1 << 6, /** This flow always calls `super`. Constructors only. */ - CALLS_SUPER = 1 << 7, + CallsSuper = 1 << 7, /** This flow always terminates (returns, throws or continues). */ - TERMINATES = 1 << 8, // Note that this doesn't cover BREAKS, which is separate + Terminates = 1 << 8, // Note that this doesn't cover BREAKS, which is separate // conditional /** This flow conditionally returns in a child flow. */ - CONDITIONALLY_RETURNS = 1 << 9, + ConditionallyReturns = 1 << 9, /** This flow conditionally throws in a child flow. */ - CONDITIONALLY_THROWS = 1 << 10, + ConditionallyThrows = 1 << 10, /** This flow conditionally breaks in a child flow. */ - CONDITIONALLY_BREAKS = 1 << 11, + ConditionallyBreaks = 1 << 11, /** This flow conditionally continues in a child flow. */ - CONDITIONALLY_CONTINUES = 1 << 12, + ConditionallyContinues = 1 << 12, /** This flow conditionally accesses `this` in a child flow. Constructors only. */ - CONDITIONALLY_ACCESSES_THIS = 1 << 13, + ConditionallyAccessesThis = 1 << 13, /** This flow may return a non-this value. Constructors only. */ - MAY_RETURN_NONTHIS = 1 << 14, + MayReturnNonThis = 1 << 14, // other /** This is a flow with explicitly disabled bounds checking. */ - UNCHECKED_CONTEXT = 1 << 15, + UncheckedContext = 1 << 15, /** This is a flow compiling a constructor parameter. */ - CTORPARAM_CONTEXT = 1 << 16, + CtorParamContext = 1 << 16, // masks /** Any categorical flag. */ - ANY_CATEGORICAL = FlowFlags.RETURNS - | FlowFlags.RETURNS_WRAPPED - | FlowFlags.RETURNS_NONNULL - | FlowFlags.THROWS - | FlowFlags.BREAKS - | FlowFlags.CONTINUES - | FlowFlags.ACCESSES_THIS - | FlowFlags.CALLS_SUPER - | FlowFlags.TERMINATES, + AnyCategorical = FlowFlags.Returns + | FlowFlags.ReturnsWrapped + | FlowFlags.ReturnsNonNull + | FlowFlags.Throws + | FlowFlags.Breaks + | FlowFlags.Continues + | FlowFlags.AccessesThis + | FlowFlags.CallsSuper + | FlowFlags.Terminates, /** Any conditional flag. */ - ANY_CONDITIONAL = FlowFlags.CONDITIONALLY_RETURNS - | FlowFlags.CONDITIONALLY_THROWS - | FlowFlags.CONDITIONALLY_BREAKS - | FlowFlags.CONDITIONALLY_CONTINUES - | FlowFlags.CONDITIONALLY_ACCESSES_THIS + AnyConditional = FlowFlags.ConditionallyReturns + | FlowFlags.ConditionallyThrows + | FlowFlags.ConditionallyBreaks + | FlowFlags.ConditionallyContinues + | FlowFlags.ConditionallyAccessesThis } /** Flags indicating the current state of a local. */ export const enum LocalFlags { /** No specific conditions. */ - NONE = 0, + None = 0, /** Local is constant. */ - CONSTANT = 1 << 0, + Constant = 1 << 0, /** Local is properly wrapped. Relevant for small integers. */ - WRAPPED = 1 << 1, + Wrapped = 1 << 1, /** Local is non-null. */ - NONNULL = 1 << 2, + NonNull = 1 << 2, /** Local is initialized. */ - INITIALIZED = 1 << 3 + Initialized = 1 << 3 } /** Flags indicating the current state of a field. */ export const enum FieldFlags { - NONE = 0, - INITIALIZED = 1 << 0 + None = 0, + Initialized = 1 << 0 } /** Condition kinds. */ export const enum ConditionKind { /** Outcome of the condition is unknown */ - UNKNOWN, + Unknown, /** Condition is always true. */ - TRUE, + True, /** Condition is always false. */ - FALSE + False } /** A control flow evaluator. */ @@ -198,7 +198,7 @@ export class Flow { /** Creates the parent flow of the specified function. */ static createParent(parentFunction: Function): Flow { var flow = new Flow(parentFunction); - if (parentFunction.is(CommonFlags.CONSTRUCTOR)) { + if (parentFunction.is(CommonFlags.Constructor)) { flow.initThisFieldFlags(); } return flow; @@ -209,7 +209,7 @@ export class Flow { var flow = new Flow(parentFunction); flow.inlineFunction = inlineFunction; flow.inlineReturnLabel = `${inlineFunction.internalName}|inlined.${(inlineFunction.nextInlineId++)}`; - if (inlineFunction.is(CommonFlags.CONSTRUCTOR)) { + if (inlineFunction.is(CommonFlags.Constructor)) { flow.initThisFieldFlags(); } return flow; @@ -227,7 +227,7 @@ export class Flow { /** Outer flow. Only relevant for first-class functions. */ outer: Flow | null = null; /** Flow flags indicating specific conditions. */ - flags: FlowFlags = FlowFlags.NONE; + flags: FlowFlags = FlowFlags.None; /** The label we break to when encountering a continue statement. */ continueLabel: string | null = null; /** The label we break to when encountering a break statement. */ @@ -275,21 +275,21 @@ export class Flow { unset(flag: FlowFlags): void { this.flags &= ~flag; } deriveConditionalFlags(): FlowFlags { - let condiFlags = this.flags & FlowFlags.ANY_CONDITIONAL; - if (this.is(FlowFlags.RETURNS)) { - condiFlags |= FlowFlags.CONDITIONALLY_RETURNS; + let condiFlags = this.flags & FlowFlags.AnyConditional; + if (this.is(FlowFlags.Returns)) { + condiFlags |= FlowFlags.ConditionallyReturns; } - if (this.is(FlowFlags.THROWS)) { - condiFlags |= FlowFlags.CONDITIONALLY_THROWS; + if (this.is(FlowFlags.Throws)) { + condiFlags |= FlowFlags.ConditionallyThrows; } - if (this.is(FlowFlags.BREAKS)) { - condiFlags |= FlowFlags.CONDITIONALLY_BREAKS; + if (this.is(FlowFlags.Breaks)) { + condiFlags |= FlowFlags.ConditionallyBreaks; } - if (this.is(FlowFlags.CONTINUES)) { - condiFlags |= FlowFlags.CONDITIONALLY_CONTINUES; + if (this.is(FlowFlags.Continues)) { + condiFlags |= FlowFlags.ConditionallyContinues; } - if (this.is(FlowFlags.ACCESSES_THIS)) { - condiFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + if (this.is(FlowFlags.AccessesThis)) { + condiFlags |= FlowFlags.ConditionallyAccessesThis; } return condiFlags; } @@ -301,10 +301,10 @@ export class Flow { branch.outer = this.outer; if (resetBreakContext) { branch.flags = this.flags & ~( - FlowFlags.BREAKS | - FlowFlags.CONDITIONALLY_BREAKS | - FlowFlags.CONTINUES | - FlowFlags.CONDITIONALLY_CONTINUES + FlowFlags.Breaks | + FlowFlags.ConditionallyBreaks | + FlowFlags.Continues | + FlowFlags.ConditionallyContinues ); } else { branch.flags = this.flags; @@ -312,7 +312,7 @@ export class Flow { branch.breakLabel = this.breakLabel; } branch.localFlags = this.localFlags.slice(); - if (this.actualFunction.is(CommonFlags.CONSTRUCTOR)) { + if (this.actualFunction.is(CommonFlags.Constructor)) { let thisFieldFlags = assert(this.thisFieldFlags); branch.thisFieldFlags = cloneMap(thisFieldFlags); } else { @@ -351,7 +351,7 @@ export class Flow { while (i < k) unchecked(temps[i] = temps[i++ + 1]); temps.length = k; local.type = type; - local.flags = CommonFlags.NONE; + local.flags = CommonFlags.None; this.unsetLocalFlag(local.index, ~0); return local; } @@ -362,7 +362,7 @@ export class Flow { if (temps && temps.length > 0) { local = assert(temps.pop()); local.type = type; - local.flags = CommonFlags.NONE; + local.flags = CommonFlags.None; } else { local = parentFunction.addLocal(type); } @@ -373,7 +373,7 @@ export class Flow { /** Frees the temporary local for reuse. */ freeTempLocal(local: Local): void { - if (local.is(CommonFlags.INLINED)) return; + if (local.is(CommonFlags.Inlined)) return; assert(local.index >= 0); var parentFunction = this.parentFunction; var temps: Local[]; @@ -465,7 +465,7 @@ export class Flow { var scopedLocals = this.scopedLocals; if (!scopedLocals) this.scopedLocals = scopedLocals = new Map(); else assert(!scopedLocals.has(name)); - scopedLocal.set(CommonFlags.SCOPED); + scopedLocal.set(CommonFlags.Scoped); scopedLocals.set(name, scopedLocal); return scopedLocal; } @@ -481,7 +481,7 @@ export class Flow { declarationNode.range, name ); } - scopedDummy.set(CommonFlags.SCOPED); + scopedDummy.set(CommonFlags.Scoped); scopedLocals.set(name, scopedDummy); return scopedDummy; } @@ -524,7 +524,7 @@ export class Flow { // TODO: for (let local of scopedLocals.values()) { for (let _values = Map_values(scopedLocals), i = 0, k = _values.length; i < k; ++i) { let local = unchecked(_values[i]); - if (local.is(CommonFlags.SCOPED)) { // otherwise an alias + if (local.is(CommonFlags.Scoped)) { // otherwise an alias return true; } } @@ -548,7 +548,7 @@ export class Flow { // TODO: for (let local of scopedLocals.values()) { for (let _values = Map_values(scopedLocals), i = 0, k = _values.length; i < k; ++i) { let local = unchecked(_values[i]); - if (local.is(CommonFlags.SCOPED)) { // otherwise an alias + if (local.is(CommonFlags.Scoped)) { // otherwise an alias this.freeTempLocal(local); } } @@ -609,16 +609,16 @@ export class Flow { /** Initializes `this` field flags. */ initThisFieldFlags(): void { var actualFunction = this.actualFunction; - assert(actualFunction.is(CommonFlags.CONSTRUCTOR)); + assert(actualFunction.is(CommonFlags.Constructor)); var actualParent = actualFunction.parent; - assert(actualParent.kind == ElementKind.CLASS); + assert(actualParent.kind == ElementKind.Class); var actualClass = actualParent; this.thisFieldFlags = new Map(); var members = actualClass.members; if (members) { for (let _values = Map_values(members), i = 0, k = _values.length; i < k; ++i) { let member = _values[i]; - if (member.kind == ElementKind.FIELD) { + if (member.kind == ElementKind.Field) { let field = member; if ( // guaranteed by super @@ -628,9 +628,9 @@ export class Flow { // is initialized as a ctor parameter field.prototype.parameterIndex != -1 || // is safe to initialize with zero - field.type.isAny(TypeFlags.VALUE | TypeFlags.NULLABLE) + field.type.isAny(TypeFlags.Value | TypeFlags.Nullable) ) { - this.setThisFieldFlag(field, FieldFlags.INITIALIZED); + this.setThisFieldFlag(field, FieldFlags.Initialized); } } } @@ -650,7 +650,7 @@ export class Flow { setThisFieldFlag(field: Field, flag: FieldFlags): void { var fieldFlags = this.thisFieldFlags; if (fieldFlags) { - assert(this.actualFunction.is(CommonFlags.CONSTRUCTOR)); + assert(this.actualFunction.is(CommonFlags.Constructor)); if (fieldFlags.has(field)) { let flags = changetype(fieldFlags.get(field)); fieldFlags.set(field, flags | flag); @@ -658,7 +658,7 @@ export class Flow { fieldFlags.set(field, flag); } } else { - assert(!this.actualFunction.is(CommonFlags.CONSTRUCTOR)); + assert(!this.actualFunction.is(CommonFlags.Constructor)); } } @@ -696,13 +696,13 @@ export class Flow { // respective inner flags are irrelevant if contexts differ if (this.breakLabel != other.breakLabel) { - if (otherFlags & (FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) { - otherFlags &= ~FlowFlags.TERMINATES; + if (otherFlags & (FlowFlags.Breaks | FlowFlags.ConditionallyBreaks)) { + otherFlags &= ~FlowFlags.Terminates; } - otherFlags &= ~(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS); + otherFlags &= ~(FlowFlags.Breaks | FlowFlags.ConditionallyBreaks); } if (this.continueLabel != other.continueLabel) { - otherFlags &= ~(FlowFlags.CONTINUES | FlowFlags.CONDITIONALLY_CONTINUES); + otherFlags &= ~(FlowFlags.Continues | FlowFlags.ConditionallyContinues); } this.flags = this.flags | otherFlags; // what happens before is still true @@ -711,11 +711,11 @@ export class Flow { } /** Inherits flags of a conditional branch joining again with this one, i.e. then without else. */ - inheritBranch(other: Flow, conditionKind: ConditionKind = ConditionKind.UNKNOWN): void { + inheritBranch(other: Flow, conditionKind: ConditionKind = ConditionKind.Unknown): void { assert(other.parentFunction == this.parentFunction); switch (conditionKind) { - case ConditionKind.TRUE: this.inherit(other); // always executes - case ConditionKind.FALSE: return; // never executes + case ConditionKind.True: this.inherit(other); // always executes + case ConditionKind.False: return; // never executes } // Note that flags in `this` flow have already happened. For instance, @@ -725,73 +725,73 @@ export class Flow { var thisFlags = this.flags; var otherFlags = other.flags; - var newFlags = FlowFlags.NONE; + var newFlags = FlowFlags.None; - if (thisFlags & FlowFlags.RETURNS) { // nothing can change that - newFlags |= FlowFlags.RETURNS; - } else if (otherFlags & FlowFlags.RETURNS) { - newFlags |= FlowFlags.CONDITIONALLY_RETURNS; + if (thisFlags & FlowFlags.Returns) { // nothing can change that + newFlags |= FlowFlags.Returns; + } else if (otherFlags & FlowFlags.Returns) { + newFlags |= FlowFlags.ConditionallyReturns; } else { - newFlags |= (thisFlags | otherFlags) & FlowFlags.CONDITIONALLY_RETURNS; + newFlags |= (thisFlags | otherFlags) & FlowFlags.ConditionallyReturns; } // must be the case in both - newFlags |= thisFlags & otherFlags & FlowFlags.RETURNS_WRAPPED; - newFlags |= thisFlags & otherFlags & FlowFlags.RETURNS_NONNULL; + newFlags |= thisFlags & otherFlags & FlowFlags.ReturnsWrapped; + newFlags |= thisFlags & otherFlags & FlowFlags.ReturnsNonNull; - if (thisFlags & FlowFlags.THROWS) { // nothing can change that - newFlags |= FlowFlags.THROWS; - } else if (otherFlags & FlowFlags.THROWS) { - newFlags |= FlowFlags.CONDITIONALLY_THROWS; + if (thisFlags & FlowFlags.Throws) { // nothing can change that + newFlags |= FlowFlags.Throws; + } else if (otherFlags & FlowFlags.Throws) { + newFlags |= FlowFlags.ConditionallyThrows; } else { - newFlags |= (thisFlags | otherFlags) & FlowFlags.CONDITIONALLY_THROWS; + newFlags |= (thisFlags | otherFlags) & FlowFlags.ConditionallyThrows; } - if (thisFlags & FlowFlags.BREAKS) { // nothing can change that - newFlags |= FlowFlags.BREAKS; + if (thisFlags & FlowFlags.Breaks) { // nothing can change that + newFlags |= FlowFlags.Breaks; } else if (other.breakLabel == this.breakLabel) { - if (otherFlags & FlowFlags.BREAKS) { - newFlags |= FlowFlags.CONDITIONALLY_BREAKS; + if (otherFlags & FlowFlags.Breaks) { + newFlags |= FlowFlags.ConditionallyBreaks; } else { - newFlags |= (thisFlags | otherFlags) & FlowFlags.CONDITIONALLY_BREAKS; + newFlags |= (thisFlags | otherFlags) & FlowFlags.ConditionallyBreaks; } } else { - newFlags |= thisFlags & FlowFlags.CONDITIONALLY_BREAKS; + newFlags |= thisFlags & FlowFlags.ConditionallyBreaks; } - if (thisFlags & FlowFlags.CONTINUES) { // nothing can change that - newFlags |= FlowFlags.CONTINUES; + if (thisFlags & FlowFlags.Continues) { // nothing can change that + newFlags |= FlowFlags.Continues; } else if (other.continueLabel == this.continueLabel) { - if (otherFlags & FlowFlags.CONTINUES) { - newFlags |= FlowFlags.CONDITIONALLY_CONTINUES; + if (otherFlags & FlowFlags.Continues) { + newFlags |= FlowFlags.ConditionallyContinues; } else { - newFlags |= (thisFlags | otherFlags) & FlowFlags.CONDITIONALLY_CONTINUES; + newFlags |= (thisFlags | otherFlags) & FlowFlags.ConditionallyContinues; } } else { - newFlags |= thisFlags & FlowFlags.CONDITIONALLY_CONTINUES; + newFlags |= thisFlags & FlowFlags.ConditionallyContinues; } - if (thisFlags & FlowFlags.ACCESSES_THIS) { // can become conditional - if (otherFlags & FlowFlags.ACCESSES_THIS) { - newFlags |= FlowFlags.ACCESSES_THIS; + if (thisFlags & FlowFlags.AccessesThis) { // can become conditional + if (otherFlags & FlowFlags.AccessesThis) { + newFlags |= FlowFlags.AccessesThis; } else { - newFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + newFlags |= FlowFlags.ConditionallyAccessesThis; } - } else if (otherFlags & FlowFlags.ACCESSES_THIS) { - newFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + } else if (otherFlags & FlowFlags.AccessesThis) { + newFlags |= FlowFlags.ConditionallyAccessesThis; } // may be the case in any - newFlags |= (thisFlags | otherFlags) & FlowFlags.MAY_RETURN_NONTHIS; + newFlags |= (thisFlags | otherFlags) & FlowFlags.MayReturnNonThis; // must be the case in both - newFlags |= thisFlags & otherFlags & FlowFlags.CALLS_SUPER; + newFlags |= thisFlags & otherFlags & FlowFlags.CallsSuper; - if (thisFlags & FlowFlags.TERMINATES) { // nothing can change that - newFlags |= FlowFlags.TERMINATES; + if (thisFlags & FlowFlags.Terminates) { // nothing can change that + newFlags |= FlowFlags.Terminates; } - this.flags = newFlags | (thisFlags & (FlowFlags.UNCHECKED_CONTEXT | FlowFlags.CTORPARAM_CONTEXT)); + this.flags = newFlags | (thisFlags & (FlowFlags.UncheckedContext | FlowFlags.CtorParamContext)); // local flags var thisLocalFlags = this.localFlags; @@ -803,10 +803,10 @@ export class Flow { let thisFlags = i < numThisLocalFlags ? thisLocalFlags[i] : 0; let otherFlags = i < numOtherLocalFlags ? otherLocalFlags[i] : 0; thisLocalFlags[i] = thisFlags & otherFlags & ( - LocalFlags.CONSTANT | - LocalFlags.WRAPPED | - LocalFlags.NONNULL | - LocalFlags.INITIALIZED + LocalFlags.Constant | + LocalFlags.Wrapped | + LocalFlags.NonNull | + LocalFlags.Initialized ); } @@ -823,98 +823,98 @@ export class Flow { var leftFlags = left.flags; var rightFlags = right.flags; - var newFlags = FlowFlags.NONE; + var newFlags = FlowFlags.None; - if (leftFlags & FlowFlags.RETURNS) { - if (rightFlags & FlowFlags.RETURNS) { - newFlags |= FlowFlags.RETURNS; + if (leftFlags & FlowFlags.Returns) { + if (rightFlags & FlowFlags.Returns) { + newFlags |= FlowFlags.Returns; } else { - newFlags |= FlowFlags.CONDITIONALLY_RETURNS; + newFlags |= FlowFlags.ConditionallyReturns; } - } else if (rightFlags & FlowFlags.RETURNS) { - newFlags |= FlowFlags.CONDITIONALLY_RETURNS; + } else if (rightFlags & FlowFlags.Returns) { + newFlags |= FlowFlags.ConditionallyReturns; } else { - newFlags |= (leftFlags | rightFlags) & FlowFlags.CONDITIONALLY_RETURNS; + newFlags |= (leftFlags | rightFlags) & FlowFlags.ConditionallyReturns; } - if ((leftFlags & FlowFlags.RETURNS_WRAPPED) && (rightFlags & FlowFlags.RETURNS_WRAPPED)) { - newFlags |= FlowFlags.RETURNS_WRAPPED; + if ((leftFlags & FlowFlags.ReturnsWrapped) && (rightFlags & FlowFlags.ReturnsWrapped)) { + newFlags |= FlowFlags.ReturnsWrapped; } - if ((leftFlags & FlowFlags.RETURNS_NONNULL) && (rightFlags & FlowFlags.RETURNS_NONNULL)) { - newFlags |= FlowFlags.RETURNS_NONNULL; + if ((leftFlags & FlowFlags.ReturnsNonNull) && (rightFlags & FlowFlags.ReturnsNonNull)) { + newFlags |= FlowFlags.ReturnsNonNull; } - if (leftFlags & FlowFlags.THROWS) { - if (rightFlags & FlowFlags.THROWS) { - newFlags |= FlowFlags.THROWS; + if (leftFlags & FlowFlags.Throws) { + if (rightFlags & FlowFlags.Throws) { + newFlags |= FlowFlags.Throws; } else { - newFlags |= FlowFlags.CONDITIONALLY_THROWS; + newFlags |= FlowFlags.ConditionallyThrows; } - } else if (rightFlags & FlowFlags.THROWS) { - newFlags |= FlowFlags.CONDITIONALLY_THROWS; + } else if (rightFlags & FlowFlags.Throws) { + newFlags |= FlowFlags.ConditionallyThrows; } else { - newFlags |= (leftFlags | rightFlags) & FlowFlags.CONDITIONALLY_THROWS; + newFlags |= (leftFlags | rightFlags) & FlowFlags.ConditionallyThrows; } - if (leftFlags & FlowFlags.BREAKS) { - if (rightFlags & FlowFlags.BREAKS) { - newFlags |= FlowFlags.BREAKS; + if (leftFlags & FlowFlags.Breaks) { + if (rightFlags & FlowFlags.Breaks) { + newFlags |= FlowFlags.Breaks; } else { - newFlags |= FlowFlags.CONDITIONALLY_BREAKS; + newFlags |= FlowFlags.ConditionallyBreaks; } - } else if (rightFlags & FlowFlags.BREAKS) { - newFlags |= FlowFlags.CONDITIONALLY_BREAKS; + } else if (rightFlags & FlowFlags.Breaks) { + newFlags |= FlowFlags.ConditionallyBreaks; } else { - newFlags |= (leftFlags | rightFlags) & FlowFlags.CONDITIONALLY_BREAKS; + newFlags |= (leftFlags | rightFlags) & FlowFlags.ConditionallyBreaks; } - if (leftFlags & FlowFlags.CONTINUES) { - if (rightFlags & FlowFlags.CONTINUES) { - newFlags |= FlowFlags.CONTINUES; + if (leftFlags & FlowFlags.Continues) { + if (rightFlags & FlowFlags.Continues) { + newFlags |= FlowFlags.Continues; } else { - newFlags |= FlowFlags.CONDITIONALLY_CONTINUES; + newFlags |= FlowFlags.ConditionallyContinues; } - } else if (rightFlags & FlowFlags.CONTINUES) { - newFlags |= FlowFlags.CONDITIONALLY_CONTINUES; + } else if (rightFlags & FlowFlags.Continues) { + newFlags |= FlowFlags.ConditionallyContinues; } else { - newFlags |= (leftFlags | rightFlags) & FlowFlags.CONDITIONALLY_CONTINUES; + newFlags |= (leftFlags | rightFlags) & FlowFlags.ConditionallyContinues; } - if (leftFlags & FlowFlags.ACCESSES_THIS) { - if (rightFlags & FlowFlags.ACCESSES_THIS) { - newFlags |= FlowFlags.ACCESSES_THIS; + if (leftFlags & FlowFlags.AccessesThis) { + if (rightFlags & FlowFlags.AccessesThis) { + newFlags |= FlowFlags.AccessesThis; } else { - newFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + newFlags |= FlowFlags.ConditionallyAccessesThis; } - } else if (rightFlags & FlowFlags.ACCESSES_THIS) { - newFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + } else if (rightFlags & FlowFlags.AccessesThis) { + newFlags |= FlowFlags.ConditionallyAccessesThis; } else { - newFlags |= (leftFlags | rightFlags) & FlowFlags.CONDITIONALLY_ACCESSES_THIS; + newFlags |= (leftFlags | rightFlags) & FlowFlags.ConditionallyAccessesThis; } - newFlags |= (leftFlags | rightFlags) & FlowFlags.MAY_RETURN_NONTHIS; + newFlags |= (leftFlags | rightFlags) & FlowFlags.MayReturnNonThis; - if ((leftFlags & FlowFlags.CALLS_SUPER) && (rightFlags & FlowFlags.CALLS_SUPER)) { - newFlags |= FlowFlags.CALLS_SUPER; + if ((leftFlags & FlowFlags.CallsSuper) && (rightFlags & FlowFlags.CallsSuper)) { + newFlags |= FlowFlags.CallsSuper; } - if ((leftFlags & FlowFlags.TERMINATES) && (rightFlags & FlowFlags.TERMINATES)) { - newFlags |= FlowFlags.TERMINATES; + if ((leftFlags & FlowFlags.Terminates) && (rightFlags & FlowFlags.Terminates)) { + newFlags |= FlowFlags.Terminates; } - this.flags = newFlags | (this.flags & (FlowFlags.UNCHECKED_CONTEXT | FlowFlags.CTORPARAM_CONTEXT)); + this.flags = newFlags | (this.flags & (FlowFlags.UncheckedContext | FlowFlags.CtorParamContext)); // local flags var thisLocalFlags = this.localFlags; - if (leftFlags & FlowFlags.TERMINATES) { - if (!(rightFlags & FlowFlags.TERMINATES)) { + if (leftFlags & FlowFlags.Terminates) { + if (!(rightFlags & FlowFlags.Terminates)) { let rightLocalFlags = right.localFlags; for (let i = 0, k = rightLocalFlags.length; i < k; ++i) { thisLocalFlags[i] = rightLocalFlags[i]; } } - } else if (rightFlags & FlowFlags.TERMINATES) { + } else if (rightFlags & FlowFlags.Terminates) { let leftLocalFlags = left.localFlags; for (let i = 0, k = leftLocalFlags.length; i < k; ++i) { thisLocalFlags[i] = leftLocalFlags[i]; @@ -929,10 +929,10 @@ export class Flow { let leftFlags = i < numLeftLocalFlags ? leftLocalFlags[i] : 0; let rightFlags = i < numRightLocalFlags ? rightLocalFlags[i] : 0; thisLocalFlags[i] = leftFlags & rightFlags & ( - LocalFlags.CONSTANT | - LocalFlags.WRAPPED | - LocalFlags.NONNULL | - LocalFlags.INITIALIZED + LocalFlags.Constant | + LocalFlags.Wrapped | + LocalFlags.NonNull | + LocalFlags.Initialized ); } } @@ -946,10 +946,10 @@ export class Flow { let key = _keys[i]; let leftFlags = changetype(leftFieldFlags.get(key)); if ( - (leftFlags & FieldFlags.INITIALIZED) != 0 && rightFieldFlags.has(key) && - (changetype(rightFieldFlags.get(key)) & FieldFlags.INITIALIZED) + (leftFlags & FieldFlags.Initialized) != 0 && rightFieldFlags.has(key) && + (changetype(rightFieldFlags.get(key)) & FieldFlags.Initialized) ) { - newFieldFlags.set(key, FieldFlags.INITIALIZED); + newFieldFlags.set(key, FieldFlags.Initialized); } } this.thisFieldFlags = newFieldFlags; @@ -970,12 +970,12 @@ export class Flow { let local = localsByIndex[i]; let type = local.type; if (type.isShortIntegerValue) { - if (before.isLocalFlag(i, LocalFlags.WRAPPED) && !after.isLocalFlag(i, LocalFlags.WRAPPED)) { + if (before.isLocalFlag(i, LocalFlags.Wrapped) && !after.isLocalFlag(i, LocalFlags.Wrapped)) { return true; } } if (type.isNullableReference) { - if (before.isLocalFlag(i, LocalFlags.NONNULL) && !after.isLocalFlag(i, LocalFlags.NONNULL)) { + if (before.isLocalFlag(i, LocalFlags.NonNull) && !after.isLocalFlag(i, LocalFlags.NonNull)) { return true; } } @@ -988,11 +988,11 @@ export class Flow { var numThisLocalFlags = this.localFlags.length; var numOtherLocalFlags = other.localFlags.length; for (let i = 0, k = min(numThisLocalFlags, numOtherLocalFlags); i < k; ++i) { - if (this.isLocalFlag(i, LocalFlags.WRAPPED) != other.isLocalFlag(i, LocalFlags.WRAPPED)) { - this.unsetLocalFlag(i, LocalFlags.WRAPPED); // assume not wrapped + if (this.isLocalFlag(i, LocalFlags.Wrapped) != other.isLocalFlag(i, LocalFlags.Wrapped)) { + this.unsetLocalFlag(i, LocalFlags.Wrapped); // assume not wrapped } - if (this.isLocalFlag(i, LocalFlags.NONNULL) != other.isLocalFlag(i, LocalFlags.NONNULL)) { - this.unsetLocalFlag(i, LocalFlags.NONNULL); // assume possibly null + if (this.isLocalFlag(i, LocalFlags.NonNull) != other.isLocalFlag(i, LocalFlags.NonNull)) { + this.unsetLocalFlag(i, LocalFlags.NonNull); // assume possibly null } } } @@ -1001,17 +1001,17 @@ export class Flow { isNonnull(expr: ExpressionRef, type: Type): bool { if (!type.isNullableReference) return true; // below, only teeLocal/getLocal are relevant because these are the only expressions that - // depend on a dynamic nullable state (flag = LocalFlags.NONNULL), while everything else + // depend on a dynamic nullable state (flag = LocalFlags.NonNull), while everything else // has already been handled by the nullable type check above. switch (getExpressionId(expr)) { case ExpressionId.LocalSet: { if (!isLocalTee(expr)) break; let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)]; - return !local.type.isNullableReference || this.isLocalFlag(local.index, LocalFlags.NONNULL, false); + return !local.type.isNullableReference || this.isLocalFlag(local.index, LocalFlags.NonNull, false); } case ExpressionId.LocalGet: { let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; - return !local.type.isNullableReference || this.isLocalFlag(local.index, LocalFlags.NONNULL, false); + return !local.type.isNullableReference || this.isLocalFlag(local.index, LocalFlags.NonNull, false); } } return false; @@ -1038,16 +1038,16 @@ export class Flow { case ExpressionId.LocalSet: { if (!isLocalTee(expr)) break; let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)]; - if (!iff || iff.isLocalFlag(local.index, LocalFlags.NONNULL)) { - this.setLocalFlag(local.index, LocalFlags.NONNULL); + if (!iff || iff.isLocalFlag(local.index, LocalFlags.NonNull)) { + this.setLocalFlag(local.index, LocalFlags.NonNull); } this.inheritNonnullIfTrue(getLocalSetValue(expr), iff); // must have been true-ish as well break; } case ExpressionId.LocalGet: { let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; - if (!iff || iff.isLocalFlag(local.index, LocalFlags.NONNULL)) { - this.setLocalFlag(local.index, LocalFlags.NONNULL); + if (!iff || iff.isLocalFlag(local.index, LocalFlags.NonNull)) { + this.setLocalFlag(local.index, LocalFlags.NonNull); } break; } @@ -1240,7 +1240,7 @@ export class Flow { // overflows if the local isn't wrapped or the conversion does case ExpressionId.LocalGet: { let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; - return !this.isLocalFlag(local.index, LocalFlags.WRAPPED, true) + return !this.isLocalFlag(local.index, LocalFlags.Wrapped, true) || canConversionOverflow(local.type, type); } @@ -1254,7 +1254,7 @@ export class Flow { case ExpressionId.GlobalGet: { // TODO: this is inefficient because it has to read a string let global = assert(this.parentFunction.program.elementsByName.get(assert(getGlobalGetName(expr)))); - assert(global.kind == ElementKind.GLOBAL || global.kind == ElementKind.ENUMVALUE); + assert(global.kind == ElementKind.Global || global.kind == ElementKind.EnumValue); return canConversionOverflow((global).type, type); } @@ -1417,7 +1417,7 @@ export class Flow { default: assert(false); } switch (type.kind) { - case TypeKind.BOOL: return (value & ~1) != 0; + case TypeKind.Bool: return (value & ~1) != 0; case TypeKind.I8: return value < i8.MIN_VALUE || value > i8.MAX_VALUE; case TypeKind.I16: return value < i16.MIN_VALUE || value > i16.MAX_VALUE; case TypeKind.U8: return value < 0 || value > u8.MAX_VALUE; @@ -1469,10 +1469,10 @@ export class Flow { let instanceName = assert(getCallTarget(expr)); if (instancesByName.has(instanceName)) { let instance = assert(instancesByName.get(instanceName)); - assert(instance.kind == ElementKind.FUNCTION); + assert(instance.kind == ElementKind.Function); let functionInstance = instance; let returnType = functionInstance.signature.returnType; - return !functionInstance.flow.is(FlowFlags.RETURNS_WRAPPED) + return !functionInstance.flow.is(FlowFlags.ReturnsWrapped) || canConversionOverflow(returnType, type); } return false; // assume no overflow for builtins @@ -1492,21 +1492,21 @@ export class Flow { ++levels; } var sb = new Array(); - if (this.is(FlowFlags.RETURNS)) sb.push("RETURNS"); - if (this.is(FlowFlags.RETURNS_WRAPPED)) sb.push("RETURNS_WRAPPED"); - if (this.is(FlowFlags.RETURNS_NONNULL)) sb.push("RETURNS_NONNULL"); - if (this.is(FlowFlags.THROWS)) sb.push("THROWS"); - if (this.is(FlowFlags.BREAKS)) sb.push("BREAKS"); - if (this.is(FlowFlags.CONTINUES)) sb.push("CONTINUES"); - if (this.is(FlowFlags.ACCESSES_THIS)) sb.push("ACCESSES_THIS"); - if (this.is(FlowFlags.CALLS_SUPER)) sb.push("CALLS_SUPER"); - if (this.is(FlowFlags.TERMINATES)) sb.push("TERMINATES"); - if (this.is(FlowFlags.CONDITIONALLY_RETURNS)) sb.push("CONDITIONALLY_RETURNS"); - if (this.is(FlowFlags.CONDITIONALLY_THROWS)) sb.push("CONDITIONALLY_THROWS"); - if (this.is(FlowFlags.CONDITIONALLY_BREAKS)) sb.push("CONDITIONALLY_BREAKS"); - if (this.is(FlowFlags.CONDITIONALLY_CONTINUES)) sb.push("CONDITIONALLY_CONTINUES"); - if (this.is(FlowFlags.CONDITIONALLY_ACCESSES_THIS)) sb.push("CONDITIONALLY_ACCESSES_THIS"); - if (this.is(FlowFlags.MAY_RETURN_NONTHIS)) sb.push("MAY_RETURN_NONTHIS"); + if (this.is(FlowFlags.Returns)) sb.push("RETURNS"); + if (this.is(FlowFlags.ReturnsWrapped)) sb.push("RETURNS_WRAPPED"); + if (this.is(FlowFlags.ReturnsNonNull)) sb.push("RETURNS_NONNULL"); + if (this.is(FlowFlags.Throws)) sb.push("THROWS"); + if (this.is(FlowFlags.Breaks)) sb.push("BREAKS"); + if (this.is(FlowFlags.Continues)) sb.push("CONTINUES"); + if (this.is(FlowFlags.AccessesThis)) sb.push("ACCESSES_THIS"); + if (this.is(FlowFlags.CallsSuper)) sb.push("CALLS_SUPER"); + if (this.is(FlowFlags.Terminates)) sb.push("TERMINATES"); + if (this.is(FlowFlags.ConditionallyReturns)) sb.push("CONDITIONALLY_RETURNS"); + if (this.is(FlowFlags.ConditionallyThrows)) sb.push("CONDITIONALLY_THROWS"); + if (this.is(FlowFlags.ConditionallyBreaks)) sb.push("CONDITIONALLY_BREAKS"); + if (this.is(FlowFlags.ConditionallyContinues)) sb.push("CONDITIONALLY_CONTINUES"); + if (this.is(FlowFlags.ConditionallyAccessesThis)) sb.push("CONDITIONALLY_ACCESSES_THIS"); + if (this.is(FlowFlags.MayReturnNonThis)) sb.push("MAY_RETURN_NONTHIS"); return `Flow(${this.actualFunction})[${levels}] ${sb.join(" ")}`; } } diff --git a/src/index-wasm.ts b/src/index-wasm.ts index acb9af0a79..e0b1fd622e 100644 --- a/src/index-wasm.ts +++ b/src/index-wasm.ts @@ -166,35 +166,35 @@ export function setBundleVersion( } /** Sign extension operations. */ -export const FEATURE_SIGN_EXTENSION = Feature.SIGN_EXTENSION; +export const FEATURE_SIGN_EXTENSION = Feature.SignExtension; /** Mutable global imports and exports. */ -export const FEATURE_MUTABLE_GLOBALS = Feature.MUTABLE_GLOBALS; +export const FEATURE_MUTABLE_GLOBALS = Feature.MutableGlobals; /** Non-trapping float to int conversion operations. */ -export const FEATURE_NONTRAPPING_F2I = Feature.NONTRAPPING_F2I; +export const FEATURE_NONTRAPPING_F2I = Feature.NontrappingF2I; /** Bulk memory operations. */ -export const FEATURE_BULK_MEMORY = Feature.BULK_MEMORY; +export const FEATURE_BULK_MEMORY = Feature.BulkMemory; /** SIMD types and operations. */ -export const FEATURE_SIMD = Feature.SIMD; +export const FEATURE_SIMD = Feature.Simd; /** Threading and atomic operations. */ -export const FEATURE_THREADS = Feature.THREADS; +export const FEATURE_THREADS = Feature.Threads; /** Exception handling operations. */ -export const FEATURE_EXCEPTION_HANDLING = Feature.EXCEPTION_HANDLING; +export const FEATURE_EXCEPTION_HANDLING = Feature.ExceptionHandling; /** Tail call operations. */ -export const FEATURE_TAIL_CALLS = Feature.TAIL_CALLS; +export const FEATURE_TAIL_CALLS = Feature.TailCalls; /** Reference types. */ -export const FEATURE_REFERENCE_TYPES = Feature.REFERENCE_TYPES; +export const FEATURE_REFERENCE_TYPES = Feature.ReferenceTypes; /** Multi value types. */ -export const FEATURE_MULTI_VALUE = Feature.MULTI_VALUE; +export const FEATURE_MULTI_VALUE = Feature.MultiValue; /** Garbage collection. */ export const FEATURE_GC = Feature.GC; /** Memory64. */ -export const FEATURE_MEMORY64 = Feature.MEMORY64; +export const FEATURE_MEMORY64 = Feature.Memory64; /** Function references. */ -export const FEATURE_FUNCTION_REFERENCES = Feature.FUNCTION_REFERENCES; +export const FEATURE_FUNCTION_REFERENCES = Feature.FunctionReferences; /** Relaxed SIMD. */ -export const FEATURE_RELAXED_SIMD = Feature.RELAXED_SIMD; +export const FEATURE_RELAXED_SIMD = Feature.RelaxedSimd; /** Extended const expressions. */ -export const FEATURE_EXTENDED_CONST = Feature.EXTENDED_CONST; +export const FEATURE_EXTENDED_CONST = Feature.ExtendedConst; /** Enables a specific feature. */ export function enableFeature(options: Options, feature: Feature): void { @@ -300,17 +300,17 @@ export function getSourceNormalizedPath(source: Source): string { /** Tests whether a diagnostic is informatory. */ export function isInfo(message: DiagnosticMessage): bool { - return message.category == DiagnosticCategory.INFO; + return message.category == DiagnosticCategory.Info; } /** Tests whether a diagnostic is a warning. */ export function isWarning(message: DiagnosticMessage): bool { - return message.category == DiagnosticCategory.WARNING; + return message.category == DiagnosticCategory.Warning; } /** Tests whether a diagnostic is an error. */ export function isError(message: DiagnosticMessage): bool { - return message.category == DiagnosticCategory.ERROR; + return message.category == DiagnosticCategory.Error; } // Parser diff --git a/src/module.ts b/src/module.ts index 43530296bb..4f8be2501d 100644 --- a/src/module.ts +++ b/src/module.ts @@ -98,7 +98,7 @@ export const enum FeatureFlags { Atomics = 1 /* _BinaryenFeatureAtomics */, MutableGlobals = 2 /* _BinaryenFeatureMutableGlobals */, TruncSat = 4 /* _BinaryenFeatureNontrappingFPToInt */, - SIMD = 8 /* _BinaryenFeatureSIMD128 */, + Simd = 8 /* _BinaryenFeatureSIMD128 */, BulkMemory = 16 /* _BinaryenFeatureBulkMemory */, SignExt = 32 /* _BinaryenFeatureSignExt */, ExceptionHandling = 64 /* _BinaryenFeatureExceptionHandling */, @@ -108,7 +108,7 @@ export const enum FeatureFlags { GC = 1024 /* _BinaryenFeatureGC */, Memory64 = 2048 /* _BinaryenFeatureMemory64 */, FunctionReferences = 4096 /* _BinaryenFeatureTypedFunctionReferences */, - RelaxedSIMD = 16384 /* _BinaryenFeatureRelaxedSIMD */, + RelaxedSimd = 16384 /* _BinaryenFeatureRelaxedSIMD */, ExtendedConst = 32768 /* _BinaryenFeatureExtendedConst */, Strings = 65536 /* _BinaryenFeatureStrings */, All = 253951 /* _BinaryenFeatureAll */ @@ -2258,7 +2258,7 @@ export class Module { let offset = segment.offset; unchecked(segs[i] = allocU8Array(buffer)); unchecked(psvs[i] = 0); // no passive segments currently - unchecked(offs[i] = target == Target.WASM64 + unchecked(offs[i] = target == Target.Wasm64 ? this.i64(i64_low(offset), i64_high(offset)) : this.i32(i64_low(offset)) ); @@ -3396,7 +3396,7 @@ function allocU32Array(u32s: u32[] | null): usize { export function allocPtrArray(ptrs: usize[] | null): usize { if (!ptrs) return 0; // TODO: WASM64 - assert(ASC_TARGET != Target.WASM64); + assert(ASC_TARGET != Target.Wasm64); var len = ptrs.length; var ptr = binaryen._malloc(len << 2); var idx = ptr; diff --git a/src/parser.ts b/src/parser.ts index 73f0751bd7..621423bb4c 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -197,7 +197,7 @@ export class Parser extends DiagnosticEmitter { tn: Tokenizer, namespace: NamespaceDeclaration | null = null ): Statement | null { - var flags = namespace ? namespace.flags & CommonFlags.AMBIENT : CommonFlags.NONE; + var flags = namespace ? namespace.flags & CommonFlags.Ambient : CommonFlags.None; var startPos = -1; // check decorators @@ -220,7 +220,7 @@ export class Parser extends DiagnosticEmitter { var defaultEnd = 0; if (tn.skip(Token.EXPORT)) { if (startPos < 0) startPos = tn.tokenPos; - flags |= CommonFlags.EXPORT; + flags |= CommonFlags.Export; exportStart = tn.tokenPos; exportEnd = tn.pos; if (tn.skip(Token.DEFAULT)) { @@ -231,7 +231,7 @@ export class Parser extends DiagnosticEmitter { var declareStart = 0; var declareEnd = 0; - var contextIsAmbient = namespace != null && namespace.is(CommonFlags.AMBIENT); + var contextIsAmbient = namespace != null && namespace.is(CommonFlags.Ambient); if (tn.skip(Token.DECLARE)) { if (contextIsAmbient) { this.error( @@ -242,10 +242,10 @@ export class Parser extends DiagnosticEmitter { if (startPos < 0) startPos = tn.tokenPos; declareStart = startPos; declareEnd = tn.pos; - flags |= CommonFlags.DECLARE | CommonFlags.AMBIENT; + flags |= CommonFlags.Declare | CommonFlags.Ambient; } } else if (contextIsAmbient) { - flags |= CommonFlags.AMBIENT; + flags |= CommonFlags.Ambient; } // parse the statement @@ -257,7 +257,7 @@ export class Parser extends DiagnosticEmitter { switch (first) { case Token.CONST: { tn.next(); - flags |= CommonFlags.CONST; + flags |= CommonFlags.Const; if (tn.skip(Token.ENUM)) { statement = this.parseEnum(tn, flags, decorators, startPos); } else { @@ -266,7 +266,7 @@ export class Parser extends DiagnosticEmitter { decorators = null; break; } - case Token.LET: flags |= CommonFlags.LET; + case Token.LET: flags |= CommonFlags.Let; case Token.VAR: { tn.next(); statement = this.parseVariable(tn, flags, decorators, startPos); @@ -309,7 +309,7 @@ export class Parser extends DiagnosticEmitter { } else { tn.discard(state); } - flags |= CommonFlags.ABSTRACT; + flags |= CommonFlags.Abstract; // fall through } case Token.CLASS: @@ -334,8 +334,8 @@ export class Parser extends DiagnosticEmitter { } case Token.IMPORT: { tn.next(); - flags |= CommonFlags.IMPORT; - if (flags & CommonFlags.EXPORT) { + flags |= CommonFlags.Import; + if (flags & CommonFlags.Export) { statement = this.parseExportImport(tn, startPos); } else { statement = this.parseImport(tn); @@ -370,7 +370,7 @@ export class Parser extends DiagnosticEmitter { default: { // handle plain exports - if (flags & CommonFlags.EXPORT) { + if (flags & CommonFlags.Export) { if (defaultEnd && tn.skipIdentifier(IdentifierHandling.PREFER)) { if (declareEnd) { this.error( @@ -381,7 +381,7 @@ export class Parser extends DiagnosticEmitter { statement = this.parseExportDefaultAlias(tn, startPos, defaultStart, defaultEnd); defaultStart = defaultEnd = 0; // consume } else { - statement = this.parseExport(tn, startPos, (flags & CommonFlags.DECLARE) != 0); + statement = this.parseExport(tn, startPos, (flags & CommonFlags.Declare) != 0); } // handle non-declaration statements @@ -419,11 +419,11 @@ export class Parser extends DiagnosticEmitter { // check if this an `export default` declaration if (defaultEnd && statement != null) { switch (statement.kind) { - case NodeKind.ENUMDECLARATION: - case NodeKind.FUNCTIONDECLARATION: - case NodeKind.CLASSDECLARATION: - case NodeKind.INTERFACEDECLARATION: - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.EnumDeclaration: + case NodeKind.FunctionDeclaration: + case NodeKind.ClassDeclaration: + case NodeKind.InterfaceDeclaration: + case NodeKind.NamespaceDeclaration: { return Node.createExportDefaultStatement(statement, tn.range(startPos, tn.pos)); } default: { @@ -732,7 +732,7 @@ export class Parser extends DiagnosticEmitter { tn.discard(state); let type = this.parseType(tn, false); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -967,7 +967,7 @@ export class Parser extends DiagnosticEmitter { } var flags = parentFlags; if (tn.skip(Token.EXCLAMATION)) { - flags |= CommonFlags.DEFINITELY_ASSIGNED; + flags |= CommonFlags.DefinitelyAssigned; } var type: TypeNode | null = null; @@ -977,7 +977,7 @@ export class Parser extends DiagnosticEmitter { var initializer: Expression | null = null; if (tn.skip(Token.EQUALS)) { - if (flags & CommonFlags.AMBIENT) { + if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts, tn.range() @@ -986,8 +986,8 @@ export class Parser extends DiagnosticEmitter { initializer = this.parseExpression(tn, Precedence.COMMA + 1); if (!initializer) return null; } else if (!isFor) { - if (flags & CommonFlags.CONST) { - if (!(flags & CommonFlags.AMBIENT)) { + if (flags & CommonFlags.Const) { + if (!(flags & CommonFlags.Ambient)) { this.error( DiagnosticCode._const_declarations_must_be_initialized, identifier.range @@ -1001,7 +1001,7 @@ export class Parser extends DiagnosticEmitter { } } var range = Range.join(identifier.range, tn.range()); - if (initializer && (flags & CommonFlags.DEFINITELY_ASSIGNED) != 0) { + if (initializer && (flags & CommonFlags.DefinitelyAssigned) != 0) { this.error( DiagnosticCode.A_definite_assignment_assertion_is_not_permitted_in_this_context, range @@ -1043,7 +1043,7 @@ export class Parser extends DiagnosticEmitter { } var members = new Array(); while (!tn.skip(Token.CLOSEBRACE)) { - let member = this.parseEnumValue(tn, CommonFlags.NONE); + let member = this.parseEnumValue(tn, CommonFlags.None); if (!member) return null; members.push(member); if (!tn.skip(Token.COMMA)) { @@ -1177,7 +1177,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.EXTENDS)) { let type = this.parseType(tn); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1190,7 +1190,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.EQUALS)) { let type = this.parseType(tn); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1235,7 +1235,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { thisType = this.parseType(tn); // reports if (!thisType) return null; - if (thisType.kind == NodeKind.NAMEDTYPE) { + if (thisType.kind == NodeKind.NamedType) { this.parseParametersThis = thisType; } else { this.error( @@ -1318,17 +1318,17 @@ export class Parser extends DiagnosticEmitter { var isRest = false; var isOptional = false; var startRange: Range | null = null; - var accessFlags: CommonFlags = CommonFlags.NONE; + var accessFlags: CommonFlags = CommonFlags.None; if (isConstructor) { if (tn.skip(Token.PUBLIC)) { startRange = tn.range(); - accessFlags |= CommonFlags.PUBLIC; + accessFlags |= CommonFlags.Public; } else if (tn.skip(Token.PROTECTED)) { startRange = tn.range(); - accessFlags |= CommonFlags.PROTECTED; + accessFlags |= CommonFlags.Protected; } else if (tn.skip(Token.PRIVATE)) { startRange = tn.range(); - accessFlags |= CommonFlags.PRIVATE; + accessFlags |= CommonFlags.Private; } if (tn.peek() == Token.READONLY) { let state = tn.mark(); @@ -1336,7 +1336,7 @@ export class Parser extends DiagnosticEmitter { if (tn.peek() != Token.COLON) { // modifier tn.discard(state); if (!startRange) startRange = tn.range(); - accessFlags |= CommonFlags.READONLY; + accessFlags |= CommonFlags.Readonly; } else { // identifier tn.reset(state); } @@ -1442,7 +1442,7 @@ export class Parser extends DiagnosticEmitter { signatureStart = tn.tokenPos; typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; - flags |= CommonFlags.GENERIC; + flags |= CommonFlags.Generic; } if (!tn.skip(Token.OPENPAREN)) { @@ -1461,7 +1461,7 @@ export class Parser extends DiagnosticEmitter { if (!parameters) return null; var thisType = this.parseParametersThis; - var isSetter = (flags & CommonFlags.SET) != 0; + var isSetter = (flags & CommonFlags.Set) != 0; if (isSetter) { if (parameters.length != 1) { this.error( @@ -1477,7 +1477,7 @@ export class Parser extends DiagnosticEmitter { } } - if (flags & CommonFlags.GET) { + if (flags & CommonFlags.Get) { if (parameters.length) { this.error( DiagnosticCode.A_get_accessor_cannot_have_parameters, @@ -1514,7 +1514,7 @@ export class Parser extends DiagnosticEmitter { var body: Statement | null = null; if (tn.skip(Token.OPENBRACE)) { - if (flags & CommonFlags.AMBIENT) { + if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, tn.range() @@ -1523,7 +1523,7 @@ export class Parser extends DiagnosticEmitter { body = this.parseBlockStatement(tn, false); if (!body) return null; - } else if (!(flags & CommonFlags.AMBIENT)) { + } else if (!(flags & CommonFlags.Ambient)) { this.error( DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration, tn.range(tn.pos) @@ -1537,7 +1537,7 @@ export class Parser extends DiagnosticEmitter { typeParameters, signature, body, - ArrowKind.NONE, + ArrowKind.None, tn.range(startPos, tn.pos) ); ret.overriddenModuleName = this.currentModuleName; @@ -1548,7 +1548,7 @@ export class Parser extends DiagnosticEmitter { parseFunctionExpression(tn: Tokenizer): FunctionExpression | null { var startPos = tn.tokenPos; var name: IdentifierExpression; - var arrowKind = ArrowKind.NONE; + var arrowKind = ArrowKind.None; // either at 'function': // Identifier? @@ -1574,7 +1574,7 @@ export class Parser extends DiagnosticEmitter { // Statement } else { - arrowKind = ArrowKind.ARROW_PARENTHESIZED; + arrowKind = ArrowKind.Parenthesized; assert(tn.token == Token.OPENPAREN); name = Node.createEmptyIdentifierExpression(tn.range(tn.tokenPos)); } @@ -1601,7 +1601,7 @@ export class Parser extends DiagnosticEmitter { if (signatureStart < 0) signatureStart = startPos; var returnType: TypeNode | null = null; - if (arrowKind != ArrowKind.ARROW_SINGLE && tn.skip(Token.COLON)) { + if (arrowKind != ArrowKind.Single && tn.skip(Token.COLON)) { returnType = this.parseType(tn); if (!returnType) return null; } else { @@ -1649,7 +1649,7 @@ export class Parser extends DiagnosticEmitter { var declaration = Node.createFunctionDeclaration( name, null, - CommonFlags.NONE, + CommonFlags.None, null, signature, body, @@ -1692,14 +1692,14 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.LESSTHAN)) { typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; - flags |= CommonFlags.GENERIC; + flags |= CommonFlags.Generic; } var extendsType: NamedTypeNode | null = null; if (tn.skip(Token.EXTENDS)) { let type = this.parseType(tn); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1720,7 +1720,7 @@ export class Parser extends DiagnosticEmitter { do { let type = this.parseType(tn); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1772,7 +1772,7 @@ export class Parser extends DiagnosticEmitter { do { let member = this.parseClassMember(tn, declaration); if (member) { - if (member.kind == NodeKind.INDEXSIGNATURE) { + if (member.kind == NodeKind.IndexSignature) { declaration.indexSignature = member; } else { assert(member instanceof DeclarationStatement); @@ -1820,7 +1820,7 @@ export class Parser extends DiagnosticEmitter { var declaration = Node.createClassDeclaration( name, null, - CommonFlags.NONE, + CommonFlags.None, null, null, null, @@ -1831,7 +1831,7 @@ export class Parser extends DiagnosticEmitter { do { let member = this.parseClassMember(tn, declaration); if (member) { - if (member.kind == NodeKind.INDEXSIGNATURE) { + if (member.kind == NodeKind.IndexSignature) { declaration.indexSignature = member; } else { assert(declaration instanceof DeclarationStatement); @@ -1867,7 +1867,7 @@ export class Parser extends DiagnosticEmitter { // ('get' | 'set')? // Identifier ... - var isInterface = parent.kind == NodeKind.INTERFACEDECLARATION; + var isInterface = parent.kind == NodeKind.InterfaceDeclaration; var startPos = 0; var decorators: DecoratorNode[] | null = null; if (tn.skip(Token.AT)) { @@ -1887,14 +1887,14 @@ export class Parser extends DiagnosticEmitter { } // inherit ambient status - var flags = parent.flags & CommonFlags.AMBIENT; + var flags = parent.flags & CommonFlags.Ambient; // implemented methods are virtual - if (isInterface) flags |= CommonFlags.VIRTUAL; + if (isInterface) flags |= CommonFlags.Virtual; var declareStart = 0; var declareEnd = 0; - var contextIsAmbient = parent.is(CommonFlags.AMBIENT); + var contextIsAmbient = parent.is(CommonFlags.Ambient); if (tn.skip(Token.DECLARE)) { if (isInterface) { this.error( @@ -1908,14 +1908,14 @@ export class Parser extends DiagnosticEmitter { tn.range() ); // recoverable } else { - flags |= CommonFlags.DECLARE | CommonFlags.AMBIENT; + flags |= CommonFlags.Declare | CommonFlags.Ambient; declareStart = tn.tokenPos; declareEnd = tn.pos; } } if (!startPos) startPos = tn.tokenPos; } else if (contextIsAmbient) { - flags |= CommonFlags.AMBIENT; + flags |= CommonFlags.Ambient; } var accessStart = 0; @@ -1927,7 +1927,7 @@ export class Parser extends DiagnosticEmitter { tn.range(), "public" ); } else { - flags |= CommonFlags.PUBLIC; + flags |= CommonFlags.Public; accessStart = tn.tokenPos; accessEnd = tn.pos; } @@ -1939,7 +1939,7 @@ export class Parser extends DiagnosticEmitter { tn.range(), "private" ); } else { - flags |= CommonFlags.PRIVATE; + flags |= CommonFlags.Private; accessStart = tn.tokenPos; accessEnd = tn.pos; } @@ -1951,7 +1951,7 @@ export class Parser extends DiagnosticEmitter { tn.range(), "protected" ); } else { - flags |= CommonFlags.PROTECTED; + flags |= CommonFlags.Protected; accessStart = tn.tokenPos; accessEnd = tn.pos; } @@ -1969,27 +1969,27 @@ export class Parser extends DiagnosticEmitter { tn.range(), "static" ); } else { - flags |= CommonFlags.STATIC; + flags |= CommonFlags.Static; staticStart = tn.tokenPos; staticEnd = tn.pos; } if (!startPos) startPos = tn.tokenPos; } else { - flags |= CommonFlags.INSTANCE; + flags |= CommonFlags.Instance; if (tn.skip(Token.ABSTRACT)) { - if (isInterface || !parent.is(CommonFlags.ABSTRACT)) { + if (isInterface || !parent.is(CommonFlags.Abstract)) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(), "abstract" ); } else { - flags |= CommonFlags.ABSTRACT; + flags |= CommonFlags.Abstract; abstractStart = tn.tokenPos; abstractEnd = tn.pos; } if (!startPos) startPos = tn.tokenPos; } - if (parent.flags & CommonFlags.GENERIC) flags |= CommonFlags.GENERIC_CONTEXT; + if (parent.flags & CommonFlags.Generic) flags |= CommonFlags.GenericContext; } var overrideStart = 0; @@ -2001,7 +2001,7 @@ export class Parser extends DiagnosticEmitter { tn.range(), "override" ); } else { - flags |= CommonFlags.OVERRIDE; + flags |= CommonFlags.Override; overrideStart = tn.tokenPos; overrideEnd = tn.pos; } @@ -2015,7 +2015,7 @@ export class Parser extends DiagnosticEmitter { tn.next(); if (tn.peek() != Token.COLON) { // modifier tn.discard(state); - flags |= CommonFlags.READONLY; + flags |= CommonFlags.Readonly; readonlyStart = tn.tokenPos; readonlyEnd = tn.pos; if (!startPos) startPos = readonlyStart; @@ -2036,12 +2036,12 @@ export class Parser extends DiagnosticEmitter { if (!isInterface) { if (tn.skip(Token.GET)) { if (tn.peek(true, IdentifierHandling.PREFER) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { - flags |= CommonFlags.GET; + flags |= CommonFlags.Get; isGetter = true; getStart = tn.tokenPos; getEnd = tn.pos; if (!startPos) startPos = getStart; - if (flags & CommonFlags.READONLY) { + if (flags & CommonFlags.Readonly) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(readonlyStart, readonlyEnd), "readonly" @@ -2052,12 +2052,12 @@ export class Parser extends DiagnosticEmitter { } } else if (tn.skip(Token.SET)) { if (tn.peek(true, IdentifierHandling.PREFER) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { - flags |= CommonFlags.SET; + flags |= CommonFlags.Set; isSetter = true; setStart = tn.tokenPos; setEnd = tn.pos; if (!startPos) startPos = setStart; - if (flags & CommonFlags.READONLY) { + if (flags & CommonFlags.Readonly) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(readonlyStart, readonlyEnd), "readonly" @@ -2067,22 +2067,22 @@ export class Parser extends DiagnosticEmitter { tn.reset(state); } } else if (tn.skip(Token.CONSTRUCTOR)) { - flags |= CommonFlags.CONSTRUCTOR; + flags |= CommonFlags.Constructor; isConstructor = true; if (!startPos) startPos = tn.tokenPos; - if (flags & CommonFlags.STATIC) { + if (flags & CommonFlags.Static) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(staticStart, staticEnd), "static" ); // recoverable } - if (flags & CommonFlags.ABSTRACT) { + if (flags & CommonFlags.Abstract) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(abstractStart, abstractEnd), "abstract" ); // recoverable } - if (flags & CommonFlags.READONLY) { + if (flags & CommonFlags.Readonly) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(readonlyStart, readonlyEnd), "readonly" @@ -2099,35 +2099,35 @@ export class Parser extends DiagnosticEmitter { if (!isGetterOrSetter && tn.skip(Token.OPENBRACKET)) { if (!startPos) startPos = tn.tokenPos; // TODO: also handle symbols, which might have some of these modifiers - if (flags & CommonFlags.PUBLIC) { + if (flags & CommonFlags.Public) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(accessStart, accessEnd), "public" ); // recoverable - } else if (flags & CommonFlags.PROTECTED) { + } else if (flags & CommonFlags.Protected) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(accessStart, accessEnd), "protected" ); // recoverable - } else if (flags & CommonFlags.PRIVATE) { + } else if (flags & CommonFlags.Private) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(accessStart, accessEnd), "private" ); // recoverable } - if (flags & CommonFlags.STATIC) { + if (flags & CommonFlags.Static) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(staticStart, staticEnd), "static" ); // recoverable } - if (flags & CommonFlags.OVERRIDE) { + if (flags & CommonFlags.Override) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(overrideStart, overrideEnd), "override" ); } - if (flags & CommonFlags.ABSTRACT) { + if (flags & CommonFlags.Abstract) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(abstractStart, abstractEnd), "abstract" @@ -2135,7 +2135,7 @@ export class Parser extends DiagnosticEmitter { } let retIndex = this.parseIndexSignature(tn, flags, decorators); if (!retIndex) { - if (flags & CommonFlags.READONLY) { + if (flags & CommonFlags.Readonly) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(readonlyStart, readonlyEnd), "readonly" @@ -2172,13 +2172,13 @@ export class Parser extends DiagnosticEmitter { tn.range(typeParametersStart, tn.pos) ); // recoverable } else { - flags |= CommonFlags.GENERIC; + flags |= CommonFlags.Generic; } } // method: '(' Parameters (':' Type)? '{' Statement* '}' ';'? if (tn.skip(Token.OPENPAREN)) { - if (flags & CommonFlags.DECLARE) { + if (flags & CommonFlags.Declare) { this.error( DiagnosticCode._0_modifier_cannot_appear_on_class_elements_of_this_kind, tn.range(declareStart, declareEnd), "declare" @@ -2193,15 +2193,15 @@ export class Parser extends DiagnosticEmitter { for (let i = 0, k = parameters.length; i < k; ++i) { let parameter = parameters[i]; if (parameter.isAny( - CommonFlags.PUBLIC | - CommonFlags.PROTECTED | - CommonFlags.PRIVATE | - CommonFlags.READONLY + CommonFlags.Public | + CommonFlags.Protected | + CommonFlags.Private | + CommonFlags.Readonly )) { let implicitFieldDeclaration = Node.createFieldDeclaration( parameter.name, null, - parameter.flags | CommonFlags.INSTANCE, + parameter.flags | CommonFlags.Instance, parameter.type, null, // initialized via parameter parameter.range @@ -2240,7 +2240,7 @@ export class Parser extends DiagnosticEmitter { let returnType: TypeNode | null = null; if (tn.skip(Token.COLON)) { - if (name.kind == NodeKind.CONSTRUCTOR) { + if (name.kind == NodeKind.Constructor) { this.error( DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration, tn.range() @@ -2251,11 +2251,11 @@ export class Parser extends DiagnosticEmitter { tn.range() ); } - returnType = this.parseType(tn, isSetter || name.kind == NodeKind.CONSTRUCTOR); + returnType = this.parseType(tn, isSetter || name.kind == NodeKind.Constructor); if (!returnType) return null; } else { returnType = Node.createOmittedType(tn.range(tn.pos)); - if (!isSetter && name.kind != NodeKind.CONSTRUCTOR) { + if (!isSetter && name.kind != NodeKind.Constructor) { this.error( DiagnosticCode.Type_expected, returnType.range @@ -2273,12 +2273,12 @@ export class Parser extends DiagnosticEmitter { let body: Statement | null = null; if (tn.skip(Token.OPENBRACE)) { - if (flags & CommonFlags.AMBIENT) { + if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, tn.range() ); // recoverable - } else if (flags & CommonFlags.ABSTRACT) { + } else if (flags & CommonFlags.Abstract) { this.error( DiagnosticCode.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, tn.range(), name.text @@ -2291,7 +2291,7 @@ export class Parser extends DiagnosticEmitter { } body = this.parseBlockStatement(tn, false); if (!body) return null; - } else if (!isInterface && !(flags & (CommonFlags.AMBIENT | CommonFlags.ABSTRACT))) { + } else if (!isInterface && !(flags & (CommonFlags.Ambient | CommonFlags.Abstract))) { this.error( DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration, tn.range() @@ -2326,28 +2326,28 @@ export class Parser extends DiagnosticEmitter { // field: (':' Type)? ('=' Expression)? ';'? } else { - if (flags & CommonFlags.DECLARE) { + if (flags & CommonFlags.Declare) { this.error( DiagnosticCode.Not_implemented_0, tn.range(declareStart, declareEnd), "Ambient fields" ); // recoverable } - if (flags & CommonFlags.ABSTRACT) { + if (flags & CommonFlags.Abstract) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(abstractStart, abstractEnd), "abstract" ); // recoverable } - if (flags & CommonFlags.GET) { + if (flags & CommonFlags.Get) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(getStart, getEnd), "get" ); // recoverable } - if (flags & CommonFlags.SET) { + if (flags & CommonFlags.Set) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(setStart, setEnd), "set" @@ -2362,7 +2362,7 @@ export class Parser extends DiagnosticEmitter { ); } if (tn.skip(Token.EXCLAMATION)) { - flags |= CommonFlags.DEFINITELY_ASSIGNED; + flags |= CommonFlags.DefinitelyAssigned; } if (tn.skip(Token.COLON)) { type = this.parseType(tn); @@ -2375,7 +2375,7 @@ export class Parser extends DiagnosticEmitter { } let initializer: Expression | null = null; if (tn.skip(Token.EQUALS)) { - if (flags & CommonFlags.AMBIENT) { + if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts, tn.range() @@ -2386,8 +2386,8 @@ export class Parser extends DiagnosticEmitter { } let range = tn.range(startPos, tn.pos); if ( - (flags & CommonFlags.DEFINITELY_ASSIGNED) != 0 && - (isInterface || initializer || (flags & CommonFlags.STATIC) != 0) + (flags & CommonFlags.DefinitelyAssigned) != 0 && + (isInterface || initializer || (flags & CommonFlags.Static) != 0) ) { this.error( DiagnosticCode.A_definite_assignment_assertion_is_not_permitted_in_this_context, @@ -2432,7 +2432,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { let keyType = this.parseType(tn); if (!keyType) return null; - if (keyType.kind != NodeKind.NAMEDTYPE) { + if (keyType.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Type_expected, tn.range() @@ -2443,7 +2443,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { let valueType = this.parseType(tn); if (!valueType) return null; - if (valueType.kind != NodeKind.NAMEDTYPE) { + if (valueType.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, valueType.range @@ -2507,7 +2507,7 @@ export class Parser extends DiagnosticEmitter { while (!tn.skip(Token.CLOSEBRACE)) { let member = this.parseTopLevelStatement(tn, declaration); if (member) { - if (member.kind == NodeKind.EXPORT) { + if (member.kind == NodeKind.Export) { this.error( DiagnosticCode.A_default_export_can_only_be_used_in_a_module, member.range, @@ -2891,7 +2891,7 @@ export class Parser extends DiagnosticEmitter { break; } case Token.CONST: { - statement = this.parseVariable(tn, CommonFlags.CONST, null, tn.tokenPos); + statement = this.parseVariable(tn, CommonFlags.Const, null, tn.tokenPos); break; } case Token.CONTINUE: { @@ -2911,11 +2911,11 @@ export class Parser extends DiagnosticEmitter { break; } case Token.LET: { - statement = this.parseVariable(tn, CommonFlags.LET, null, tn.tokenPos); + statement = this.parseVariable(tn, CommonFlags.Let, null, tn.tokenPos); break; } case Token.VAR: { - statement = this.parseVariable(tn, CommonFlags.NONE, null, tn.tokenPos); + statement = this.parseVariable(tn, CommonFlags.None, null, tn.tokenPos); break; } case Token.OPENBRACE: { @@ -2957,7 +2957,7 @@ export class Parser extends DiagnosticEmitter { } case Token.TYPE: { // also identifier if (tn.peek(false, IdentifierHandling.PREFER) == Token.IDENTIFIER) { - statement = this.parseTypeDeclaration(tn, CommonFlags.NONE, null, tn.tokenPos); + statement = this.parseTypeDeclaration(tn, CommonFlags.None, null, tn.tokenPos); break; } // fall-through @@ -3102,11 +3102,11 @@ export class Parser extends DiagnosticEmitter { let initializer: Statement | null = null; if (tn.skip(Token.CONST)) { - initializer = this.parseVariable(tn, CommonFlags.CONST, null, tn.tokenPos, true); + initializer = this.parseVariable(tn, CommonFlags.Const, null, tn.tokenPos, true); } else if (tn.skip(Token.LET)) { - initializer = this.parseVariable(tn, CommonFlags.LET, null, tn.tokenPos, true); + initializer = this.parseVariable(tn, CommonFlags.Let, null, tn.tokenPos, true); } else if (tn.skip(Token.VAR)) { - initializer = this.parseVariable(tn, CommonFlags.NONE, null, tn.tokenPos, true); + initializer = this.parseVariable(tn, CommonFlags.None, null, tn.tokenPos, true); } else if (!tn.skip(Token.SEMICOLON)) { initializer = this.parseExpressionStatement(tn); @@ -3116,8 +3116,8 @@ export class Parser extends DiagnosticEmitter { if (initializer) { if (tn.skip(Token.OF)) { // TODO: for (let [key, val] of ...) - if (initializer.kind == NodeKind.EXPRESSION) { - if ((initializer).expression.kind != NodeKind.IDENTIFIER) { + if (initializer.kind == NodeKind.Expression) { + if ((initializer).expression.kind != NodeKind.Identifier) { this.error( DiagnosticCode.Identifier_expected, initializer.range @@ -3126,7 +3126,7 @@ export class Parser extends DiagnosticEmitter { } return this.parseForOfStatement(tn, startPos, initializer); } - if (initializer.kind == NodeKind.VARIABLE) { + if (initializer.kind == NodeKind.Variable) { let declarations = (initializer).declarations; for (let i = 0, k = declarations.length; i < k; ++i) { let declaration = declarations[i]; @@ -3147,12 +3147,12 @@ export class Parser extends DiagnosticEmitter { return null; } // non-for..of needs type or initializer - if (initializer.kind == NodeKind.VARIABLE) { + if (initializer.kind == NodeKind.Variable) { let declarations = (initializer).declarations; for (let i = 0, k = declarations.length; i < k; ++i) { let declaration = declarations[i]; if (!declaration.initializer) { - if (declaration.flags & CommonFlags.CONST) { + if (declaration.flags & CommonFlags.Const) { this.error( DiagnosticCode._const_declarations_must_be_initialized, declaration.name.range @@ -3515,7 +3515,7 @@ export class Parser extends DiagnosticEmitter { depth: i32 = 0 ): i32 { switch (type.kind) { - case NodeKind.NAMEDTYPE: { + case NodeKind.NamedType: { let typeArguments = (type).typeArguments; if (typeArguments) { for (let i = 0, k = typeArguments.length; i < k; i++) { @@ -3528,7 +3528,7 @@ export class Parser extends DiagnosticEmitter { } break; } - case NodeKind.FUNCTIONTYPE: { + case NodeKind.FunctionType: { let fnType = type; let res = this.getRecursiveDepthForTypeDeclaration(identifierName, fnType.returnType, depth + 1); if (res != -1) return res; @@ -3558,7 +3558,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.LESSTHAN)) { typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; - flags |= CommonFlags.GENERIC; + flags |= CommonFlags.Generic; } if (tn.skip(Token.EQUALS)) { tn.skip(Token.BAR); @@ -3696,9 +3696,9 @@ export class Parser extends DiagnosticEmitter { let operand = this.parseExpression(tn, Precedence.UNARY_PREFIX); if (!operand) return null; switch (operand.kind) { - case NodeKind.IDENTIFIER: - case NodeKind.ELEMENTACCESS: - case NodeKind.PROPERTYACCESS: break; + case NodeKind.Identifier: + case NodeKind.ElementAccess: + case NodeKind.PropertyAccess: break; default: { this.error( DiagnosticCode.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access, @@ -3756,7 +3756,7 @@ export class Parser extends DiagnosticEmitter { Node.createEmptyIdentifierExpression(tn.range(startPos)), [], null, - ArrowKind.ARROW_PARENTHESIZED + ArrowKind.Parenthesized ); } let state = tn.mark(); @@ -3925,7 +3925,7 @@ export class Parser extends DiagnosticEmitter { let expr = this.parseExpression(tn, Precedence.CALL); if (!expr) return null; return Node.createAssertionExpression( - AssertionKind.PREFIX, + AssertionKind.Prefix, expr, toType, tn.range(startPos, tn.pos) @@ -3952,7 +3952,7 @@ export class Parser extends DiagnosticEmitter { ) ], null, - ArrowKind.ARROW_SINGLE, + ArrowKind.Single, startPos ); } @@ -4112,7 +4112,7 @@ export class Parser extends DiagnosticEmitter { case Token.AS: { if (tn.skip(Token.CONST)) { expr = Node.createAssertionExpression( - AssertionKind.CONST, + AssertionKind.Const, expr, null, tn.range(startPos, tn.pos) @@ -4121,7 +4121,7 @@ export class Parser extends DiagnosticEmitter { let toType = this.parseType(tn); // reports if (!toType) return null; expr = Node.createAssertionExpression( - AssertionKind.AS, + AssertionKind.As, expr, toType, tn.range(startPos, tn.pos) @@ -4131,7 +4131,7 @@ export class Parser extends DiagnosticEmitter { } case Token.EXCLAMATION: { expr = Node.createAssertionExpression( - AssertionKind.NONNULL, + AssertionKind.NonNull, expr, null, tn.range(startPos, tn.pos) @@ -4173,9 +4173,9 @@ export class Parser extends DiagnosticEmitter { case Token.PLUS_PLUS: case Token.MINUS_MINUS: { if ( - expr.kind != NodeKind.IDENTIFIER && - expr.kind != NodeKind.ELEMENTACCESS && - expr.kind != NodeKind.PROPERTYACCESS + expr.kind != NodeKind.Identifier && + expr.kind != NodeKind.ElementAccess && + expr.kind != NodeKind.PropertyAccess ) { this.error( DiagnosticCode.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access, @@ -4236,7 +4236,7 @@ export class Parser extends DiagnosticEmitter { } else { let next = this.parseExpression(tn, nextPrecedence + 1); if (!next) return null; - if (next.kind == NodeKind.CALL) { // expr '.' CallExpression + if (next.kind == NodeKind.Call) { // expr '.' CallExpression expr = this.joinPropertyCall(tn, startPos, expr, next); if (!expr) return null; } else { @@ -4341,7 +4341,7 @@ export class Parser extends DiagnosticEmitter { ): Expression | null { var callee = call.expression; switch (callee.kind) { - case NodeKind.IDENTIFIER: { // join property access and use as call target + case NodeKind.Identifier: { // join property access and use as call target call.expression = Node.createPropertyAccessExpression( expr, callee, @@ -4349,7 +4349,7 @@ export class Parser extends DiagnosticEmitter { ); break; } - case NodeKind.CALL: { // join call target und wrap the original call around it + case NodeKind.Call: { // join call target und wrap the original call around it let inner = this.joinPropertyCall(tn, startPos, expr, callee); if (!inner) return null; call.expression = inner; diff --git a/src/passes/shadowstack.ts b/src/passes/shadowstack.ts index 8107023b66..82c5d8d11d 100644 --- a/src/passes/shadowstack.ts +++ b/src/passes/shadowstack.ts @@ -273,7 +273,7 @@ export class ShadowStackPass extends Pass { makeStackFill(frameSize: i32, stmts: ExpressionRef[]): void { assert(frameSize > 0); var module = this.module; - if (this.options.hasFeature(Feature.BULK_MEMORY) && frameSize > 16) { + if (this.options.hasFeature(Feature.BulkMemory) && frameSize > 16) { stmts.push( module.memory_fill( module.global_get(BuiltinNames.stack_pointer, this.ptrType), diff --git a/src/program.ts b/src/program.ts index 366de8e233..39ab687cb0 100644 --- a/src/program.ts +++ b/src/program.ts @@ -248,8 +248,8 @@ export namespace OperatorKind { export function fromDecorator(decoratorKind: DecoratorKind, arg: string): OperatorKind { assert(arg.length); switch (decoratorKind) { - case DecoratorKind.OPERATOR: - case DecoratorKind.OPERATOR_BINARY: { + case DecoratorKind.Operator: + case DecoratorKind.OperatorBinary: { switch (arg.charCodeAt(0)) { case CharCode.OPENBRACKET: { if (arg == "[]") return OperatorKind.INDEXED_GET; @@ -318,7 +318,7 @@ export namespace OperatorKind { } break; } - case DecoratorKind.OPERATOR_PREFIX: { + case DecoratorKind.OperatorPrefix: { switch (arg.charCodeAt(0)) { case CharCode.PLUS: { if (arg == "+") return OperatorKind.PLUS; @@ -341,7 +341,7 @@ export namespace OperatorKind { } break; } - case DecoratorKind.OPERATOR_POSTFIX: { + case DecoratorKind.OperatorPostfix: { switch (arg.charCodeAt(0)) { case CharCode.PLUS: { if (arg == "++") return OperatorKind.POSTFIX_INC; @@ -501,7 +501,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Array` prototype. */ get arrayPrototype(): ClassPrototype { var cached = this._arrayPrototype; - if (!cached) this._arrayPrototype = cached = this.require(CommonNames.Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._arrayPrototype = cached = this.require(CommonNames.Array, ElementKind.ClassPrototype); return cached; } private _arrayPrototype: ClassPrototype | null = null; @@ -509,7 +509,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `StaticArray` prototype. */ get staticArrayPrototype(): ClassPrototype { var cached = this._staticArrayPrototype; - if (!cached) this._staticArrayPrototype = cached = this.require(CommonNames.StaticArray, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._staticArrayPrototype = cached = this.require(CommonNames.StaticArray, ElementKind.ClassPrototype); return cached; } private _staticArrayPrototype: ClassPrototype | null = null; @@ -517,7 +517,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Set` prototype. */ get setPrototype(): ClassPrototype { var cached = this._setPrototype; - if (!cached) this._setPrototype = cached = this.require(CommonNames.Set, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._setPrototype = cached = this.require(CommonNames.Set, ElementKind.ClassPrototype); return cached; } private _setPrototype: ClassPrototype | null = null; @@ -525,7 +525,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Map` prototype. */ get mapPrototype(): ClassPrototype { var cached = this._mapPrototype; - if (!cached) this._mapPrototype = cached = this.require(CommonNames.Map, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._mapPrototype = cached = this.require(CommonNames.Map, ElementKind.ClassPrototype); return cached; } private _mapPrototype: ClassPrototype | null = null; @@ -533,7 +533,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Function` prototype. */ get functionPrototype(): ClassPrototype { var cached = this._functionPrototype; - if (!cached) this._functionPrototype = cached = this.require(CommonNames.Function, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._functionPrototype = cached = this.require(CommonNames.Function, ElementKind.ClassPrototype); return cached; } private _functionPrototype: ClassPrototype | null = null; @@ -541,7 +541,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int8Array` prototype. */ get int8ArrayPrototype(): ClassPrototype { var cached = this._int8ArrayPrototype; - if (!cached) this._int8ArrayPrototype = cached = this.require(CommonNames.Int8Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._int8ArrayPrototype = cached = this.require(CommonNames.Int8Array, ElementKind.ClassPrototype); return cached; } private _int8ArrayPrototype: ClassPrototype | null = null; @@ -549,7 +549,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int16Array` prototype. */ get int16ArrayPrototype(): ClassPrototype { var cached = this._int16ArrayPrototype; - if (!cached) this._int16ArrayPrototype = cached = this.require(CommonNames.Int16Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._int16ArrayPrototype = cached = this.require(CommonNames.Int16Array, ElementKind.ClassPrototype); return cached; } private _int16ArrayPrototype: ClassPrototype | null = null; @@ -557,7 +557,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int32Array` prototype. */ get int32ArrayPrototype(): ClassPrototype { var cached = this._int32ArrayPrototype; - if (!cached) this._int32ArrayPrototype = cached = this.require(CommonNames.Int32Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._int32ArrayPrototype = cached = this.require(CommonNames.Int32Array, ElementKind.ClassPrototype); return cached; } private _int32ArrayPrototype: ClassPrototype | null = null; @@ -565,7 +565,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int64Array` prototype. */ get int64ArrayPrototype(): ClassPrototype { var cached = this._int64ArrayPrototype; - if (!cached) this._int64ArrayPrototype = cached = this.require(CommonNames.Int64Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._int64ArrayPrototype = cached = this.require(CommonNames.Int64Array, ElementKind.ClassPrototype); return cached; } private _int64ArrayPrototype: ClassPrototype | null = null; @@ -573,7 +573,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint8Array` prototype. */ get uint8ArrayPrototype(): ClassPrototype { var cached = this._uint8ArrayPrototype; - if (!cached) this._uint8ArrayPrototype = cached = this.require(CommonNames.Uint8Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._uint8ArrayPrototype = cached = this.require(CommonNames.Uint8Array, ElementKind.ClassPrototype); return cached; } private _uint8ArrayPrototype: ClassPrototype | null = null; @@ -581,7 +581,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint8ClampedArray` prototype. */ get uint8ClampedArrayPrototype(): ClassPrototype { var cached = this._uint8ClampedArrayPrototype; - if (!cached) this._uint8ClampedArrayPrototype = cached = this.require(CommonNames.Uint8ClampedArray, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._uint8ClampedArrayPrototype = cached = this.require(CommonNames.Uint8ClampedArray, ElementKind.ClassPrototype); return cached; } private _uint8ClampedArrayPrototype: ClassPrototype | null = null; @@ -589,7 +589,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint16Array` prototype. */ get uint16ArrayPrototype(): ClassPrototype { var cached = this._uint16ArrayPrototype; - if (!cached) this._uint16ArrayPrototype = cached = this.require(CommonNames.Uint16Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._uint16ArrayPrototype = cached = this.require(CommonNames.Uint16Array, ElementKind.ClassPrototype); return cached; } private _uint16ArrayPrototype: ClassPrototype | null = null; @@ -597,7 +597,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint32Array` prototype. */ get uint32ArrayPrototype(): ClassPrototype { var cached = this._uint32ArrayPrototype; - if (!cached) this._uint32ArrayPrototype = cached = this.require(CommonNames.Uint32Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._uint32ArrayPrototype = cached = this.require(CommonNames.Uint32Array, ElementKind.ClassPrototype); return cached; } private _uint32ArrayPrototype: ClassPrototype | null = null; @@ -605,7 +605,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint64Array` prototype. */ get uint64ArrayPrototype(): ClassPrototype { var cached = this._uint64ArrayPrototype; - if (!cached) this._uint64ArrayPrototype = cached = this.require(CommonNames.Uint64Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._uint64ArrayPrototype = cached = this.require(CommonNames.Uint64Array, ElementKind.ClassPrototype); return cached; } private _uint64ArrayPrototype: ClassPrototype | null = null; @@ -613,7 +613,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Float32Array` prototype. */ get float32ArrayPrototype(): ClassPrototype { var cached = this._float32ArrayPrototype; - if (!cached) this._float32ArrayPrototype = cached = this.require(CommonNames.Float32Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._float32ArrayPrototype = cached = this.require(CommonNames.Float32Array, ElementKind.ClassPrototype); return cached; } private _float32ArrayPrototype: ClassPrototype | null = null; @@ -621,7 +621,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Float64Array` prototype. */ get float64ArrayPrototype(): ClassPrototype { var cached = this._float64ArrayPrototype; - if (!cached) this._float64ArrayPrototype = cached = this.require(CommonNames.Float64Array, ElementKind.CLASS_PROTOTYPE); + if (!cached) this._float64ArrayPrototype = cached = this.require(CommonNames.Float64Array, ElementKind.ClassPrototype); return cached; } private _float64ArrayPrototype: ClassPrototype | null = null; @@ -661,7 +661,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `abort` instance, if not explicitly disabled. */ get abortInstance(): Function | null { var prototype = this.lookup(CommonNames.abort); - if (!prototype || prototype.kind != ElementKind.FUNCTION_PROTOTYPE) return null; + if (!prototype || prototype.kind != ElementKind.FunctionPrototype) return null; return this.resolver.resolveFunction(prototype, null); } @@ -849,7 +849,7 @@ export class Program extends DiagnosticEmitter { /** The simple name of the variable */ name: string, /** Flags indicating specific traits, e.g. `CONST`. */ - flags: CommonFlags = CommonFlags.NONE + flags: CommonFlags = CommonFlags.None ): VariableDeclaration { var range = this.nativeSource.range; return Node.createVariableDeclaration( @@ -863,7 +863,7 @@ export class Program extends DiagnosticEmitter { /** The simple name of the type. */ name: string, /** Flags indicating specific traits, e.g. `GENERIC`. */ - flags: CommonFlags = CommonFlags.NONE + flags: CommonFlags = CommonFlags.None ): TypeDeclaration { var range = this.nativeSource.range; var identifier = Node.createIdentifierExpression(name, range); @@ -883,7 +883,7 @@ export class Program extends DiagnosticEmitter { /** The simple name of the function. */ name: string, /** Flags indicating specific traits, e.g. `DECLARE`. */ - flags: CommonFlags = CommonFlags.NONE + flags: CommonFlags = CommonFlags.None ): FunctionDeclaration { var range = this.nativeSource.range; var signature = this.nativeDummySignature; @@ -898,7 +898,7 @@ export class Program extends DiagnosticEmitter { } return Node.createFunctionDeclaration( Node.createIdentifierExpression(name, range), - null, flags, null, signature, null, ArrowKind.NONE, range + null, flags, null, signature, null, ArrowKind.None, range ); } @@ -907,7 +907,7 @@ export class Program extends DiagnosticEmitter { /** The simple name of the namespace. */ name: string, /** Flags indicating specific traits, e.g. `EXPORT`. */ - flags: CommonFlags = CommonFlags.NONE + flags: CommonFlags = CommonFlags.None ): NamespaceDeclaration { var range = this.nativeSource.range; return Node.createNamespaceDeclaration( @@ -925,9 +925,9 @@ export class Program extends DiagnosticEmitter { /** Parent element, usually a file, class or namespace. */ parent: Element = this.nativeFile, /** Flags indicating specific traits, e.g. `GENERIC`. */ - flags: CommonFlags = CommonFlags.NONE, + flags: CommonFlags = CommonFlags.None, /** Decorator flags representing built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ): Function { return new Function( name, @@ -977,32 +977,32 @@ export class Program extends DiagnosticEmitter { this.nativeFile.add(CommonNames.native, new TypeDefinition( CommonNames.native, this.nativeFile, - this.makeNativeTypeDeclaration(CommonNames.native, CommonFlags.EXPORT | CommonFlags.GENERIC), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(CommonNames.native, CommonFlags.Export | CommonFlags.Generic), + DecoratorFlags.Builtin )); this.nativeFile.add(CommonNames.indexof, new TypeDefinition( CommonNames.indexof, this.nativeFile, - this.makeNativeTypeDeclaration(CommonNames.indexof, CommonFlags.EXPORT | CommonFlags.GENERIC), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(CommonNames.indexof, CommonFlags.Export | CommonFlags.Generic), + DecoratorFlags.Builtin )); this.nativeFile.add(CommonNames.valueof, new TypeDefinition( CommonNames.valueof, this.nativeFile, - this.makeNativeTypeDeclaration(CommonNames.valueof, CommonFlags.EXPORT | CommonFlags.GENERIC), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(CommonNames.valueof, CommonFlags.Export | CommonFlags.Generic), + DecoratorFlags.Builtin )); this.nativeFile.add(CommonNames.returnof, new TypeDefinition( CommonNames.returnof, this.nativeFile, - this.makeNativeTypeDeclaration(CommonNames.returnof, CommonFlags.EXPORT | CommonFlags.GENERIC), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(CommonNames.returnof, CommonFlags.Export | CommonFlags.Generic), + DecoratorFlags.Builtin )); this.nativeFile.add(CommonNames.nonnull, new TypeDefinition( CommonNames.nonnull, this.nativeFile, - this.makeNativeTypeDeclaration(CommonNames.nonnull, CommonFlags.EXPORT | CommonFlags.GENERIC), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(CommonNames.nonnull, CommonFlags.Export | CommonFlags.Generic), + DecoratorFlags.Builtin )); // The following types might not be enabled by compiler options, so the @@ -1018,7 +1018,7 @@ export class Program extends DiagnosticEmitter { // register compiler hints this.registerConstantInteger(CommonNames.ASC_TARGET, Type.i32, - i64_new(options.isWasm64 ? Target.WASM64 : Target.WASM32)); + i64_new(options.isWasm64 ? Target.Wasm64 : Target.Wasm32)); this.registerConstantInteger(CommonNames.ASC_RUNTIME, Type.i32, i64_new(options.runtime)); this.registerConstantInteger(CommonNames.ASC_NO_ASSERT, Type.bool, @@ -1044,35 +1044,35 @@ export class Program extends DiagnosticEmitter { // register feature hints this.registerConstantInteger(CommonNames.ASC_FEATURE_SIGN_EXTENSION, Type.bool, - i64_new(options.hasFeature(Feature.SIGN_EXTENSION) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.SignExtension) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_MUTABLE_GLOBALS, Type.bool, - i64_new(options.hasFeature(Feature.MUTABLE_GLOBALS) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.MutableGlobals) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_NONTRAPPING_F2I, Type.bool, - i64_new(options.hasFeature(Feature.NONTRAPPING_F2I) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.NontrappingF2I) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_BULK_MEMORY, Type.bool, - i64_new(options.hasFeature(Feature.BULK_MEMORY) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.BulkMemory) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_SIMD, Type.bool, - i64_new(options.hasFeature(Feature.SIMD) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.Simd) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_THREADS, Type.bool, - i64_new(options.hasFeature(Feature.THREADS) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.Threads) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_EXCEPTION_HANDLING, Type.bool, - i64_new(options.hasFeature(Feature.EXCEPTION_HANDLING) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.ExceptionHandling) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_TAIL_CALLS, Type.bool, - i64_new(options.hasFeature(Feature.TAIL_CALLS) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.TailCalls) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_REFERENCE_TYPES, Type.bool, - i64_new(options.hasFeature(Feature.REFERENCE_TYPES) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.ReferenceTypes) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_MULTI_VALUE, Type.bool, - i64_new(options.hasFeature(Feature.MULTI_VALUE) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.MultiValue) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_GC, Type.bool, i64_new(options.hasFeature(Feature.GC) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_MEMORY64, Type.bool, - i64_new(options.hasFeature(Feature.MEMORY64) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.Memory64) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_FUNCTION_REFERENCES, Type.bool, - i64_new(options.hasFeature(Feature.FUNCTION_REFERENCES) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.FunctionReferences) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_RELAXED_SIMD, Type.bool, - i64_new(options.hasFeature(Feature.RELAXED_SIMD) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.RelaxedSimd) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_EXTENDED_CONST, Type.bool, - i64_new(options.hasFeature(Feature.EXTENDED_CONST)? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.ExtendedConst)? 1 : 0, 0)); // remember deferred elements var queuedImports = new Array(); @@ -1090,43 +1090,43 @@ export class Program extends DiagnosticEmitter { for (let j = 0, l = statements.length; j < l; ++j) { let statement = statements[j]; switch (statement.kind) { - case NodeKind.EXPORT: { + case NodeKind.Export: { this.initializeExports(statement, file, queuedExports, queuedExportsStar); break; } - case NodeKind.EXPORTDEFAULT: { + case NodeKind.ExportDefault: { this.initializeExportDefault(statement, file, queuedExtends, queuedImplements); break; } - case NodeKind.IMPORT: { + case NodeKind.Import: { this.initializeImports(statement, file, queuedImports, queuedExports); break; } - case NodeKind.VARIABLE: { + case NodeKind.Variable: { this.initializeVariables(statement, file); break; } - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { this.initializeClass(statement, file, queuedExtends, queuedImplements); break; } - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { this.initializeEnum(statement, file); break; } - case NodeKind.FUNCTIONDECLARATION: { + case NodeKind.FunctionDeclaration: { this.initializeFunction(statement, file); break; } - case NodeKind.INTERFACEDECLARATION: { + case NodeKind.InterfaceDeclaration: { this.initializeInterface(statement, file, queuedExtends); break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { this.initializeNamespace(statement, file, queuedExtends, queuedImplements); break; } - case NodeKind.TYPEDECLARATION: { + case NodeKind.TypeDeclaration: { this.initializeTypeDefinition(statement, file); break; } @@ -1275,8 +1275,8 @@ export class Program extends DiagnosticEmitter { this.registerWrapperClass(Type.bool, CommonNames.Bool); this.registerWrapperClass(Type.f32, CommonNames.F32); this.registerWrapperClass(Type.f64, CommonNames.F64); - if (options.hasFeature(Feature.SIMD)) this.registerWrapperClass(Type.v128, CommonNames.V128); - if (options.hasFeature(Feature.REFERENCE_TYPES)) { + if (options.hasFeature(Feature.Simd)) this.registerWrapperClass(Type.v128, CommonNames.V128); + if (options.hasFeature(Feature.ReferenceTypes)) { this.registerWrapperClass(Type.funcref, CommonNames.Funcref); this.registerWrapperClass(Type.externref, CommonNames.Externref); if (options.hasFeature(Feature.GC)) { @@ -1294,18 +1294,18 @@ export class Program extends DiagnosticEmitter { let extendsNode = assert(thisPrototype.extendsNode); // must be present if in queuedExtends let baseElement = resolver.resolveTypeName(extendsNode.name, thisPrototype.parent); if (!baseElement) continue; - if (thisPrototype.kind == ElementKind.CLASS_PROTOTYPE) { - if (baseElement.kind == ElementKind.CLASS_PROTOTYPE) { + if (thisPrototype.kind == ElementKind.ClassPrototype) { + if (baseElement.kind == ElementKind.ClassPrototype) { let basePrototype = baseElement; - if (basePrototype.hasDecorator(DecoratorFlags.FINAL)) { + if (basePrototype.hasDecorator(DecoratorFlags.Final)) { this.error( DiagnosticCode.Class_0_is_final_and_cannot_be_extended, extendsNode.range, basePrototype.identifierNode.text ); } if ( - basePrototype.hasDecorator(DecoratorFlags.UNMANAGED) != - thisPrototype.hasDecorator(DecoratorFlags.UNMANAGED) + basePrototype.hasDecorator(DecoratorFlags.Unmanaged) != + thisPrototype.hasDecorator(DecoratorFlags.Unmanaged) ) { this.error( DiagnosticCode.Unmanaged_classes_cannot_extend_managed_classes_and_vice_versa, @@ -1327,8 +1327,8 @@ export class Program extends DiagnosticEmitter { extendsNode.range ); } - } else if (thisPrototype.kind == ElementKind.INTERFACE_PROTOTYPE) { - if (baseElement.kind == ElementKind.INTERFACE_PROTOTYPE) { + } else if (thisPrototype.kind == ElementKind.InterfacePrototype) { + if (baseElement.kind == ElementKind.InterfacePrototype) { const basePrototype = baseElement; if (!thisPrototype.extends(basePrototype)) { thisPrototype.basePrototype = basePrototype; @@ -1356,7 +1356,7 @@ export class Program extends DiagnosticEmitter { let implementsNode = implementsNodes[j]; let interfaceElement = resolver.resolveTypeName(implementsNode.name, thisPrototype.parent); if (!interfaceElement) continue; - if (interfaceElement.kind == ElementKind.INTERFACE_PROTOTYPE) { + if (interfaceElement.kind == ElementKind.InterfacePrototype) { let interfacePrototype = interfaceElement; let interfacePrototypes = thisPrototype.interfacePrototypes; if (!interfacePrototypes) thisPrototype.interfacePrototypes = interfacePrototypes = new Array(); @@ -1455,13 +1455,13 @@ export class Program extends DiagnosticEmitter { for (let _values = Map_values(thisInstanceMembers), j = 0, l = _values.length; j < l; ++j) { let thisMember = _values[j]; if ( - !thisMember.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.PRIVATE) && + !thisMember.isAny(CommonFlags.Constructor | CommonFlags.Private) && baseInstanceMembers.has(thisMember.name) ) { let baseMember = assert(baseInstanceMembers.get(thisMember.name)); if ( - thisMember.kind == ElementKind.FUNCTION_PROTOTYPE && - baseMember.kind == ElementKind.FUNCTION_PROTOTYPE + thisMember.kind == ElementKind.FunctionPrototype && + baseMember.kind == ElementKind.FunctionPrototype ) { let thisMethod = thisMember; let baseMethod = baseMember; @@ -1471,7 +1471,7 @@ export class Program extends DiagnosticEmitter { thisMethod.identifierNode.range, baseMethod.identifierNode.range ); } - baseMember.set(CommonFlags.VIRTUAL); + baseMember.set(CommonFlags.Virtual); let overloads = baseMethod.overloads; if (!overloads) baseMethod.overloads = overloads = new Set(); overloads.add(thisMember); @@ -1479,12 +1479,12 @@ export class Program extends DiagnosticEmitter { if (baseMethodInstances) { for (let _values = Map_values(baseMethodInstances), a = 0, b = _values.length; a < b; ++a) { let baseMethodInstance = _values[a]; - baseMethodInstance.set(CommonFlags.VIRTUAL); + baseMethodInstance.set(CommonFlags.Virtual); } } } else if ( - thisMember.kind == ElementKind.PROPERTY_PROTOTYPE && - baseMember.kind == ElementKind.PROPERTY_PROTOTYPE + thisMember.kind == ElementKind.PropertyPrototype && + baseMember.kind == ElementKind.PropertyPrototype ) { let thisProperty = thisMember; let baseProperty = baseMember; @@ -1494,10 +1494,10 @@ export class Program extends DiagnosticEmitter { thisProperty.identifierNode.range, baseProperty.identifierNode.range ); } - baseProperty.set(CommonFlags.VIRTUAL); + baseProperty.set(CommonFlags.Virtual); let baseGetter = baseProperty.getterPrototype; if (baseGetter) { - baseGetter.set(CommonFlags.VIRTUAL); + baseGetter.set(CommonFlags.Virtual); let thisGetter = thisProperty.getterPrototype; if (thisGetter) { let overloads = baseGetter.overloads; @@ -1508,13 +1508,13 @@ export class Program extends DiagnosticEmitter { if (baseGetterInstances) { for (let _values = Map_values(baseGetterInstances), a = 0, b = _values.length; a < b; ++a) { let baseGetterInstance = _values[a]; - baseGetterInstance.set(CommonFlags.VIRTUAL); + baseGetterInstance.set(CommonFlags.Virtual); } } } let baseSetter = baseProperty.setterPrototype; if (baseSetter && thisProperty.setterPrototype) { - baseSetter.set(CommonFlags.VIRTUAL); + baseSetter.set(CommonFlags.Virtual); let thisSetter = thisProperty.setterPrototype; if (thisSetter) { let overloads = baseSetter.overloads; @@ -1525,13 +1525,13 @@ export class Program extends DiagnosticEmitter { if (baseSetterInstances) { for (let _values = Map_values(baseSetterInstances), a = 0, b = _values.length; a < b; ++a) { let baseSetterInstance = _values[a]; - baseSetterInstance.set(CommonFlags.VIRTUAL); + baseSetterInstance.set(CommonFlags.Virtual); } } } } } - if (thisMember.is(CommonFlags.OVERRIDE) && !baseInstanceMembers.has(thisMember.name)) { + if (thisMember.is(CommonFlags.Override) && !baseInstanceMembers.has(thisMember.name)) { this.error( DiagnosticCode.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0, thisMember.identifierNode.range, basePrototype.name @@ -1563,12 +1563,12 @@ export class Program extends DiagnosticEmitter { /** Requires that a global variable is present and returns it. */ requireGlobal(name: string): Global { - return this.require(name, ElementKind.GLOBAL); + return this.require(name, ElementKind.Global); } /** Requires that a non-generic global class is present and returns it. */ requireClass(name: string): Class { - var prototype = this.require(name, ElementKind.CLASS_PROTOTYPE); + var prototype = this.require(name, ElementKind.ClassPrototype); var resolved = this.resolver.resolveClass(prototype, null); if (!resolved) throw new Error(`Invalid standard library class: ${name}`); return resolved; @@ -1576,7 +1576,7 @@ export class Program extends DiagnosticEmitter { /** Requires that a global function is present and returns it. */ requireFunction(name: string, typeArguments: Type[] | null = null): Function { - var prototype = this.require(name, ElementKind.FUNCTION_PROTOTYPE); + var prototype = this.require(name, ElementKind.FunctionPrototype); var resolved = this.resolver.resolveFunction(prototype, typeArguments); if (!resolved) throw new Error(`Invalid standard library function: ${name}`); return resolved; @@ -1602,9 +1602,9 @@ export class Program extends DiagnosticEmitter { /** Marks an element and its children as a module export. */ private markModuleExport(element: Element): void { - element.set(CommonFlags.MODULE_EXPORT); + element.set(CommonFlags.ModuleExport); switch (element.kind) { - case ElementKind.CLASS_PROTOTYPE: { + case ElementKind.ClassPrototype: { let instanceMembers = (element).instanceMembers; if (instanceMembers) { // TODO: for (let member of instanceMembers.values()) { @@ -1615,7 +1615,7 @@ export class Program extends DiagnosticEmitter { } break; } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let propertyPrototype = element; let getterPrototype = propertyPrototype.getterPrototype; if (getterPrototype) this.markModuleExport(getterPrototype); @@ -1623,10 +1623,10 @@ export class Program extends DiagnosticEmitter { if (setterPrototype) this.markModuleExport(setterPrototype); break; } - case ElementKind.PROPERTY: - case ElementKind.FUNCTION: - case ElementKind.FIELD: - case ElementKind.CLASS: assert(false); // assumes that there are no instances yet + case ElementKind.Property: + case ElementKind.Function: + case ElementKind.Field: + case ElementKind.Class: assert(false); // assumes that there are no instances yet } var staticMembers = element.members; if (staticMembers) { @@ -1640,7 +1640,7 @@ export class Program extends DiagnosticEmitter { /** Marks an element as a module import. */ markModuleImport(moduleName: string, name: string, element: Element): void { - element.set(CommonFlags.MODULE_IMPORT); + element.set(CommonFlags.ModuleImport); var moduleImports = this.moduleImports; var module: Map; if (moduleImports.has(moduleName)) { @@ -1657,8 +1657,8 @@ export class Program extends DiagnosticEmitter { var element = new TypeDefinition( name, this.nativeFile, - this.makeNativeTypeDeclaration(name, CommonFlags.EXPORT), - DecoratorFlags.BUILTIN + this.makeNativeTypeDeclaration(name, CommonFlags.Export), + DecoratorFlags.Builtin ); element.setType(type); this.nativeFile.add(name, element); @@ -1669,7 +1669,7 @@ export class Program extends DiagnosticEmitter { var wrapperClasses = this.wrapperClasses; assert(!type.isInternalReference && !wrapperClasses.has(type)); var element = assert(this.lookup(className)); - assert(element.kind == ElementKind.CLASS_PROTOTYPE); + assert(element.kind == ElementKind.ClassPrototype); var classElement = assert(this.resolver.resolveClass(element, null)); classElement.wrappedType = type; wrapperClasses.set(type, classElement); @@ -1681,8 +1681,8 @@ export class Program extends DiagnosticEmitter { var global = new Global( name, this.nativeFile, - DecoratorFlags.NONE, - this.makeNativeVariableDeclaration(name, CommonFlags.CONST | CommonFlags.EXPORT) + DecoratorFlags.None, + this.makeNativeVariableDeclaration(name, CommonFlags.Const | CommonFlags.Export) ); global.setConstantIntegerValue(value, type); this.nativeFile.add(name, global); @@ -1694,8 +1694,8 @@ export class Program extends DiagnosticEmitter { var global = new Global( name, this.nativeFile, - DecoratorFlags.NONE, - this.makeNativeVariableDeclaration(name, CommonFlags.CONST | CommonFlags.EXPORT) + DecoratorFlags.None, + this.makeNativeVariableDeclaration(name, CommonFlags.Const | CommonFlags.Export) ); global.setConstantFloatValue(value, type); this.nativeFile.add(name, global); @@ -1807,14 +1807,14 @@ export class Program extends DiagnosticEmitter { /** Accepted decorator flags. Emits diagnostics if any other decorators are present. */ acceptedFlags: DecoratorFlags ): DecoratorFlags { - var flags = DecoratorFlags.NONE; + var flags = DecoratorFlags.None; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { let decorator = decorators[i]; let kind = DecoratorKind.fromNode(decorator.name); let flag = DecoratorFlags.fromKind(kind); if (flag) { - if (flag == DecoratorFlags.BUILTIN) { + if (flag == DecoratorFlags.Builtin) { if (!(acceptedFlags & flag) && !decorator.range.source.isLibrary) { this.error( DiagnosticCode.Decorator_0_is_not_valid_here, @@ -1859,9 +1859,9 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.GLOBAL | - DecoratorFlags.FINAL | - DecoratorFlags.UNMANAGED + DecoratorFlags.Global | + DecoratorFlags.Final | + DecoratorFlags.Unmanaged ) ); if (!parent.add(name, element)) return null; @@ -1872,7 +1872,7 @@ export class Program extends DiagnosticEmitter { let numImplementsTypes = implementsTypes.length; if (numImplementsTypes) { // cannot implement interfaces when unmanaged - if (element.hasDecorator(DecoratorFlags.UNMANAGED)) { + if (element.hasDecorator(DecoratorFlags.Unmanaged)) { this.error( DiagnosticCode.Unmanaged_classes_cannot_implement_interfaces, Range.join( @@ -1894,23 +1894,23 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = memberDeclarations.length; i < k; ++i) { let memberDeclaration = memberDeclarations[i]; switch (memberDeclaration.kind) { - case NodeKind.FIELDDECLARATION: { + case NodeKind.FieldDeclaration: { this.initializeField(memberDeclaration, element); break; } - case NodeKind.METHODDECLARATION: { + case NodeKind.MethodDeclaration: { let methodDeclaration = memberDeclaration; - if (memberDeclaration.isAny(CommonFlags.GET | CommonFlags.SET)) { + if (memberDeclaration.isAny(CommonFlags.Get | CommonFlags.Set)) { this.initializeProperty(methodDeclaration, element); } else { let method = this.initializeMethod(methodDeclaration, element); - if (method && methodDeclaration.name.kind == NodeKind.CONSTRUCTOR) { + if (method && methodDeclaration.name.kind == NodeKind.Constructor) { element.constructorPrototype = method; } } break; } - case NodeKind.INDEXSIGNATURE: break; // ignored for now + case NodeKind.IndexSignature: break; // ignored for now default: assert(false); // class member expected } } @@ -1927,15 +1927,15 @@ export class Program extends DiagnosticEmitter { var name = declaration.name.text; var decorators = declaration.decorators; var element: DeclaredElement; - var acceptedFlags: DecoratorFlags = DecoratorFlags.UNSAFE; - if (parent.is(CommonFlags.AMBIENT)) { - acceptedFlags |= DecoratorFlags.EXTERNAL; + var acceptedFlags: DecoratorFlags = DecoratorFlags.Unsafe; + if (parent.is(CommonFlags.Ambient)) { + acceptedFlags |= DecoratorFlags.External; } - if (declaration.is(CommonFlags.STATIC)) { // global variable - assert(parent.kind != ElementKind.INTERFACE_PROTOTYPE); - acceptedFlags |= DecoratorFlags.LAZY; - if (declaration.is(CommonFlags.READONLY)) { - acceptedFlags |= DecoratorFlags.INLINE; + if (declaration.is(CommonFlags.Static)) { // global variable + assert(parent.kind != ElementKind.InterfacePrototype); + acceptedFlags |= DecoratorFlags.Lazy; + if (declaration.is(CommonFlags.Readonly)) { + acceptedFlags |= DecoratorFlags.Inline; } element = new Global( name, @@ -1945,7 +1945,7 @@ export class Program extends DiagnosticEmitter { ); if (!parent.add(name, element)) return; } else { // actual instance field - assert(!declaration.isAny(CommonFlags.ABSTRACT | CommonFlags.GET | CommonFlags.SET)); + assert(!declaration.isAny(CommonFlags.Abstract | CommonFlags.Get | CommonFlags.Set)); element = new FieldPrototype( name, parent, @@ -1964,15 +1964,15 @@ export class Program extends DiagnosticEmitter { parent: ClassPrototype ): FunctionPrototype | null { var name = declaration.name.text; - var isStatic = declaration.is(CommonFlags.STATIC); - var acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE; - if (!declaration.is(CommonFlags.GENERIC)) { - acceptedFlags |= DecoratorFlags.OPERATOR_BINARY - | DecoratorFlags.OPERATOR_PREFIX - | DecoratorFlags.OPERATOR_POSTFIX; + var isStatic = declaration.is(CommonFlags.Static); + var acceptedFlags = DecoratorFlags.Inline | DecoratorFlags.Unsafe; + if (!declaration.is(CommonFlags.Generic)) { + acceptedFlags |= DecoratorFlags.OperatorBinary + | DecoratorFlags.OperatorPrefix + | DecoratorFlags.OperatorPostfix; } - if (parent.is(CommonFlags.AMBIENT)) { - acceptedFlags |= DecoratorFlags.EXTERNAL; + if (parent.is(CommonFlags.Ambient)) { + acceptedFlags |= DecoratorFlags.External; } var element = new FunctionPrototype( name, @@ -1981,7 +1981,7 @@ export class Program extends DiagnosticEmitter { this.checkDecorators(declaration.decorators, acceptedFlags) ); if (isStatic) { // global function - assert(declaration.name.kind != NodeKind.CONSTRUCTOR); + assert(declaration.name.kind != NodeKind.Constructor); if (!parent.add(name, element)) return null; } else { // actual instance method if (!parent.addInstance(name, element)) return null; @@ -2003,15 +2003,15 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = decorators.length; i < k; ++i) { let decorator: DecoratorNode = decorators[i]; // FIXME: why does tsc want a type here? switch (decorator.decoratorKind) { - case DecoratorKind.OPERATOR: - case DecoratorKind.OPERATOR_BINARY: - case DecoratorKind.OPERATOR_PREFIX: - case DecoratorKind.OPERATOR_POSTFIX: { + case DecoratorKind.Operator: + case DecoratorKind.OperatorBinary: + case DecoratorKind.OperatorPrefix: + case DecoratorKind.OperatorPostfix: { let args = decorator.args; let numArgs = args ? args.length : 0; if (numArgs == 1) { let firstArg = (decorator.args)[0]; - if (firstArg.isLiteralKind(LiteralKind.STRING)) { + if (firstArg.isLiteralKind(LiteralKind.String)) { let text = (firstArg).value; let kind = OperatorKind.fromDecorator(decorator.decoratorKind, text); if (kind == OperatorKind.INVALID) { @@ -2057,11 +2057,11 @@ export class Program extends DiagnosticEmitter { parent: ClassPrototype ): PropertyPrototype | null { var name = declaration.name.text; - if (declaration.is(CommonFlags.STATIC)) { + if (declaration.is(CommonFlags.Static)) { let parentMembers = parent.members; if (parentMembers && parentMembers.has(name)) { let element = assert(parentMembers.get(name)); - if (element.kind == ElementKind.PROPERTY_PROTOTYPE) return element; + if (element.kind == ElementKind.PropertyPrototype) return element; } else { let element = new PropertyPrototype(name, parent, declaration); if (!parent.add(name, element)) return null; @@ -2071,7 +2071,7 @@ export class Program extends DiagnosticEmitter { let parentMembers = parent.instanceMembers; if (parentMembers && parentMembers.has(name)) { let element = assert(parentMembers.get(name)); - if (element.kind == ElementKind.PROPERTY_PROTOTYPE) return element; + if (element.kind == ElementKind.PropertyPrototype) return element; } else { let element = new PropertyPrototype(name, parent, declaration); if (!parent.addInstance(name, element)) return null; @@ -2095,7 +2095,7 @@ export class Program extends DiagnosticEmitter { var property = this.ensureProperty(declaration, parent); if (!property) return; var name = declaration.name.text; - var isGetter = declaration.is(CommonFlags.GET); + var isGetter = declaration.is(CommonFlags.Get); if (isGetter) { if (property.getterPrototype) { this.error( @@ -2118,7 +2118,7 @@ export class Program extends DiagnosticEmitter { property, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.INLINE | DecoratorFlags.UNSAFE + DecoratorFlags.Inline | DecoratorFlags.Unsafe ) ); if (isGetter) { @@ -2141,9 +2141,9 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.GLOBAL | - DecoratorFlags.INLINE | - DecoratorFlags.LAZY + DecoratorFlags.Global | + DecoratorFlags.Inline | + DecoratorFlags.Lazy ) ); if (!parent.add(name, element)) return null; @@ -2167,7 +2167,7 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.NONE + DecoratorFlags.None ) ); if (!parent.add(name, element)) return; @@ -2275,23 +2275,23 @@ export class Program extends DiagnosticEmitter { var declaration = statement.declaration; var element: DeclaredElement | null = null; switch (declaration.kind) { - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { element = this.initializeEnum(declaration, parent); break; } - case NodeKind.FUNCTIONDECLARATION: { + case NodeKind.FunctionDeclaration: { element = this.initializeFunction(declaration, parent); break; } - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { element = this.initializeClass(declaration, parent, queuedExtends, queuedImplements); break; } - case NodeKind.INTERFACEDECLARATION: { + case NodeKind.InterfaceDeclaration: { element = this.initializeInterface(declaration, parent, queuedExtends); break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { element = this.initializeNamespace(declaration, parent, queuedExtends, queuedImplements); break; } @@ -2399,18 +2399,18 @@ export class Program extends DiagnosticEmitter { parent: Element ): FunctionPrototype | null { var name = declaration.name.text; - var validDecorators = DecoratorFlags.UNSAFE | DecoratorFlags.BUILTIN; - if (declaration.is(CommonFlags.AMBIENT)) { - validDecorators |= DecoratorFlags.EXTERNAL | DecoratorFlags.EXTERNAL_JS; + var validDecorators = DecoratorFlags.Unsafe | DecoratorFlags.Builtin; + if (declaration.is(CommonFlags.Ambient)) { + validDecorators |= DecoratorFlags.External | DecoratorFlags.ExternalJs; } else { - validDecorators |= DecoratorFlags.INLINE; - if (declaration.range.source.isLibrary || declaration.is(CommonFlags.EXPORT)) { - validDecorators |= DecoratorFlags.LAZY; + validDecorators |= DecoratorFlags.Inline; + if (declaration.range.source.isLibrary || declaration.is(CommonFlags.Export)) { + validDecorators |= DecoratorFlags.Lazy; } } - if (!declaration.is(CommonFlags.INSTANCE)) { - if (parent.kind != ElementKind.CLASS_PROTOTYPE) { - validDecorators |= DecoratorFlags.GLOBAL; + if (!declaration.is(CommonFlags.Instance)) { + if (parent.kind != ElementKind.ClassPrototype) { + validDecorators |= DecoratorFlags.Global; } } var element = new FunctionPrototype( @@ -2438,7 +2438,7 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.GLOBAL + DecoratorFlags.Global ) ); if (!parent.add(name, element)) return null; @@ -2450,13 +2450,13 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = memberDeclarations.length; i < k; ++i) { let memberDeclaration = memberDeclarations[i]; switch (memberDeclaration.kind) { - case NodeKind.FIELDDECLARATION: { + case NodeKind.FieldDeclaration: { this.initializeFieldAsProperty(memberDeclaration, element); break; } - case NodeKind.METHODDECLARATION: { + case NodeKind.MethodDeclaration: { let methodDeclaration = memberDeclaration; - if (memberDeclaration.isAny(CommonFlags.GET | CommonFlags.SET)) { + if (memberDeclaration.isAny(CommonFlags.Get | CommonFlags.Set)) { this.initializeProperty(methodDeclaration, element); } else { this.initializeMethod(methodDeclaration, element); @@ -2482,7 +2482,7 @@ export class Program extends DiagnosticEmitter { Node.createMethodDeclaration( declaration.name, declaration.decorators, - declaration.flags | CommonFlags.GET, + declaration.flags | CommonFlags.Get, null, Node.createFunctionType( [], @@ -2496,12 +2496,12 @@ export class Program extends DiagnosticEmitter { ), parent ); - if (!declaration.is(CommonFlags.READONLY)) { + if (!declaration.is(CommonFlags.Readonly)) { this.initializeProperty( Node.createMethodDeclaration( declaration.name, declaration.decorators, - declaration.flags | CommonFlags.SET, + declaration.flags | CommonFlags.Set, null, Node.createFunctionType( [ @@ -2542,7 +2542,7 @@ export class Program extends DiagnosticEmitter { name, parent, declaration, - this.checkDecorators(declaration.decorators, DecoratorFlags.GLOBAL) + this.checkDecorators(declaration.decorators, DecoratorFlags.Global) ); if (!parent.add(name, original)) return null; var element = assert(parent.getMember(name)); // possibly merged @@ -2550,31 +2550,31 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = members.length; i < k; ++i) { let member = members[i]; switch (member.kind) { - case NodeKind.CLASSDECLARATION: { + case NodeKind.ClassDeclaration: { this.initializeClass(member, original, queuedExtends, queuedImplements); break; } - case NodeKind.ENUMDECLARATION: { + case NodeKind.EnumDeclaration: { this.initializeEnum(member, original); break; } - case NodeKind.FUNCTIONDECLARATION: { + case NodeKind.FunctionDeclaration: { this.initializeFunction(member, original); break; } - case NodeKind.INTERFACEDECLARATION: { + case NodeKind.InterfaceDeclaration: { this.initializeInterface(member, original, queuedExtends); break; } - case NodeKind.NAMESPACEDECLARATION: { + case NodeKind.NamespaceDeclaration: { this.initializeNamespace(member, original, queuedExtends, queuedImplements); break; } - case NodeKind.TYPEDECLARATION: { + case NodeKind.TypeDeclaration: { this.initializeTypeDefinition(member, original); break; } - case NodeKind.VARIABLE: { + case NodeKind.Variable: { this.initializeVariables(member, original); break; } @@ -2597,7 +2597,7 @@ export class Program extends DiagnosticEmitter { name, parent, declaration, - this.checkDecorators(declaration.decorators, DecoratorFlags.NONE) + this.checkDecorators(declaration.decorators, DecoratorFlags.None) ); parent.add(name, element); // reports } @@ -2613,12 +2613,12 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = declarations.length; i < k; ++i) { let declaration = declarations[i]; let name = declaration.name.text; - let acceptedFlags = DecoratorFlags.GLOBAL | DecoratorFlags.LAZY; - if (declaration.is(CommonFlags.AMBIENT)) { - acceptedFlags |= DecoratorFlags.EXTERNAL; + let acceptedFlags = DecoratorFlags.Global | DecoratorFlags.Lazy; + if (declaration.is(CommonFlags.Ambient)) { + acceptedFlags |= DecoratorFlags.External; } - if (declaration.is(CommonFlags.CONST)) { - acceptedFlags |= DecoratorFlags.INLINE; + if (declaration.is(CommonFlags.Const)) { + acceptedFlags |= DecoratorFlags.Inline; } let element = new Global( name, @@ -2661,71 +2661,71 @@ export class Program extends DiagnosticEmitter { /** Indicates the specific kind of an {@link Element}. */ export const enum ElementKind { /** A {@link Global}. */ - GLOBAL, + Global, /** A {@link Local}. */ - LOCAL, + Local, /** An {@link Enum}. */ - ENUM, + Enum, /** An {@link EnumValue}. */ - ENUMVALUE, + EnumValue, /** A {@link FunctionPrototype}. */ - FUNCTION_PROTOTYPE, + FunctionPrototype, /** A {@link Function}. */ - FUNCTION, + Function, /** A {@link ClassPrototype}. */ - CLASS_PROTOTYPE, + ClassPrototype, /** A {@link Class}. */ - CLASS, + Class, /** An {@link InterfacePrototype}. */ - INTERFACE_PROTOTYPE, + InterfacePrototype, /** An {@link Interface}. */ - INTERFACE, + Interface, /** A {@link FieldPrototype}. */ - FIELD_PROTOTYPE, + FieldPrototype, /** A {@link Field}. */ - FIELD, + Field, /** A {@link PropertyPrototype}. */ - PROPERTY_PROTOTYPE, + PropertyPrototype, /** A {@link Property}. */ - PROPERTY, + Property, /** A {@link Namespace}. */ - NAMESPACE, + Namespace, /** A {@link File}. */ - FILE, + File, /** A {@link TypeDefinition}. */ - TYPEDEFINITION, + TypeDefinition, /** An {@link IndexSignature}. */ - INDEXSIGNATURE + IndexSignature } /** Indicates built-in decorators that are present. */ export enum DecoratorFlags { /** No flags set. */ - NONE = 0, + None = 0, /** Is a program global. */ - GLOBAL = 1 << 0, + Global = 1 << 0, /** Is a binary operator overload. */ - OPERATOR_BINARY = 1 << 1, + OperatorBinary = 1 << 1, /** Is a unary prefix operator overload. */ - OPERATOR_PREFIX = 1 << 2, + OperatorPrefix = 1 << 2, /** Is a unary postfix operator overload. */ - OPERATOR_POSTFIX = 1 << 3, + OperatorPostfix = 1 << 3, /** Is an unmanaged class. */ - UNMANAGED = 1 << 4, + Unmanaged = 1 << 4, /** Is a final class. */ - FINAL = 1 << 5, + Final = 1 << 5, /** Is always inlined. */ - INLINE = 1 << 6, + Inline = 1 << 6, /** Is using a different external name. */ - EXTERNAL = 1 << 7, + External = 1 << 7, /** Has external JavaScript code. */ - EXTERNAL_JS = 1 << 8, + ExternalJs = 1 << 8, /** Is a builtin. */ - BUILTIN = 1 << 9, + Builtin = 1 << 9, /** Is compiled lazily. */ - LAZY = 1 << 10, + Lazy = 1 << 10, /** Is considered unsafe code. */ - UNSAFE = 1 << 11 + Unsafe = 1 << 11 } export namespace DecoratorFlags { @@ -2733,20 +2733,20 @@ export namespace DecoratorFlags { /** Translates a decorator kind to the respective decorator flag. */ export function fromKind(kind: DecoratorKind): DecoratorFlags { switch (kind) { - case DecoratorKind.GLOBAL: return DecoratorFlags.GLOBAL; - case DecoratorKind.OPERATOR: - case DecoratorKind.OPERATOR_BINARY: return DecoratorFlags.OPERATOR_BINARY; - case DecoratorKind.OPERATOR_PREFIX: return DecoratorFlags.OPERATOR_PREFIX; - case DecoratorKind.OPERATOR_POSTFIX: return DecoratorFlags.OPERATOR_POSTFIX; - case DecoratorKind.UNMANAGED: return DecoratorFlags.UNMANAGED; - case DecoratorKind.FINAL: return DecoratorFlags.FINAL; - case DecoratorKind.INLINE: return DecoratorFlags.INLINE; - case DecoratorKind.EXTERNAL: return DecoratorFlags.EXTERNAL; - case DecoratorKind.EXTERNAL_JS: return DecoratorFlags.EXTERNAL_JS; - case DecoratorKind.BUILTIN: return DecoratorFlags.BUILTIN; - case DecoratorKind.LAZY: return DecoratorFlags.LAZY; - case DecoratorKind.UNSAFE: return DecoratorFlags.UNSAFE; - default: return DecoratorFlags.NONE; + case DecoratorKind.Global: return DecoratorFlags.Global; + case DecoratorKind.Operator: + case DecoratorKind.OperatorBinary: return DecoratorFlags.OperatorBinary; + case DecoratorKind.OperatorPrefix: return DecoratorFlags.OperatorPrefix; + case DecoratorKind.OperatorPostfix: return DecoratorFlags.OperatorPostfix; + case DecoratorKind.Unmanaged: return DecoratorFlags.Unmanaged; + case DecoratorKind.Final: return DecoratorFlags.Final; + case DecoratorKind.Inline: return DecoratorFlags.Inline; + case DecoratorKind.External: return DecoratorFlags.External; + case DecoratorKind.ExternalJs: return DecoratorFlags.ExternalJs; + case DecoratorKind.Builtin: return DecoratorFlags.Builtin; + case DecoratorKind.Lazy: return DecoratorFlags.Lazy; + case DecoratorKind.Unsafe: return DecoratorFlags.Unsafe; + default: return DecoratorFlags.None; } } } @@ -2757,9 +2757,9 @@ export abstract class Element { /** Parent element. */ parent!: Element; /** Common flags indicating specific traits. */ - flags: CommonFlags = CommonFlags.NONE; + flags: CommonFlags = CommonFlags.None; /** Decorator flags indicating annotated traits. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE; + decoratorFlags: DecoratorFlags = DecoratorFlags.None; /** Member elements. */ members: Map | null = null; /** Shadowing type in type space, if any. */ @@ -2784,7 +2784,7 @@ export abstract class Element { if (parent) { this.parent = parent; } else { - assert(this.kind == ElementKind.FILE); + assert(this.kind == ElementKind.File); this.parent = this; // special case to keep this.parent non-nullable } } @@ -2794,7 +2794,7 @@ export abstract class Element { var current: Element = this; do { current = current.parent; - if (current.kind == ElementKind.FILE) return current; + if (current.kind == ElementKind.File) return current; } while (true); } @@ -2859,7 +2859,7 @@ export abstract class Element { } members.set(name, element); var program = this.program; - if (element.kind != ElementKind.FUNCTION_PROTOTYPE || !(element).isBound) { + if (element.kind != ElementKind.FunctionPrototype || !(element).isBound) { // prefer unbound prototypes in global lookup maps program.elementsByName.set(element.internalName, element); program.elementsByDeclaration.set(originalDeclaration, element); @@ -2869,18 +2869,18 @@ export abstract class Element { /** Checks if this element is public, explicitly or implicitly. */ get isPublic(): bool { - return !this.isAny(CommonFlags.PRIVATE | CommonFlags.PROTECTED); + return !this.isAny(CommonFlags.Private | CommonFlags.Protected); } /** Checks if this element is implicitly public, i.e. not explicitly declared to be. */ get isImplicitlyPublic(): bool { - return this.isPublic && !this.is(CommonFlags.PUBLIC); + return this.isPublic && !this.is(CommonFlags.Public); } /** Checks if the visibility of this element equals the specified. */ visibilityEquals(other: Element): bool { if (this.isPublic == other.isPublic) return true; - const vis = CommonFlags.PRIVATE | CommonFlags.PROTECTED; + const vis = CommonFlags.Private | CommonFlags.Protected; return (this.flags & vis) == (other.flags & vis); } @@ -2942,7 +2942,7 @@ export abstract class DeclaredElement extends Element { get identifierAndSignatureRange(): Range { var declaration = this.declaration; var identifierNode = declaration.name; - if (declaration.kind == NodeKind.FUNCTIONDECLARATION || declaration.kind == NodeKind.METHODDECLARATION) { + if (declaration.kind == NodeKind.FunctionDeclaration || declaration.kind == NodeKind.MethodDeclaration) { let signatureNode = (declaration).signature; return Range.join(identifierNode.range, signatureNode.range); } @@ -2960,10 +2960,10 @@ export abstract class DeclaredElement extends Element { var kind = self.kind; if (kind == base.kind) { switch (kind) { - case ElementKind.FUNCTION: { + case ElementKind.Function: { return (self).signature.isAssignableTo((base).signature); } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let selfProperty = self; let baseProperty = base; let selfGetter = selfProperty.getterInstance; @@ -3026,9 +3026,9 @@ export abstract class TypedElement extends DeclaredElement { /** Sets the resolved type of this element. */ setType(type: Type): void { - assert(!this.is(CommonFlags.RESOLVED)); + assert(!this.is(CommonFlags.Resolved)); this.type = type; - this.set(CommonFlags.RESOLVED); + this.set(CommonFlags.Resolved); } } @@ -3052,7 +3052,7 @@ export class File extends Element { public source: Source ) { super( - ElementKind.FILE, + ElementKind.File, source.normalizedPath, source.internalPath, program, @@ -3072,12 +3072,12 @@ export class File extends Element { /* @override */ add(name: string, element: DeclaredElement, localIdentifierIfImport: IdentifierExpression | null = null): bool { - if (element.hasDecorator(DecoratorFlags.GLOBAL)) { + if (element.hasDecorator(DecoratorFlags.Global)) { element = this.program.ensureGlobal(name, element); // possibly merged globally } if (!super.add(name, element, localIdentifierIfImport)) return false; element = assert(this.getMember(name)); // possibly merged locally - if (element.is(CommonFlags.EXPORT) && !localIdentifierIfImport) { + if (element.is(CommonFlags.Export) && !localIdentifierIfImport) { this.ensureExport( element.name, element @@ -3151,7 +3151,7 @@ export class File extends Element { var declaration = this.program.makeNativeNamespaceDeclaration(name); declaration.name = localIdentifier; var ns = new Namespace(name, parent, declaration); - ns.set(CommonFlags.SCOPED); + ns.set(CommonFlags.Scoped); this.copyExportsToNamespace(ns); // NOTE: Some exports are still queued, and can't yet be added here, // so we remember all the alias namespaces and add to them as well @@ -3192,10 +3192,10 @@ export class TypeDefinition extends TypedElement { /** Declaration reference. */ declaration: TypeDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.TYPEDEFINITION, + ElementKind.TypeDefinition, name, mangleInternalName(name, parent, false), parent.program, @@ -3228,10 +3228,10 @@ export class Namespace extends DeclaredElement { /** Declaration reference. */ declaration: NamespaceDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.NAMESPACE, + ElementKind.Namespace, name, mangleInternalName(name, parent, false), parent.program, @@ -3261,10 +3261,10 @@ export class Enum extends TypedElement { /** Declaration reference. */ declaration: EnumDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.ENUM, + ElementKind.Enum, name, mangleInternalName(name, parent, false), parent.program, @@ -3286,18 +3286,18 @@ export class Enum extends TypedElement { /** Indicates the kind of an inlined constant value. */ export const enum ConstantValueKind { /** No constant value. */ - NONE, + None, /** Constant integer value. */ - INTEGER, + Integer, /** Constant float value. */ - FLOAT + Float } /** Base class of all variable-like program elements. */ export abstract class VariableLikeElement extends TypedElement { /** Constant value kind. */ - constantValueKind: ConstantValueKind = ConstantValueKind.NONE; + constantValueKind: ConstantValueKind = ConstantValueKind.None; /** Constant integer value, if applicable. */ constantIntegerValue: i64 = i64_zero; /** Constant float value, if applicable. */ @@ -3317,7 +3317,7 @@ export abstract class VariableLikeElement extends TypedElement { super( kind, name, - mangleInternalName(name, parent, declaration.is(CommonFlags.INSTANCE)), + mangleInternalName(name, parent, declaration.is(CommonFlags.Instance)), parent.program, parent, declaration @@ -3339,18 +3339,18 @@ export abstract class VariableLikeElement extends TypedElement { setConstantIntegerValue(value: i64, type: Type): void { assert(type.isIntegerInclReference); this.type = type; - this.constantValueKind = ConstantValueKind.INTEGER; + this.constantValueKind = ConstantValueKind.Integer; this.constantIntegerValue = value; - this.set(CommonFlags.CONST | CommonFlags.INLINED | CommonFlags.RESOLVED); + this.set(CommonFlags.Const | CommonFlags.Inlined | CommonFlags.Resolved); } /** Applies a constant float value to this element. */ setConstantFloatValue(value: f64, type: Type): void { assert(type.isFloatValue); this.type = type; - this.constantValueKind = ConstantValueKind.FLOAT; + this.constantValueKind = ConstantValueKind.Float; this.constantFloatValue = value; - this.set(CommonFlags.CONST | CommonFlags.INLINED | CommonFlags.RESOLVED); + this.set(CommonFlags.Const | CommonFlags.Inlined | CommonFlags.Resolved); } } @@ -3366,10 +3366,10 @@ export class EnumValue extends VariableLikeElement { /** Declaration reference. */ declaration: EnumValueDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.ENUMVALUE, + ElementKind.EnumValue, name, parent, declaration @@ -3402,7 +3402,7 @@ export class Global extends VariableLikeElement { declaration: VariableLikeDeclarationStatement = parent.program.makeNativeVariableDeclaration(name) ) { super( - ElementKind.GLOBAL, + ElementKind.Global, name, parent, declaration @@ -3444,7 +3444,7 @@ export class Local extends VariableLikeElement { declaration: VariableLikeDeclarationStatement = parent.program.makeNativeVariableDeclaration(name) ) { super( - ElementKind.LOCAL, + ElementKind.Local, name, parent, declaration @@ -3491,12 +3491,12 @@ export class FunctionPrototype extends DeclaredElement { /** Declaration reference. */ declaration: FunctionDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.FUNCTION_PROTOTYPE, + ElementKind.FunctionPrototype, name, - mangleInternalName(name, parent, declaration.is(CommonFlags.INSTANCE)), + mangleInternalName(name, parent, declaration.is(CommonFlags.Instance)), parent.program, parent, declaration @@ -3528,19 +3528,19 @@ export class FunctionPrototype extends DeclaredElement { get isBound(): bool { var parent = this.parent; var parentKind = parent.kind; - if (parentKind == ElementKind.PROPERTY_PROTOTYPE) parentKind = parent.parent.kind; - return parentKind == ElementKind.CLASS || parentKind == ElementKind.INTERFACE; + if (parentKind == ElementKind.PropertyPrototype) parentKind = parent.parent.kind; + return parentKind == ElementKind.Class || parentKind == ElementKind.Interface; } /** Creates a clone of this prototype that is bound to a concrete class instead. */ toBound(classInstance: Class): FunctionPrototype { - assert(this.is(CommonFlags.INSTANCE)); + assert(this.is(CommonFlags.Instance)); assert(!this.isBound); var boundPrototypes = this.boundPrototypes; if (!boundPrototypes) this.boundPrototypes = boundPrototypes = new Map(); else if (boundPrototypes.has(classInstance)) return assert(boundPrototypes.get(classInstance)); var declaration = this.declaration; - assert(declaration.kind == NodeKind.METHODDECLARATION); + assert(declaration.kind == NodeKind.MethodDeclaration); var bound = new FunctionPrototype( this.name, classInstance, // ! @@ -3622,9 +3622,9 @@ export class Function extends TypedElement { contextualTypeArguments: Map | null = null ) { super( - ElementKind.FUNCTION, + ElementKind.Function, nameInclTypeParameters, - mangleInternalName(nameInclTypeParameters, prototype.parent, prototype.is(CommonFlags.INSTANCE)), + mangleInternalName(nameInclTypeParameters, prototype.parent, prototype.is(CommonFlags.Instance)), prototype.program, prototype.parent, prototype.declaration @@ -3632,13 +3632,13 @@ export class Function extends TypedElement { this.prototype = prototype; this.typeArguments = typeArguments; this.signature = signature; - this.flags = prototype.flags | CommonFlags.RESOLVED; + this.flags = prototype.flags | CommonFlags.Resolved; this.decoratorFlags = prototype.decoratorFlags; this.contextualTypeArguments = contextualTypeArguments; this.original = this; var program = prototype.program; this.type = signature.type; - if (!prototype.is(CommonFlags.AMBIENT)) { + if (!prototype.is(CommonFlags.Ambient)) { let localIndex = 0; let thisType = signature.thisType; if (thisType) { @@ -3680,8 +3680,8 @@ export class Function extends TypedElement { /** Gets the class or interface this function belongs to, if an instance method. */ getClassOrInterface(): Class | null { var parent = this.parent; - if (parent.kind == ElementKind.PROPERTY) parent = parent.parent; - if (parent.kind == ElementKind.CLASS || parent.kind == ElementKind.INTERFACE) { + if (parent.kind == ElementKind.Property) parent = parent.parent; + if (parent.kind == ElementKind.Class || parent.kind == ElementKind.Interface) { return parent; } return null; @@ -3697,7 +3697,7 @@ export class Function extends TypedElement { this.contextualTypeArguments ); stub.original = this.original; - stub.set(this.flags & ~CommonFlags.COMPILED | CommonFlags.STUB); + stub.set(this.flags & ~CommonFlags.Compiled | CommonFlags.Stub); return stub; } @@ -3705,7 +3705,7 @@ export class Function extends TypedElement { addLocal(type: Type, name: string | null = null, declaration: VariableDeclaration | null = null): Local { // if it has a name, check previously as this method will throw otherwise var localIndex = this.signature.parameterTypes.length + this.additionalLocals.length; - if (this.is(CommonFlags.INSTANCE)) ++localIndex; + if (this.is(CommonFlags.Instance)) ++localIndex; var localName = name != null ? name : `var$${localIndex}`; if (!declaration) declaration = this.program.makeNativeVariableDeclaration(localName); var local = new Local( @@ -3804,12 +3804,12 @@ export class FieldPrototype extends DeclaredElement { /** Declaration reference. */ declaration: FieldDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE + decoratorFlags: DecoratorFlags = DecoratorFlags.None ) { super( - ElementKind.FIELD_PROTOTYPE, + ElementKind.FieldPrototype, name, - mangleInternalName(name, parent, assert(declaration.is(CommonFlags.INSTANCE))), + mangleInternalName(name, parent, assert(declaration.is(CommonFlags.Instance))), parent.program, parent, declaration @@ -3855,7 +3855,7 @@ export class Field extends VariableLikeElement { type: Type ) { super( - ElementKind.FIELD, + ElementKind.Field, prototype.name, parent, prototype.declaration @@ -3871,7 +3871,7 @@ export class Field extends VariableLikeElement { /** Gets the field's `this` type. */ get thisType(): Type { var parent = this.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); return (parent).type; } @@ -3939,34 +3939,34 @@ export class PropertyPrototype extends DeclaredElement { firstDeclaration: FunctionDeclaration ) { super( - ElementKind.PROPERTY_PROTOTYPE, + ElementKind.PropertyPrototype, name, - mangleInternalName(name, parent, firstDeclaration.is(CommonFlags.INSTANCE)), + mangleInternalName(name, parent, firstDeclaration.is(CommonFlags.Instance)), parent.program, parent, firstDeclaration ); - this.flags &= ~(CommonFlags.GET | CommonFlags.SET); + this.flags &= ~(CommonFlags.Get | CommonFlags.Set); } /** Tests if this prototype is bound to a class. */ get isBound(): bool { switch (this.parent.kind) { - case ElementKind.CLASS: - case ElementKind.INTERFACE: return true; + case ElementKind.Class: + case ElementKind.Interface: return true; } return false; } /** Creates a clone of this prototype that is bound to a concrete class instead. */ toBound(classInstance: Class): PropertyPrototype { - assert(this.is(CommonFlags.INSTANCE)); + assert(this.is(CommonFlags.Instance)); assert(!this.isBound); var boundPrototypes = this.boundPrototypes; if (!boundPrototypes) this.boundPrototypes = boundPrototypes = new Map(); else if (boundPrototypes.has(classInstance)) return assert(boundPrototypes.get(classInstance)); var firstDeclaration = this.declaration; - assert(firstDeclaration.kind == NodeKind.METHODDECLARATION); + assert(firstDeclaration.kind == NodeKind.MethodDeclaration); var bound = new PropertyPrototype( this.name, classInstance, // ! @@ -4004,15 +4004,15 @@ export class Property extends VariableLikeElement { parent: Element ) { super( - ElementKind.PROPERTY, + ElementKind.Property, prototype.name, parent, Node.createVariableDeclaration( prototype.identifierNode, null, - prototype.is(CommonFlags.INSTANCE) - ? CommonFlags.INSTANCE - : CommonFlags.NONE, + prototype.is(CommonFlags.Instance) + ? CommonFlags.Instance + : CommonFlags.None, null, null, prototype.identifierNode.range ) @@ -4020,7 +4020,7 @@ export class Property extends VariableLikeElement { this.prototype = prototype; this.flags = prototype.flags; this.decoratorFlags = prototype.decoratorFlags; - if (this.is(CommonFlags.INSTANCE)) { + if (this.is(CommonFlags.Instance)) { registerConcreteElement(this.program, this); } } @@ -4035,7 +4035,7 @@ export class IndexSignature extends TypedElement { parent: Class ) { super( - ElementKind.INDEXSIGNATURE, + ElementKind.IndexSignature, "[]", parent.internalName + "[]", parent.program, @@ -4081,13 +4081,13 @@ export class ClassPrototype extends DeclaredElement { /** Declaration reference. */ declaration: ClassDeclaration, /** Pre-checked flags indicating built-in decorators. */ - decoratorFlags: DecoratorFlags = DecoratorFlags.NONE, + decoratorFlags: DecoratorFlags = DecoratorFlags.None, _isInterface: bool = false // FIXME ) { super( - _isInterface ? ElementKind.INTERFACE_PROTOTYPE : ElementKind.CLASS_PROTOTYPE, + _isInterface ? ElementKind.InterfacePrototype : ElementKind.ClassPrototype, name, - mangleInternalName(name, parent, declaration.is(CommonFlags.INSTANCE)), + mangleInternalName(name, parent, declaration.is(CommonFlags.Instance)), parent.program, parent, declaration @@ -4155,8 +4155,8 @@ export class ClassPrototype extends DeclaredElement { element = merged; } instanceMembers.set(name, element); - if (element.is(CommonFlags.EXPORT) && this.is(CommonFlags.MODULE_EXPORT)) { - element.set(CommonFlags.MODULE_EXPORT); // propagate + if (element.is(CommonFlags.Export) && this.is(CommonFlags.ModuleExport)) { + element.set(CommonFlags.ModuleExport); // propagate } this.program.elementsByDeclaration.set(originalDeclaration, element); return true; @@ -4230,9 +4230,9 @@ export class Class extends TypedElement { var lengthField = this.getMember("length"); if (!lengthField) return false; return ( - lengthField.kind == ElementKind.FIELD || + lengthField.kind == ElementKind.Field || ( - lengthField.kind == ElementKind.PROPERTY_PROTOTYPE && + lengthField.kind == ElementKind.PropertyPrototype && (lengthField).getterPrototype != null // TODO: resolve & check type? ) ) && ( @@ -4252,9 +4252,9 @@ export class Class extends TypedElement { _isInterface: bool = false // FIXME ) { super( - _isInterface ? ElementKind.INTERFACE : ElementKind.CLASS, + _isInterface ? ElementKind.Interface : ElementKind.Class, nameInclTypeParameters, - mangleInternalName(nameInclTypeParameters, prototype.parent, prototype.is(CommonFlags.INSTANCE)), + mangleInternalName(nameInclTypeParameters, prototype.parent, prototype.is(CommonFlags.Instance)), prototype.program, prototype.parent, prototype.declaration @@ -4265,11 +4265,11 @@ export class Class extends TypedElement { this.decoratorFlags = prototype.decoratorFlags; this.typeArguments = typeArguments; var usizeType = program.options.usizeType; - var type = new Type(usizeType.kind, usizeType.flags & ~TypeFlags.VALUE | TypeFlags.REFERENCE, usizeType.size); + var type = new Type(usizeType.kind, usizeType.flags & ~TypeFlags.Value | TypeFlags.Reference, usizeType.size); type.classReference = this; this.setType(type); - if (!this.hasDecorator(DecoratorFlags.UNMANAGED)) { + if (!this.hasDecorator(DecoratorFlags.Unmanaged)) { let id = program.nextClassId++; this._id = id; program.managedClasses.set(id, this); @@ -4336,7 +4336,7 @@ export class Class extends TypedElement { var current: Class | null = this; do { if (current == target) return true; - if (target.kind == ElementKind.INTERFACE) { + if (target.kind == ElementKind.Interface) { let interfaces = current.interfaces; if (interfaces) { for (let _values = Set_values(interfaces), i = 0, k = _values.length; i < k; ++i) { @@ -4381,7 +4381,7 @@ export class Class extends TypedElement { /** Gets the method of the specified name, resolved with the given type arguments. */ getMethod(name: string, typeArguments: Type[] | null = null): Function | null { var member = this.getMember(name); - if (member && member.kind == ElementKind.FUNCTION_PROTOTYPE) { + if (member && member.kind == ElementKind.FunctionPrototype) { return this.program.resolver.resolveFunction(member, typeArguments); } return null; @@ -4390,7 +4390,7 @@ export class Class extends TypedElement { /** Calculates the memory offset of the specified field. */ offsetof(fieldName: string): u32 { var member = assert(this.getMember(fieldName)); - assert(member.kind == ElementKind.FIELD); + assert(member.kind == ElementKind.Field); return (member).memoryOffset; } @@ -4412,7 +4412,7 @@ export class Class extends TypedElement { /** Writes a field value to a buffer and returns the number of bytes written. */ writeField(name: string, value: T, buffer: Uint8Array, baseOffset: i32 = this.program.totalOverhead): i32 { var member = this.getMember(name); - if (member && member.kind == ElementKind.FIELD) { + if (member && member.kind == ElementKind.Field) { let fieldInstance = member; let offset = baseOffset + fieldInstance.memoryOffset; let typeKind = fieldInstance.type.kind; @@ -4435,18 +4435,18 @@ export class Class extends TypedElement { writeI32(i32(value), buffer, offset); return 4; } - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { if (this.program.options.isWasm64) { if (i64_is(value)) { writeI64(value, buffer, offset); } else { - writeI32AsI64(i32(value), buffer, offset, typeKind == TypeKind.USIZE); + writeI32AsI64(i32(value), buffer, offset, typeKind == TypeKind.Usize); } return 8; } else { if (i64_is(value)) { - writeI64AsI32(value, buffer, offset, typeKind == TypeKind.USIZE); + writeI64AsI32(value, buffer, offset, typeKind == TypeKind.Usize); } else { writeI32(i32(value), buffer, offset); } @@ -4546,7 +4546,7 @@ export class Class extends TypedElement { // Check that there are no managed instance fields for (let _values = Map_values(instanceMembers), i = 0, k = _values.length; i < k; ++i) { let member = unchecked(_values[i]); - if (member.kind == ElementKind.FIELD) { + if (member.kind == ElementKind.Field) { let fieldType = (member).type; if (fieldType.isManaged) return false; } @@ -4648,14 +4648,14 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { if (newer.members) return null; var merged: DeclaredElement | null = null; switch (older.kind) { - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { switch (newer.kind) { - case ElementKind.NAMESPACE: { + case ElementKind.Namespace: { copyMembers(newer, older); merged = older; break; } - case ElementKind.TYPEDEFINITION: { + case ElementKind.TypeDefinition: { if (!older.shadowType) { older.shadowType = newer; copyMembers(newer, older); @@ -4666,30 +4666,30 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { } break; } - case ElementKind.CLASS_PROTOTYPE: - case ElementKind.ENUM: { - if (newer.kind == ElementKind.NAMESPACE) { + case ElementKind.ClassPrototype: + case ElementKind.Enum: { + if (newer.kind == ElementKind.Namespace) { copyMembers(newer, older); merged = older; break; } break; } - case ElementKind.NAMESPACE: { + case ElementKind.Namespace: { switch (newer.kind) { - case ElementKind.ENUM: - case ElementKind.CLASS_PROTOTYPE: // TS2434 - case ElementKind.FUNCTION_PROTOTYPE: { // TS2434 + case ElementKind.Enum: + case ElementKind.ClassPrototype: // TS2434 + case ElementKind.FunctionPrototype: { // TS2434 copyMembers(older, newer); merged = newer; break; } - case ElementKind.NAMESPACE: { + case ElementKind.Namespace: { copyMembers(newer, older); merged = older; break; } - case ElementKind.TYPEDEFINITION: { + case ElementKind.TypeDefinition: { if (!older.shadowType) { older.shadowType = newer; copyMembers(newer, older); @@ -4700,8 +4700,8 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { } break; } - case ElementKind.GLOBAL: { - if (newer.kind == ElementKind.TYPEDEFINITION) { + case ElementKind.Global: { + if (newer.kind == ElementKind.TypeDefinition) { if (!older.shadowType) { older.shadowType = newer; copyMembers(newer, older); @@ -4710,11 +4710,11 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { } break; } - case ElementKind.TYPEDEFINITION: { + case ElementKind.TypeDefinition: { switch (newer.kind) { - case ElementKind.GLOBAL: - case ElementKind.FUNCTION_PROTOTYPE: - case ElementKind.NAMESPACE: { + case ElementKind.Global: + case ElementKind.FunctionPrototype: + case ElementKind.Namespace: { if (!newer.shadowType) { newer.shadowType = older; copyMembers(older, newer); @@ -4727,8 +4727,8 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { } } if (merged) { - let olderIsExport = older.is(CommonFlags.EXPORT) || older.hasDecorator(DecoratorFlags.GLOBAL); - let newerIsExport = newer.is(CommonFlags.EXPORT) || newer.hasDecorator(DecoratorFlags.GLOBAL); + let olderIsExport = older.is(CommonFlags.Export) || older.hasDecorator(DecoratorFlags.Global); + let newerIsExport = newer.is(CommonFlags.Export) || newer.hasDecorator(DecoratorFlags.Global); if (olderIsExport != newerIsExport) { older.program.error( DiagnosticCode.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, @@ -4762,23 +4762,23 @@ export function mangleInternalName( asGlobal: bool = false ): string { switch (parent.kind) { - case ElementKind.FILE: { + case ElementKind.File: { if (asGlobal) return name; return parent.internalName + PATH_DELIMITER + name; } - case ElementKind.FUNCTION: { + case ElementKind.Function: { if (asGlobal) return name; assert(!isInstance); return parent.internalName + INNER_DELIMITER + name; } - case ElementKind.PROPERTY_PROTOTYPE: // properties are just containers - case ElementKind.PROPERTY: { // + case ElementKind.PropertyPrototype: // properties are just containers + case ElementKind.Property: { // parent = parent.parent; // fall-through } default: { return ( - mangleInternalName(parent.name, parent.parent, parent.is(CommonFlags.INSTANCE), asGlobal) + + mangleInternalName(parent.name, parent.parent, parent.is(CommonFlags.Instance), asGlobal) + (isInstance ? INSTANCE_DELIMITER : STATIC_DELIMITER) + name ); } diff --git a/src/resolver.ts b/src/resolver.ts index 9297041b2a..cd61430977 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -110,9 +110,9 @@ import { /** Indicates whether errors are reported or not. */ export const enum ReportMode { /** Report errors. */ - REPORT, + Report, /** Swallow errors. */ - SWALLOW + Swallow } /** Provides tools to resolve types and expressions. */ @@ -148,10 +148,10 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { switch (node.kind) { - case NodeKind.NAMEDTYPE: { + case NodeKind.NamedType: { return this.resolveNamedType( node, ctxElement, @@ -159,7 +159,7 @@ export class Resolver extends DiagnosticEmitter { reportMode ); } - case NodeKind.FUNCTIONTYPE: { + case NodeKind.FunctionType: { return this.resolveFunctionType( node, ctxElement, @@ -181,7 +181,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var nameNode = node.name; var typeArgumentNodes = node.typeArguments; @@ -193,7 +193,7 @@ export class Resolver extends DiagnosticEmitter { if (ctxTypes && ctxTypes.has(simpleName)) { let type = assert(ctxTypes.get(simpleName)); if (typeArgumentNodes && typeArgumentNodes.length > 0) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, node.range, type.toString() @@ -202,7 +202,7 @@ export class Resolver extends DiagnosticEmitter { } if (node.isNullable) { if (type.isInternalReference) return type.asNullable(); - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_cannot_be_nullable, node.range, type.toString() @@ -225,9 +225,9 @@ export class Resolver extends DiagnosticEmitter { } else { // Handle enums (become i32) - if (element.kind == ElementKind.ENUM) { + if (element.kind == ElementKind.Enum) { if (typeArgumentNodes && typeArgumentNodes.length > 0) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, node.range, element.internalName @@ -235,7 +235,7 @@ export class Resolver extends DiagnosticEmitter { } } if (node.isNullable) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_cannot_be_nullable, node.range, `${element.name}/i32` @@ -247,8 +247,8 @@ export class Resolver extends DiagnosticEmitter { // Handle classes and interfaces if ( - element.kind == ElementKind.CLASS_PROTOTYPE || - element.kind == ElementKind.INTERFACE_PROTOTYPE + element.kind == ElementKind.ClassPrototype || + element.kind == ElementKind.InterfacePrototype ) { let instance = this.resolveClassInclTypeArguments( element, @@ -264,13 +264,13 @@ export class Resolver extends DiagnosticEmitter { } // Handle type definitions - if (element.kind == ElementKind.TYPEDEFINITION) { + if (element.kind == ElementKind.TypeDefinition) { let typeDefinition = element; // Shortcut already resolved (mostly builtins) - if (element.is(CommonFlags.RESOLVED)) { + if (element.is(CommonFlags.Resolved)) { if (typeArgumentNodes && typeArgumentNodes.length > 0) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, node.range, element.internalName @@ -280,7 +280,7 @@ export class Resolver extends DiagnosticEmitter { let type = typeDefinition.type; if (node.isNullable) { if (type.isInternalReference) return type.asNullable(); - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_cannot_be_nullable, nameNode.range, nameNode.identifier.text @@ -328,7 +328,7 @@ export class Resolver extends DiagnosticEmitter { if (!type) return null; if (node.isNullable) { if (type.isInternalReference) return type.asNullable(); - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_cannot_be_nullable, nameNode.range, nameNode.identifier.text @@ -337,7 +337,7 @@ export class Resolver extends DiagnosticEmitter { } return type; } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Cannot_find_name_0, nameNode.range, nameNode.identifier.text @@ -355,7 +355,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var explicitThisType = node.explicitThisType; var thisType: Type | null = null; @@ -388,7 +388,7 @@ export class Resolver extends DiagnosticEmitter { } let parameterTypeNode = parameterNode.type; if (isTypeOmitted(parameterTypeNode)) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, parameterTypeNode.range @@ -408,7 +408,7 @@ export class Resolver extends DiagnosticEmitter { var returnTypeNode = node.returnType; var returnType: Type | null; if (isTypeOmitted(returnTypeNode)) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, returnTypeNode.range @@ -438,7 +438,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const typeArgumentNode = this.ensureOneTypeArgument(node, reportMode); if (!typeArgumentNode) return null; @@ -448,18 +448,18 @@ export class Resolver extends DiagnosticEmitter { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: return Type.i32; - case TypeKind.ISIZE: if (!this.program.options.isWasm64) return Type.i32; + case TypeKind.Isize: if (!this.program.options.isWasm64) return Type.i32; case TypeKind.I64: return Type.i64; case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: - case TypeKind.BOOL: return Type.u32; - case TypeKind.USIZE: if (!this.program.options.isWasm64) return Type.u32; + case TypeKind.Bool: return Type.u32; + case TypeKind.Usize: if (!this.program.options.isWasm64) return Type.u32; case TypeKind.U64: return Type.u64; case TypeKind.F32: return Type.f32; case TypeKind.F64: return Type.f64; case TypeKind.V128: return Type.v128; - case TypeKind.VOID: return Type.void; + case TypeKind.Void: return Type.void; default: assert(false); } return null; @@ -473,7 +473,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const typeArgumentNode = this.ensureOneTypeArgument(node, reportMode); if (!typeArgumentNode) return null; @@ -481,7 +481,7 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; var classReference = typeArgument.classReference; if (!classReference) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, typeArgumentNode.range, typeArgument.toString() @@ -492,7 +492,7 @@ export class Resolver extends DiagnosticEmitter { var overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); if (overload) { let parameterTypes = overload.signature.parameterTypes; - if (overload.is(CommonFlags.STATIC)) { + if (overload.is(CommonFlags.Static)) { assert(parameterTypes.length == 2); return parameterTypes[1]; } else { @@ -500,7 +500,7 @@ export class Resolver extends DiagnosticEmitter { return parameterTypes[0]; } } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, typeArgumentNode.range, typeArgument.toString() @@ -517,7 +517,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const typeArgumentNode = this.ensureOneTypeArgument(node, reportMode); if (!typeArgumentNode) return null; @@ -528,7 +528,7 @@ export class Resolver extends DiagnosticEmitter { let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); if (overload) return overload.signature.returnType; } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, typeArgumentNode.range, typeArgument.toString() @@ -545,7 +545,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventualy diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const typeArgumentNode = this.ensureOneTypeArgument(node, reportMode); if (!typeArgumentNode) return null; @@ -553,7 +553,7 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; var signatureReference = typeArgument.getSignature(); if (signatureReference) return signatureReference.returnType; - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_has_no_call_signatures, typeArgumentNode.range, typeArgument.toString() @@ -570,7 +570,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const typeArgumentNode = this.ensureOneTypeArgument(node, reportMode); if (!typeArgumentNode) return null; @@ -587,11 +587,11 @@ export class Resolver extends DiagnosticEmitter { /** Contextual element. */ ctxElement: Element, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var element = ctxElement.lookup(node.identifier.text, true); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Cannot_find_name_0, node.range, node.identifier.text @@ -603,7 +603,7 @@ export class Resolver extends DiagnosticEmitter { var next = node.next; while (next) { if (!(element = element.getMember(next.identifier.text))) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, next.range, next.identifier.text, prev.identifier.text @@ -630,7 +630,7 @@ export class Resolver extends DiagnosticEmitter { /** Alternative report node in case of empty type arguments. */ alternativeReportNode: Node | null = null, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type[] | null { var minParameterCount = 0, @@ -641,7 +641,7 @@ export class Resolver extends DiagnosticEmitter { } var argumentCount = typeArgumentNodes ? typeArgumentNodes.length : 0; if (argumentCount < minParameterCount || argumentCount > maxParameterCount) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expected_0_type_arguments_but_got_1, argumentCount @@ -686,14 +686,14 @@ export class Resolver extends DiagnosticEmitter { node: CallExpression, prototype: FunctionPrototype, ctxFlow: Flow, - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Function | null { var typeArguments = node.typeArguments; // resolve generic call if type arguments have been provided if (typeArguments) { - if (!prototype.is(CommonFlags.GENERIC)) { - if (reportMode == ReportMode.REPORT) { + if (!prototype.is(CommonFlags.Generic)) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, node.expression.range, prototype.internalName @@ -712,7 +712,7 @@ export class Resolver extends DiagnosticEmitter { } // infer generic call if type arguments have been omitted - if (prototype.is(CommonFlags.GENERIC)) { + if (prototype.is(CommonFlags.Generic)) { let contextualTypeArguments = cloneMap(ctxFlow.contextualTypeArguments); // fill up contextual types with auto for each generic component @@ -741,7 +741,7 @@ export class Resolver extends DiagnosticEmitter { continue; } // missing initializer -> too few arguments - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expected_0_arguments_but_got_1, node.range, numParameters.toString(), numArguments.toString() @@ -751,7 +751,7 @@ export class Resolver extends DiagnosticEmitter { } let typeNode = parameterNodes[i].type; if (typeNode.hasGenericComponent(typeParameterNodes)) { - let type = this.resolveExpression(argumentExpression, ctxFlow, Type.auto, ReportMode.SWALLOW); + let type = this.resolveExpression(argumentExpression, ctxFlow, Type.auto, ReportMode.Swallow); if (type) { this.propagateInferredGenericTypes( typeNode, @@ -780,9 +780,9 @@ export class Resolver extends DiagnosticEmitter { // Default parameters are resolved in context of the called function, not the calling function let parent = prototype.parent; let defaultTypeContextualTypeArguments: Map | null = null; - if (parent.kind == ElementKind.CLASS) { + if (parent.kind == ElementKind.Class) { defaultTypeContextualTypeArguments = (parent).contextualTypeArguments; - } else if (parent.kind == ElementKind.FUNCTION) { + } else if (parent.kind == ElementKind.Function) { defaultTypeContextualTypeArguments = (parent).contextualTypeArguments; } let resolvedDefaultType = this.resolveType( @@ -798,7 +798,7 @@ export class Resolver extends DiagnosticEmitter { } // unused template, e.g. `function test(): void {...}` called as `test()` // invalid because the type is effectively unknown inside the function body - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_argument_expected, node.expression.range.atEnd @@ -831,14 +831,14 @@ export class Resolver extends DiagnosticEmitter { /** The names of the type parameters being inferred. */ typeParameterNames: Set ): void { - if (node.kind == NodeKind.NAMEDTYPE) { + if (node.kind == NodeKind.NamedType) { let namedTypeNode = node; let typeArgumentNodes = namedTypeNode.typeArguments; if (typeArgumentNodes && typeArgumentNodes.length > 0) { // foo(bar: Array) let classReference = type.classReference; if (classReference) { let classPrototype = this.resolveTypeName(namedTypeNode.name, ctxElement); - if (!classPrototype || classPrototype.kind != ElementKind.CLASS_PROTOTYPE) return; + if (!classPrototype || classPrototype.kind != ElementKind.ClassPrototype) return; if (classReference.prototype == classPrototype) { let typeArguments = classReference.typeArguments; if (typeArguments && typeArguments.length == typeArgumentNodes.length) { @@ -865,7 +865,7 @@ export class Resolver extends DiagnosticEmitter { ) ctxTypes.set(name, type); } } - } else if (node.kind == NodeKind.FUNCTIONTYPE) { // foo(bar: (baz: T) => i32)) + } else if (node.kind == NodeKind.FunctionType) { // foo(bar: (baz: T) => i32)) let functionTypeNode = node; let parameterNodes = functionTypeNode.parameters; let signatureReference = type.signatureReference; @@ -909,8 +909,8 @@ export class Resolver extends DiagnosticEmitter { /** Gets the concrete type of an element. */ getTypeOfElement(element: Element): Type | null { var kind = element.kind; - if (kind == ElementKind.GLOBAL) { - if (!this.ensureResolvedLazyGlobal(element, ReportMode.SWALLOW)) return null; + if (kind == ElementKind.Global) { + if (!this.ensureResolvedLazyGlobal(element, ReportMode.Swallow)) return null; } if (isTypedElement(kind)) { let type = (element).type; @@ -942,106 +942,106 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { - while (node.kind == NodeKind.PARENTHESIZED) { // skip + while (node.kind == NodeKind.Parenthesized) { // skip node = (node).expression; } switch (node.kind) { - case NodeKind.ASSERTION: { + case NodeKind.Assertion: { return this.lookupAssertionExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.BINARY: { + case NodeKind.Binary: { return this.lookupBinaryExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.CALL: { + case NodeKind.Call: { return this.lookupCallExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.COMMA: { + case NodeKind.Comma: { return this.lookupCommaExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.ELEMENTACCESS: { + case NodeKind.ElementAccess: { return this.lookupElementAccessExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.FUNCTION: { + case NodeKind.Function: { return this.lookupFunctionExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.IDENTIFIER: - case NodeKind.FALSE: - case NodeKind.NULL: - case NodeKind.TRUE: { + case NodeKind.Identifier: + case NodeKind.False: + case NodeKind.Null: + case NodeKind.True: { return this.lookupIdentifierExpression( node, ctxFlow, ctxFlow.actualFunction, reportMode ); } - case NodeKind.THIS: { + case NodeKind.This: { return this.lookupThisExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.SUPER: { + case NodeKind.Super: { return this.lookupSuperExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.INSTANCEOF: { + case NodeKind.InstanceOf: { return this.lookupInstanceOfExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.LITERAL: { + case NodeKind.Literal: { return this.lookupLiteralExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.NEW: { + case NodeKind.New: { return this.lookupNewExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.PROPERTYACCESS: { + case NodeKind.PropertyAccess: { return this.lookupPropertyAccessExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.TERNARY: { + case NodeKind.Ternary: { return this.lookupTernaryExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.UNARYPOSTFIX: { + case NodeKind.UnaryPostfix: { return this.lookupUnaryPostfixExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.UNARYPREFIX: { + case NodeKind.UnaryPrefix: { return this.lookupUnaryPrefixExpression( node, ctxFlow, ctxType, reportMode @@ -1064,7 +1064,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const resolvingExpressions = this.resolvingExpressions; if (resolvingExpressions.has(node)) return null; @@ -1079,106 +1079,106 @@ export class Resolver extends DiagnosticEmitter { node: Expression, ctxFlow: Flow, ctxType: Type = Type.auto, - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { - while (node.kind == NodeKind.PARENTHESIZED) { // skip + while (node.kind == NodeKind.Parenthesized) { // skip node = (node).expression; } switch (node.kind) { - case NodeKind.ASSERTION: { + case NodeKind.Assertion: { return this.resolveAssertionExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.BINARY: { + case NodeKind.Binary: { return this.resolveBinaryExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.CALL: { + case NodeKind.Call: { return this.resolveCallExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.COMMA: { + case NodeKind.Comma: { return this.resolveCommaExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.ELEMENTACCESS: { + case NodeKind.ElementAccess: { return this.resolveElementAccessExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.FUNCTION: { + case NodeKind.Function: { return this.resolveFunctionExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.IDENTIFIER: - case NodeKind.FALSE: - case NodeKind.NULL: - case NodeKind.TRUE: { + case NodeKind.Identifier: + case NodeKind.False: + case NodeKind.Null: + case NodeKind.True: { return this.resolveIdentifierExpression( node, ctxFlow, ctxType, ctxFlow.actualFunction, reportMode ); } - case NodeKind.THIS: { + case NodeKind.This: { return this.resolveThisExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.SUPER: { + case NodeKind.Super: { return this.resolveSuperExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.INSTANCEOF: { + case NodeKind.InstanceOf: { return this.resolveInstanceOfExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.LITERAL: { + case NodeKind.Literal: { return this.resolveLiteralExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.NEW: { + case NodeKind.New: { return this.resolveNewExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.PROPERTYACCESS: { + case NodeKind.PropertyAccess: { return this.resolvePropertyAccessExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.TERNARY: { + case NodeKind.Ternary: { return this.resolveTernaryExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.UNARYPOSTFIX: { + case NodeKind.UnaryPostfix: { return this.resolveUnaryPostfixExpression( node, ctxFlow, ctxType, reportMode ); } - case NodeKind.UNARYPREFIX: { + case NodeKind.UnaryPrefix: { return this.resolveUnaryPrefixExpression( node, ctxFlow, ctxType, reportMode @@ -1198,12 +1198,12 @@ export class Resolver extends DiagnosticEmitter { /** Element to search. */ ctxElement: Element = ctxFlow.actualFunction, // differs for enums and namespaces /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { switch (node.kind) { - case NodeKind.TRUE: - case NodeKind.FALSE: - case NodeKind.NULL: { + case NodeKind.True: + case NodeKind.False: + case NodeKind.Null: { let type = this.resolveIdentifierExpression(node, ctxFlow, Type.auto, ctxElement, reportMode); return type ? this.getElementOfType(type) : null; } @@ -1233,7 +1233,7 @@ export class Resolver extends DiagnosticEmitter { this.currentElementExpression = null; return element; } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Cannot_find_name_0, node.range, name @@ -1253,12 +1253,12 @@ export class Resolver extends DiagnosticEmitter { /** Element to search. */ ctxElement: Element = ctxFlow.actualFunction, // differs for enums and namespaces /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { switch (node.kind) { - case NodeKind.TRUE: - case NodeKind.FALSE: return Type.bool; - case NodeKind.NULL: { + case NodeKind.True: + case NodeKind.False: return Type.bool; + case NodeKind.Null: { let classReference = ctxType.getClass(); if (classReference) { return classReference.type.asNullable(); @@ -1275,14 +1275,14 @@ export class Resolver extends DiagnosticEmitter { } var element = this.lookupIdentifierExpression(node, ctxFlow, ctxElement, reportMode); if (!element) return null; - if (element.kind == ElementKind.FUNCTION_PROTOTYPE) { + if (element.kind == ElementKind.FunctionPrototype) { let instance = this.resolveFunction(element, null, new Map(), reportMode); if (!instance) return null; element = instance; } var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -1293,8 +1293,8 @@ export class Resolver extends DiagnosticEmitter { } /** Resolves a lazily compiled global, i.e. a static class field or annotated `@lazy`. */ - private ensureResolvedLazyGlobal(global: Global, reportMode: ReportMode = ReportMode.REPORT): bool { - if (global.is(CommonFlags.RESOLVED)) return true; + private ensureResolvedLazyGlobal(global: Global, reportMode: ReportMode = ReportMode.Report): bool { + if (global.is(CommonFlags.Resolved)) return true; var typeNode = global.typeNode; var type = typeNode ? this.resolveType(typeNode, global.parent, null, reportMode) @@ -1318,7 +1318,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var targetNode = node.expression; var target = this.lookupExpression(targetNode, ctxFlow, ctxType, reportMode); // reports @@ -1327,16 +1327,16 @@ export class Resolver extends DiagnosticEmitter { // Resolve variable-likes to their class type first switch (target.kind) { - case ElementKind.GLOBAL: if (!this.ensureResolvedLazyGlobal(target, reportMode)) return null; - case ElementKind.ENUMVALUE: - case ElementKind.LOCAL: - case ElementKind.FIELD: { // someVar.prop + case ElementKind.Global: if (!this.ensureResolvedLazyGlobal(target, reportMode)) return null; + case ElementKind.EnumValue: + case ElementKind.Local: + case ElementKind.Field: { // someVar.prop let variableLikeElement = target; let type = variableLikeElement.type; assert(type != Type.void); let classReference = type.getClassOrWrapper(this.program); if (!classReference) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, node.property.range, propertyName, variableLikeElement.type.toString() @@ -1347,19 +1347,19 @@ export class Resolver extends DiagnosticEmitter { target = classReference; break; } - case ElementKind.PROPERTY_PROTOTYPE: { // SomeClass.prop + case ElementKind.PropertyPrototype: { // SomeClass.prop let propertyInstance = this.resolveProperty(target, reportMode); if (!propertyInstance) return null; target = propertyInstance; // fall-through } - case ElementKind.PROPERTY: { // someInstance.prop + case ElementKind.Property: { // someInstance.prop let propertyInstance = target; let getterInstance = assert(propertyInstance.getterInstance); // must have a getter let type = getterInstance.signature.returnType; let classReference = type.getClassOrWrapper(this.program); if (!classReference) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, node.property.range, propertyName, type.toString() @@ -1370,15 +1370,15 @@ export class Resolver extends DiagnosticEmitter { target = classReference; break; } - case ElementKind.INDEXSIGNATURE: { // someInstance[x].prop + case ElementKind.IndexSignature: { // someInstance[x].prop let indexSignature = target; let parent = indexSignature.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let elementExpression = assert(this.currentElementExpression); let indexedGet = classInstance.lookupOverload(OperatorKind.INDEXED_GET); if (!indexedGet) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, elementExpression.range, parent.internalName @@ -1389,7 +1389,7 @@ export class Resolver extends DiagnosticEmitter { let returnType = indexedGet.signature.returnType; let classReference = returnType.getClassOrWrapper(this.program); if (!classReference) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, node.property.range, propertyName, returnType.toString() @@ -1400,22 +1400,22 @@ export class Resolver extends DiagnosticEmitter { target = classReference; break; } - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { // Function with shadow type, i.e. function Symbol() + type Symbol = _Symbol let shadowType = target.shadowType; if (shadowType) { - if (!shadowType.is(CommonFlags.RESOLVED)) { + if (!shadowType.is(CommonFlags.Resolved)) { let resolvedType = this.resolveType(shadowType.typeNode, shadowType.parent, null, reportMode); if (resolvedType) shadowType.setType(resolvedType); } let classReference = shadowType.type.classReference; if (classReference) target = classReference.prototype; break; - } else if (!target.is(CommonFlags.GENERIC)) { + } else if (!target.is(CommonFlags.Generic)) { // Inherit from 'Function' if not overridden, i.e. fn.call let ownMember = target.getMember(propertyName); if (!ownMember) { - let functionInstance = this.resolveFunction(target, null, new Map(), ReportMode.SWALLOW); + let functionInstance = this.resolveFunction(target, null, new Map(), ReportMode.Swallow); if (functionInstance) { let wrapper = functionInstance.type.getClassOrWrapper(this.program); if (wrapper) target = wrapper; @@ -1428,18 +1428,18 @@ export class Resolver extends DiagnosticEmitter { // Look up the member within switch (target.kind) { - case ElementKind.CLASS_PROTOTYPE: - case ElementKind.INTERFACE_PROTOTYPE: - case ElementKind.CLASS: - case ElementKind.INTERFACE: { + case ElementKind.ClassPrototype: + case ElementKind.InterfacePrototype: + case ElementKind.Class: + case ElementKind.Interface: { do { let member = target.getMember(propertyName); if (member) { - if (member.kind == ElementKind.PROPERTY_PROTOTYPE) { + if (member.kind == ElementKind.PropertyPrototype) { let propertyInstance = this.resolveProperty(member, reportMode); if (!propertyInstance) return null; member = propertyInstance; - if (propertyInstance.is(CommonFlags.STATIC)) { + if (propertyInstance.is(CommonFlags.Static)) { this.currentThisExpression = null; } else { this.currentThisExpression = targetNode; @@ -1452,8 +1452,8 @@ export class Resolver extends DiagnosticEmitter { } // traverse inherited static members on the base prototype if target is a class prototype if ( - target.kind == ElementKind.CLASS_PROTOTYPE || - target.kind == ElementKind.INTERFACE_PROTOTYPE + target.kind == ElementKind.ClassPrototype || + target.kind == ElementKind.InterfacePrototype ) { let classPrototype = target; let basePrototype = classPrototype.basePrototype; @@ -1464,8 +1464,8 @@ export class Resolver extends DiagnosticEmitter { } // traverse inherited instance members on the base class if target is a class instance } else if ( - target.kind == ElementKind.CLASS || - target.kind == ElementKind.INTERFACE + target.kind == ElementKind.Class || + target.kind == ElementKind.Interface ) { let classInstance = target; let baseInstance = classInstance.base; @@ -1491,7 +1491,7 @@ export class Resolver extends DiagnosticEmitter { } } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Property_0_does_not_exist_on_type_1, node.property.range, propertyName, target.internalName @@ -1509,13 +1509,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupPropertyAccessExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -1534,7 +1534,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var targetExpression = node.expression; var targetType = this.resolveExpression(targetExpression, ctxFlow, ctxType, reportMode); @@ -1551,7 +1551,7 @@ export class Resolver extends DiagnosticEmitter { classReference = classReference.base; } while(classReference); } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, targetExpression.range, targetType.toString() @@ -1569,13 +1569,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupElementAccessExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -1619,7 +1619,7 @@ export class Resolver extends DiagnosticEmitter { if (ctxType.isValue) { // compile to contextual type if matching switch (ctxType.kind) { - case TypeKind.BOOL: { + case TypeKind.Bool: { if (i64_is_bool(intValue)) return Type.bool; break; } @@ -1647,14 +1647,14 @@ export class Resolver extends DiagnosticEmitter { if (i64_is_u32(intValue)) return Type.u32; break; } - case TypeKind.ISIZE: { + case TypeKind.Isize: { if (!this.program.options.isWasm64) { if (i64_is_i32(intValue)) return Type.isize32; break; } return Type.isize64; } - case TypeKind.USIZE: { + case TypeKind.Usize: { if (!this.program.options.isWasm64) { if (i64_is_u32(intValue)) return Type.usize32; break; @@ -1682,11 +1682,11 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { switch (node.assertionKind) { - case AssertionKind.AS: - case AssertionKind.PREFIX: { + case AssertionKind.As: + case AssertionKind.Prefix: { let type = this.resolveType( assert(node.toType), // must be set if not NONNULL ctxFlow.actualFunction, @@ -1696,7 +1696,7 @@ export class Resolver extends DiagnosticEmitter { if (!type) return null; let element = this.getElementOfType(type); if (element) return element; - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_illegal_in_this_context, node.range, type.toString() @@ -1706,14 +1706,14 @@ export class Resolver extends DiagnosticEmitter { this.currentElementExpression = null; return null; } - case AssertionKind.NONNULL: { + case AssertionKind.NonNull: { return this.lookupExpression(node.expression, ctxFlow, ctxType, reportMode); } - case AssertionKind.CONST: { + case AssertionKind.Const: { // TODO: decide on the layout of ReadonlyArray first // let element = this.lookupExpression(node.expression, ctxFlow, ctxType, reportMode); // if (!element) return null; - // if (element.kind == ElementKind.CLASS && (element).extends(this.program.arrayPrototype)) { + // if (element.kind == ElementKind.Class && (element).extends(this.program.arrayPrototype)) { // let elementType = assert((element).getTypeArgumentsTo(this.program.arrayPrototype))[0]; // return this.resolveClass(this.program.readonlyArrayPrototype, [ elementType ]); // } @@ -1738,11 +1738,11 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { switch (node.assertionKind) { - case AssertionKind.AS: - case AssertionKind.PREFIX: { + case AssertionKind.As: + case AssertionKind.Prefix: { return this.resolveType( assert(node.toType), ctxFlow.actualFunction, @@ -1750,16 +1750,16 @@ export class Resolver extends DiagnosticEmitter { reportMode ); } - case AssertionKind.NONNULL: { + case AssertionKind.NonNull: { let type = this.resolveExpression(node.expression, ctxFlow, ctxType, reportMode); return type ? type.nonNullableType : null; } - case AssertionKind.CONST: { + case AssertionKind.Const: { let element = this.lookupExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; let type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -1782,13 +1782,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveUnaryPrefixExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(node.operator), type.toString() @@ -1807,14 +1807,14 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var operand = node.operand; var operator = node.operator; switch (operator) { case Token.MINUS: { // implicitly negate if an integer literal to distinguish between i32/u32/i64 - if (operand.isLiteralKind(LiteralKind.INTEGER)) { + if (operand.isLiteralKind(LiteralKind.Integer)) { return this.determineIntegerLiteralType( operand, true, @@ -1834,7 +1834,7 @@ export class Resolver extends DiagnosticEmitter { if (overload) return overload.signature.returnType; } if (!type.isNumericValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(operator), type.toString() @@ -1863,7 +1863,7 @@ export class Resolver extends DiagnosticEmitter { if (overload) return overload.signature.returnType; } if (!type.isNumericValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, "~", type.toString() @@ -1874,7 +1874,7 @@ export class Resolver extends DiagnosticEmitter { return type.intType; } case Token.DOT_DOT_DOT: { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Not_implemented_0, node.range, "Spread operator" @@ -1899,13 +1899,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveUnaryPostfixExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(node.operator), type.toString() @@ -1924,7 +1924,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var operator = node.operator; switch (operator) { @@ -1938,7 +1938,7 @@ export class Resolver extends DiagnosticEmitter { if (overload) return overload.signature.returnType; } if (!type.isNumericValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(operator), type.toString() @@ -1962,13 +1962,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveBinaryExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (element) return element; // otherwise void - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_illegal_in_this_context, node.range, type.toString() @@ -1986,7 +1986,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var left = node.left; var right = node.right; @@ -2026,7 +2026,7 @@ export class Resolver extends DiagnosticEmitter { if (overload) return overload.signature.returnType; } if (!leftType.isNumericValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(operator), leftType.toString() @@ -2077,7 +2077,7 @@ export class Resolver extends DiagnosticEmitter { if (!rightType) return null; let commonType = Type.commonDenominator(leftType, rightType, false); if (!commonType) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, node.range, leftType.toString(), rightType.toString() @@ -2100,7 +2100,7 @@ export class Resolver extends DiagnosticEmitter { if (overload) return overload.signature.returnType; } if (!leftType.isIntegerValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, operatorTokenToString(operator), leftType.toString() @@ -2127,7 +2127,7 @@ export class Resolver extends DiagnosticEmitter { if (!rightType) return null; let commonType = Type.commonDenominator(leftType, rightType, false); if (!commonType || !commonType.isIntegerValue) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, node.range, operatorTokenToString(operator), leftType.toString(), rightType.toString() @@ -2157,7 +2157,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { if (ctxFlow.isInline) { let thisLocal = ctxFlow.lookupLocal(CommonNames.this_); @@ -2173,7 +2173,7 @@ export class Resolver extends DiagnosticEmitter { this.currentElementExpression = null; return parent; } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode._this_cannot_be_referenced_in_current_location, node.range @@ -2191,13 +2191,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupThisExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -2216,7 +2216,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { if (ctxFlow.isInline) { let superLocal = ctxFlow.lookupLocal(CommonNames.super_); @@ -2227,7 +2227,7 @@ export class Resolver extends DiagnosticEmitter { } } var parent: Element | null = ctxFlow.actualFunction.parent; - if (parent && parent.kind == ElementKind.CLASS) { + if (parent && parent.kind == ElementKind.Class) { let base = (parent).base; if (base) { this.currentThisExpression = null; @@ -2235,7 +2235,7 @@ export class Resolver extends DiagnosticEmitter { return base; } } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode._super_can_only_be_referenced_in_a_derived_class, node.range @@ -2253,13 +2253,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupSuperExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -2278,12 +2278,12 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { this.currentThisExpression = node; this.currentElementExpression = null; switch (node.literalKind) { - case LiteralKind.INTEGER: { + case LiteralKind.Integer: { let intType = this.determineIntegerLiteralType( node, false, @@ -2291,18 +2291,18 @@ export class Resolver extends DiagnosticEmitter { ); return assert(intType.getClassOrWrapper(this.program)); } - case LiteralKind.FLOAT: { + case LiteralKind.Float: { let fltType = ctxType == Type.f32 ? Type.f32 : Type.f64; return assert(fltType.getClassOrWrapper(this.program)); } - case LiteralKind.STRING: - case LiteralKind.TEMPLATE: { + case LiteralKind.String: + case LiteralKind.Template: { return this.program.stringInstance; } - case LiteralKind.REGEXP: { + case LiteralKind.RegExp: { return this.program.regexpInstance; } - case LiteralKind.ARRAY: { + case LiteralKind.Array: { let classReference = ctxType.getClass(); if (classReference && classReference.prototype == this.program.arrayPrototype) { return this.getElementOfType(ctxType); @@ -2315,7 +2315,7 @@ export class Resolver extends DiagnosticEmitter { for (let i = 0, k = length; i < k; ++i) { let expression = expressions[i]; if (expression) { - if (expression.kind == NodeKind.NULL && length > 1) { + if (expression.kind == NodeKind.Null && length > 1) { ++numNullLiterals; } else { let currentType = this.resolveExpression(expression, ctxFlow, elementType); @@ -2333,7 +2333,7 @@ export class Resolver extends DiagnosticEmitter { if (numNullLiterals == length) { // all nulls infers as usize elementType = this.program.options.usizeType; } else { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, node.range, "T" @@ -2350,9 +2350,9 @@ export class Resolver extends DiagnosticEmitter { } return assert(this.resolveClass(this.program.arrayPrototype, [ elementType ])); } - case LiteralKind.OBJECT: { + case LiteralKind.Object: { if (ctxType.isClass) return ctxType.classReference; - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -2374,13 +2374,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupLiteralExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -2399,13 +2399,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.void, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveCallExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_illegal_in_this_context, node.range, type.toString() @@ -2424,7 +2424,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.void, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var targetExpression = node.expression; var target = this.lookupExpression( // reports @@ -2435,7 +2435,7 @@ export class Resolver extends DiagnosticEmitter { ); if (!target) return null; switch (target.kind) { - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let functionPrototype = target; // `unchecked` behaves like parenthesized if ( @@ -2448,18 +2448,18 @@ export class Resolver extends DiagnosticEmitter { if (!instance) return null; return instance.signature.returnType; } - case ElementKind.GLOBAL: - case ElementKind.LOCAL: - case ElementKind.FIELD: { + case ElementKind.Global: + case ElementKind.Local: + case ElementKind.Field: { let varType = (target).type; let varElement = this.getElementOfType(varType); - if (!varElement || varElement.kind != ElementKind.CLASS) { + if (!varElement || varElement.kind != ElementKind.Class) { break; } target = varElement; // fall-through } - case ElementKind.CLASS: { + case ElementKind.Class: { let typeArguments = (target).getTypeArgumentsTo(this.program.functionPrototype); if (typeArguments && typeArguments.length > 0) { let ftype = typeArguments[0]; @@ -2469,7 +2469,7 @@ export class Resolver extends DiagnosticEmitter { break; } } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, targetExpression.range, target.internalName @@ -2487,7 +2487,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var expressions = node.expressions; return this.lookupExpression(expressions[assert(expressions.length) - 1], ctxFlow, ctxType, reportMode); @@ -2502,7 +2502,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var expressions = node.expressions; return this.resolveExpression(expressions[assert(expressions.length) - 1], ctxFlow, ctxType, reportMode); @@ -2517,7 +2517,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { return assert(Type.bool.getClassOrWrapper(this.program)); } @@ -2531,7 +2531,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type = Type.auto, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { return Type.bool; } @@ -2545,13 +2545,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveTernaryExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_illegal_in_this_context, node.range, type.toString() @@ -2570,7 +2570,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var thenType = this.resolveExpression(node.ifThen, ctxFlow, ctxType, reportMode); if (!thenType) return null; @@ -2578,7 +2578,7 @@ export class Resolver extends DiagnosticEmitter { if (!elseType) return null; var commonType = Type.commonDenominator(thenType, elseType, false); if (!commonType) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, node.range, "?:", thenType.toString(), elseType.toString() @@ -2597,11 +2597,11 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var element = this.resolveTypeName(node.typeName, ctxFlow.actualFunction, reportMode); if (!element) return null; - if (element.kind == ElementKind.CLASS_PROTOTYPE) { + if (element.kind == ElementKind.ClassPrototype) { return this.resolveClassInclTypeArguments( element, node.typeArguments, @@ -2611,7 +2611,7 @@ export class Resolver extends DiagnosticEmitter { reportMode ); } - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.This_expression_is_not_constructable, node.range @@ -2629,13 +2629,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { var element = this.lookupNewExpression(node, ctxFlow, ctxType, reportMode); if (!element) return null; var type = this.getTypeOfElement(element); if (!type) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expression_cannot_be_represented_by_a_type, node.range @@ -2654,13 +2654,13 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Element | null { var type = this.resolveFunctionExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; var element = this.getElementOfType(type); if (!element) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_illegal_in_this_context, node.range, type.toString() @@ -2679,7 +2679,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual type. */ ctxType: Type, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Type | null { const declaration = node.declaration; const signature = declaration.signature; @@ -2687,8 +2687,8 @@ export class Resolver extends DiagnosticEmitter { let functionType = this.resolveFunctionType(signature, ctxFlow.actualFunction, ctxFlow.contextualTypeArguments, reportMode); if ( functionType && - declaration.arrowKind != ArrowKind.NONE && - body && body.kind == NodeKind.EXPRESSION && + declaration.arrowKind != ArrowKind.None && + body && body.kind == NodeKind.Expression && isTypeOmitted(signature.returnType) ) { // (x) => ret, infer return type accordingt to `ret` @@ -2723,17 +2723,17 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map = new Map(), /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Function | null { - var actualParent = prototype.parent.kind == ElementKind.PROPERTY_PROTOTYPE + var actualParent = prototype.parent.kind == ElementKind.PropertyPrototype ? prototype.parent.parent : prototype.parent; var classInstance: Class | null = null; // if an instance method var instanceKey = typeArguments ? typesToString(typeArguments) : ""; // Instance method prototypes are pre-bound to their concrete class as their parent - if (prototype.is(CommonFlags.INSTANCE)) { - assert(actualParent.kind == ElementKind.CLASS || actualParent.kind == ElementKind.INTERFACE); + if (prototype.is(CommonFlags.Instance)) { + assert(actualParent.kind == ElementKind.Class || actualParent.kind == ElementKind.Interface); classInstance = actualParent; // check if this exact concrete class and function combination is known already @@ -2753,7 +2753,7 @@ export class Resolver extends DiagnosticEmitter { } } } else { - assert(actualParent.kind != ElementKind.CLASS); // must not be pre-bound + assert(actualParent.kind != ElementKind.Class); // must not be pre-bound let resolvedInstance = prototype.getResolvedInstance(instanceKey); if (resolvedInstance) return resolvedInstance; } @@ -2803,7 +2803,7 @@ export class Resolver extends DiagnosticEmitter { } let typeNode = parameterDeclaration.type; if (isTypeOmitted(typeNode)) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, typeNode.range @@ -2819,7 +2819,7 @@ export class Resolver extends DiagnosticEmitter { ); if (!parameterType) return null; if (parameterType == Type.void) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, typeNode.range @@ -2832,14 +2832,14 @@ export class Resolver extends DiagnosticEmitter { // resolve return type var returnType: Type; - if (prototype.is(CommonFlags.SET)) { + if (prototype.is(CommonFlags.Set)) { returnType = Type.void; // not annotated - } else if (prototype.is(CommonFlags.CONSTRUCTOR)) { + } else if (prototype.is(CommonFlags.Constructor)) { returnType = classInstance!.type; // not annotated } else { let typeNode = signatureNode.returnType; if (isTypeOmitted(typeNode)) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, typeNode.range @@ -2900,19 +2900,19 @@ export class Resolver extends DiagnosticEmitter { /** The node to use when reporting intermediate errors. */ reportNode: Node, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Function | null { - var actualParent = prototype.parent.kind == ElementKind.PROPERTY_PROTOTYPE + var actualParent = prototype.parent.kind == ElementKind.PropertyPrototype ? prototype.parent.parent : prototype.parent; var resolvedTypeArguments: Type[] | null = null; // Resolve type arguments if generic - if (prototype.is(CommonFlags.GENERIC)) { + if (prototype.is(CommonFlags.Generic)) { // If this is an instance method, first apply the class's type arguments - if (prototype.is(CommonFlags.INSTANCE)) { - assert(actualParent.kind == ElementKind.CLASS); + if (prototype.is(CommonFlags.Instance)) { + assert(actualParent.kind == ElementKind.Class); let classInstance = actualParent; let classTypeArguments = classInstance.typeArguments; if (classTypeArguments) { @@ -2941,7 +2941,7 @@ export class Resolver extends DiagnosticEmitter { // Otherwise make sure that no type arguments have been specified } else { if (typeArgumentNodes && typeArgumentNodes.length > 0) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, reportNode.range, prototype.internalName @@ -2975,14 +2975,14 @@ export class Resolver extends DiagnosticEmitter { let unboundOverloadPrototype = _values[i]; assert(!unboundOverloadPrototype.isBound); let unboundOverloadParent = unboundOverloadPrototype.parent; - let isProperty = unboundOverloadParent.kind == ElementKind.PROPERTY_PROTOTYPE; + let isProperty = unboundOverloadParent.kind == ElementKind.PropertyPrototype; let classInstances: Map | null; if (isProperty) { let propertyParent = (unboundOverloadParent).parent; - assert(propertyParent.kind == ElementKind.CLASS_PROTOTYPE); + assert(propertyParent.kind == ElementKind.ClassPrototype); classInstances = (propertyParent).instances; } else { - assert(unboundOverloadParent.kind == ElementKind.CLASS_PROTOTYPE); + assert(unboundOverloadParent.kind == ElementKind.ClassPrototype); classInstances = (unboundOverloadParent).instances; } if (!classInstances) continue; @@ -2993,18 +2993,18 @@ export class Resolver extends DiagnosticEmitter { let overloadInstance: Function | null; if (isProperty) { let boundProperty = assert(classInstance.members!.get(unboundOverloadParent.name)); - assert(boundProperty.kind == ElementKind.PROPERTY_PROTOTYPE); + assert(boundProperty.kind == ElementKind.PropertyPrototype); let boundPropertyInstance = this.resolveProperty(boundProperty); if (!boundPropertyInstance) continue; - if (instance.is(CommonFlags.GET)) { + if (instance.is(CommonFlags.Get)) { overloadInstance = boundPropertyInstance.getterInstance; } else { - assert(instance.is(CommonFlags.SET)); + assert(instance.is(CommonFlags.Set)); overloadInstance = boundPropertyInstance.setterInstance; } } else { let boundPrototype = assert(classInstance.members!.get(unboundOverloadPrototype.name)); - assert(boundPrototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(boundPrototype.kind == ElementKind.FunctionPrototype); overloadInstance = this.resolveFunction(boundPrototype, instance.typeArguments); } if (overloadInstance) overloads.add(overloadInstance); @@ -3025,7 +3025,7 @@ export class Resolver extends DiagnosticEmitter { /** Contextual types, i.e. `T`. */ ctxTypes: Map = new Map(), /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Class | null { var instanceKey = typeArguments ? typesToString(typeArguments) : ""; @@ -3037,7 +3037,7 @@ export class Resolver extends DiagnosticEmitter { // Otherwise create var nameInclTypeParameters = prototype.name; if (instanceKey.length) nameInclTypeParameters += `<${instanceKey}>`; - if (prototype.kind == ElementKind.INTERFACE_PROTOTYPE) { + if (prototype.kind == ElementKind.InterfacePrototype) { instance = new Interface(nameInclTypeParameters, prototype, typeArguments); } else { instance = new Class(nameInclTypeParameters, prototype, typeArguments); @@ -3125,7 +3125,7 @@ export class Resolver extends DiagnosticEmitter { reportMode ); if (!iface) return null; - assert(iface.kind == ElementKind.INTERFACE); + assert(iface.kind == ElementKind.Interface); instance.addInterface(iface); // Like above, if any implemented interface is still pending, yield @@ -3202,7 +3202,7 @@ export class Resolver extends DiagnosticEmitter { } } members.set(memberName, member); - if (member.is(CommonFlags.ABSTRACT)) { + if (member.is(CommonFlags.Abstract)) { unimplemented.set(memberName, member); } else { unimplemented.delete(memberName); @@ -3223,7 +3223,7 @@ export class Resolver extends DiagnosticEmitter { let memberName = member.name; switch (member.kind) { - case ElementKind.FIELD_PROTOTYPE: { + case ElementKind.FieldPrototype: { let fieldPrototype = member; let fieldTypeNode = fieldPrototype.typeNode; let fieldType: Type | null = null; @@ -3232,7 +3232,7 @@ export class Resolver extends DiagnosticEmitter { let baseMembers = base.members; if (baseMembers && baseMembers.has(fieldPrototype.name)) { let baseField = assert(baseMembers.get(fieldPrototype.name)); - if (baseField.kind == ElementKind.FIELD) { + if (baseField.kind == ElementKind.Field) { existingField = baseField; } else { this.errorRelated( @@ -3244,11 +3244,11 @@ export class Resolver extends DiagnosticEmitter { } } if (!fieldTypeNode) { - if (existingField && !existingField.is(CommonFlags.PRIVATE)) { + if (existingField && !existingField.is(CommonFlags.Private)) { fieldType = existingField.type; } if (!fieldType) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, fieldPrototype.identifierNode.range.atEnd @@ -3263,7 +3263,7 @@ export class Resolver extends DiagnosticEmitter { reportMode ); if (fieldType == Type.void) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_expected, fieldTypeNode.range @@ -3291,8 +3291,8 @@ export class Resolver extends DiagnosticEmitter { let baseClass = base; // handle cases row-by-row - if (fieldPrototype.is(CommonFlags.PRIVATE)) { - if (existingField.is(CommonFlags.PRIVATE)) { + if (fieldPrototype.is(CommonFlags.Private)) { + if (existingField.is(CommonFlags.Private)) { this.errorRelated( DiagnosticCode.Types_have_separate_declarations_of_a_private_property_0, fieldPrototype.identifierNode.range, existingField.identifierNode.range, @@ -3305,14 +3305,14 @@ export class Resolver extends DiagnosticEmitter { fieldPrototype.name, instance.internalName, baseClass.internalName ); } - } else if (fieldPrototype.is(CommonFlags.PROTECTED)) { - if (existingField.is(CommonFlags.PRIVATE)) { + } else if (fieldPrototype.is(CommonFlags.Protected)) { + if (existingField.is(CommonFlags.Private)) { this.errorRelated( DiagnosticCode.Property_0_is_private_in_type_1_but_not_in_type_2, fieldPrototype.identifierNode.range, existingField.identifierNode.range, fieldPrototype.name, baseClass.internalName, instance.internalName ); - } else if (!existingField.is(CommonFlags.PROTECTED)) { + } else if (!existingField.is(CommonFlags.Protected)) { // may be implicitly public this.errorRelated( DiagnosticCode.Property_0_is_protected_in_type_1_but_public_in_type_2, @@ -3322,7 +3322,7 @@ export class Resolver extends DiagnosticEmitter { } } else { // fieldPrototype is public here - if (existingField.is(CommonFlags.PRIVATE)) { + if (existingField.is(CommonFlags.Private)) { this.errorRelated( DiagnosticCode.Property_0_is_private_in_type_1_but_not_in_type_2, fieldPrototype.identifierNode.range, existingField.identifierNode.range, @@ -3353,19 +3353,19 @@ export class Resolver extends DiagnosticEmitter { instance.add(memberName, fieldInstance); // reports break; } - case ElementKind.FUNCTION_PROTOTYPE: { + case ElementKind.FunctionPrototype: { let boundPrototype = (member).toBound(instance); instance.add(boundPrototype.name, boundPrototype); // reports break; } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let boundPrototype = (member).toBound(instance); instance.add(boundPrototype.name, boundPrototype); // reports break; } default: assert(false); } - if (!member.is(CommonFlags.ABSTRACT)) { + if (!member.is(CommonFlags.Abstract)) { unimplemented.delete(memberName); } } @@ -3391,10 +3391,10 @@ export class Resolver extends DiagnosticEmitter { } } - if (instance.kind != ElementKind.INTERFACE) { + if (instance.kind != ElementKind.Interface) { // Check that all required members are implemented - if (!instance.is(CommonFlags.ABSTRACT) && unimplemented.size > 0) { + if (!instance.is(CommonFlags.Abstract) && unimplemented.size > 0) { for (let _keys = Map_keys(unimplemented), i = 0, k = _keys.length; i < k; ++i) { let memberName = _keys[i]; let member = assert(unimplemented.get(memberName)); @@ -3413,7 +3413,7 @@ export class Resolver extends DiagnosticEmitter { { let ctorPrototype = instance.getMember(CommonNames.constructor); if (ctorPrototype && ctorPrototype.parent == instance) { - assert(ctorPrototype.kind == ElementKind.FUNCTION_PROTOTYPE); + assert(ctorPrototype.kind == ElementKind.FunctionPrototype); let ctorInstance = this.resolveFunction( ctorPrototype, null, @@ -3432,12 +3432,12 @@ export class Resolver extends DiagnosticEmitter { let overloadKind = unchecked(_keys[i]); let overloadPrototype = assert(overloadPrototypes.get(overloadKind)); assert(overloadKind != OperatorKind.INVALID); - if (overloadPrototype.is(CommonFlags.GENERIC)) { + if (overloadPrototype.is(CommonFlags.Generic)) { // Already errored during initialization: AS212: Decorator '@operator' is not valid here continue; } let operatorInstance: Function | null; - if (overloadPrototype.is(CommonFlags.INSTANCE)) { + if (overloadPrototype.is(CommonFlags.Instance)) { let boundPrototype = overloadPrototype.toBound(instance); operatorInstance = this.resolveFunction( boundPrototype, @@ -3459,7 +3459,7 @@ export class Resolver extends DiagnosticEmitter { // inc/dec are special in that an instance overload attempts to re-assign // the corresponding value, thus requiring a matching return type, while a // static overload works like any other overload. - if (operatorInstance.is(CommonFlags.INSTANCE)) { + if (operatorInstance.is(CommonFlags.Instance)) { switch (overloadKind) { case OperatorKind.PREFIX_INC: case OperatorKind.PREFIX_DEC: @@ -3467,7 +3467,7 @@ export class Resolver extends DiagnosticEmitter { case OperatorKind.POSTFIX_DEC: { let returnType = operatorInstance.signature.returnType; if (!returnType.isAssignableTo(instance.type)) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, overloadPrototype.functionTypeNode.returnType.range, returnType.toString(), instance.type.toString() @@ -3487,7 +3487,7 @@ export class Resolver extends DiagnosticEmitter { } } } else { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Duplicate_decorator, operatorInstance.declaration.range @@ -3534,12 +3534,12 @@ export class Resolver extends DiagnosticEmitter { /** The node to use when reporting intermediate errors. */ reportNode: Node, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Class | null { var resolvedTypeArguments: Type[] | null = null; // Resolve type arguments if generic - if (prototype.is(CommonFlags.GENERIC)) { + if (prototype.is(CommonFlags.Generic)) { resolvedTypeArguments = this.resolveTypeArguments( // reports assert(prototype.typeParameterNodes), // must be present if generic typeArgumentNodes, @@ -3553,7 +3553,7 @@ export class Resolver extends DiagnosticEmitter { // Otherwise make sure that no type arguments have been specified } else { if (typeArgumentNodes && typeArgumentNodes.length > 0) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Type_0_is_not_generic, reportNode.range, prototype.internalName @@ -3577,7 +3577,7 @@ export class Resolver extends DiagnosticEmitter { /** The prototype of the property. */ prototype: PropertyPrototype, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): Property | null { var instance = prototype.instance; if (instance) return instance; @@ -3605,7 +3605,7 @@ export class Resolver extends DiagnosticEmitter { ); if (setterInstance) { instance.setterInstance = setterInstance; - if (!instance.is(CommonFlags.RESOLVED)) { + if (!instance.is(CommonFlags.Resolved)) { assert(setterInstance.signature.parameterTypes.length == 1); instance.setType(setterInstance.signature.parameterTypes[0]); } @@ -3618,12 +3618,12 @@ export class Resolver extends DiagnosticEmitter { /** The type to resolve. */ node: NamedTypeNode, /** How to proceed with eventual diagnostics. */ - reportMode: ReportMode = ReportMode.REPORT + reportMode: ReportMode = ReportMode.Report ): TypeNode | null { var typeArgumentNodes = node.typeArguments; let numTypeArguments = 0; if (!typeArgumentNodes || (numTypeArguments = typeArgumentNodes.length) != 1) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Expected_0_type_arguments_but_got_1, node.range, "1", numTypeArguments.toString() diff --git a/src/types.ts b/src/types.ts index a07375990b..bc1c698e10 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,7 +17,7 @@ import { /** Indicates the kind of a type. */ export const enum TypeKind { /** A 1-bit unsigned integer. */ - BOOL, + Bool, // signed integers @@ -30,7 +30,7 @@ export const enum TypeKind { /** A 64-bit signed integer. */ I64, /** A 32-bit/64-bit signed integer, depending on the target. */ - ISIZE, + Isize, // unsigned integers @@ -43,7 +43,7 @@ export const enum TypeKind { /** A 64-bit unsigned integer. */ U64, /** A 32-bit/64-bit unsigned integer, depending on the target. Also the base of class types. */ - USIZE, + Usize, // floats @@ -60,55 +60,55 @@ export const enum TypeKind { // references /** Function reference. */ - FUNCREF, + Funcref, /** External reference. */ - EXTERNREF, + Externref, /** Any reference. */ - ANYREF, + Anyref, /** Equatable reference. */ - EQREF, + Eqref, /** 31-bit integer reference. */ - I31REF, + I31ref, /** Data reference. */ - DATAREF, + Dataref, // other /** No return type. */ - VOID + Void } /** Indicates capabilities of a type. */ export const enum TypeFlags { - NONE = 0, + None = 0, /** Is a signed type that can represent negative values. */ - SIGNED = 1 << 0, + Signed = 1 << 0, /** Is an unsigned type that cannot represent negative values. */ - UNSIGNED = 1 << 1, + Unsigned = 1 << 1, /** Is an integer type. */ - INTEGER = 1 << 2, + Integer = 1 << 2, /** Is a floating point type. */ - FLOAT = 1 << 3, + Float = 1 << 3, /** Is a varying (in size) type. */ - VARYING = 1 << 4, + Varying = 1 << 4, /** Is smaller than 32-bits. */ - SHORT = 1 << 5, + Short = 1 << 5, /** Is larger than 32-bits. */ - LONG = 1 << 6, + Long = 1 << 6, /** Is a value type. */ - VALUE = 1 << 7, + Value = 1 << 7, /** Is a reference type (either a class or a function type). */ - REFERENCE = 1 << 8, + Reference = 1 << 8, /** Is a nullable type. */ - NULLABLE = 1 << 9, + Nullable = 1 << 9, /** Is a vector type. */ - VECTOR = 1 << 10, + Vector = 1 << 10, /** Is an external type. */ - EXTERNAL = 1 << 11, + External = 1 << 11, /** Is a class. */ - CLASS = 1 << 12, + Class = 1 << 12, /** Is a function. */ - FUNCTION = 1 << 13 + Function = 1 << 13 } /** Represents a resolved type. */ @@ -134,7 +134,7 @@ export class Type { this.kind = kind; this.flags = flags; this.size = size; - if (!(flags & TypeFlags.NULLABLE)) { + if (!(flags & TypeFlags.Nullable)) { this._nonNullableType = this; } else { this._nullableType = this; @@ -145,26 +145,26 @@ export class Type { get intType(): Type { if (this == Type.auto) return this; // keep auto as a hint switch (this.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I32: case TypeKind.F32: return Type.i32; case TypeKind.I8: return Type.i8; case TypeKind.I16: return Type.i16; case TypeKind.F64: case TypeKind.I64: return Type.i64; - case TypeKind.ISIZE: return this.size == 64 ? Type.isize64 : Type.isize32; + case TypeKind.Isize: return this.size == 64 ? Type.isize64 : Type.isize32; case TypeKind.U8: return Type.u8; case TypeKind.U16: return Type.u16; case TypeKind.U32: return Type.u32; case TypeKind.U64: return Type.u64; - case TypeKind.USIZE: return this.size == 64 ? Type.usize64 : Type.usize32; + case TypeKind.Usize: return this.size == 64 ? Type.usize64 : Type.usize32; default: return Type.i32; } } /** Substitutes this type with the auto type if this type is void. */ get exceptVoid(): Type { - return this.kind == TypeKind.VOID ? Type.auto : this; + return this.kind == TypeKind.Void ? Type.auto : this; } /** Size in bytes. */ @@ -180,47 +180,47 @@ export class Type { /** Tests if this type represents a basic value. */ get isValue(): bool { - return this.is(TypeFlags.VALUE); + return this.is(TypeFlags.Value); } /** Tests if this type represents an integer value. */ get isIntegerValue(): bool { - return this.is(TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents a small (< 32 bits) integer value. */ get isShortIntegerValue(): bool { - return this.is(TypeFlags.SHORT | TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Short | TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents a long (> 32 bits) integer value. */ get isLongIntegerValue(): bool { - return this.is(TypeFlags.LONG | TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Long | TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents a signed integer value. */ get isSignedIntegerValue(): bool { - return this.is(TypeFlags.SIGNED | TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Signed | TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents an unsigned integer value. */ get isUnsignedIntegerValue(): bool { - return this.is(TypeFlags.UNSIGNED | TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Unsigned | TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents a varying (in size) integer value. */ get isVaryingIntegerValue(): bool { - return this.is(TypeFlags.VARYING | TypeFlags.INTEGER | TypeFlags.VALUE); + return this.is(TypeFlags.Varying | TypeFlags.Integer | TypeFlags.Value); } /** Tests if this type represents an integer, including references. */ get isIntegerInclReference(): bool { - return this.is(TypeFlags.INTEGER); + return this.is(TypeFlags.Integer); } /** Tests if this type represents a floating point value. */ get isFloatValue(): bool { - return this.is(TypeFlags.FLOAT | TypeFlags.VALUE); + return this.is(TypeFlags.Float | TypeFlags.Value); } /** Tests if this type represents a numeric (integer or floating point) value. */ @@ -235,27 +235,27 @@ export class Type { /** Tests if this type represents a vector value. */ get isVectorValue(): bool { - return this.is(TypeFlags.VECTOR | TypeFlags.VALUE); + return this.is(TypeFlags.Vector | TypeFlags.Value); } /** Tests if this type represents an internal or external reference. */ get isReference(): bool { - return this.is(TypeFlags.REFERENCE); + return this.is(TypeFlags.Reference); } /** Tests if this type represents a nullable internal or external reference. */ get isNullableReference(): bool { - return this.is(TypeFlags.NULLABLE | TypeFlags.REFERENCE); + return this.is(TypeFlags.Nullable | TypeFlags.Reference); } /** Tests if this type represents an internal object. */ get isInternalReference(): bool { - return this.is(TypeFlags.INTEGER | TypeFlags.REFERENCE); + return this.is(TypeFlags.Integer | TypeFlags.Reference); } /** Tests if this type represents an external object. */ get isExternalReference(): bool { - return this.is(TypeFlags.EXTERNAL | TypeFlags.REFERENCE); + return this.is(TypeFlags.External | TypeFlags.Reference); } /** Gets the underlying class of this type, if any. */ @@ -311,7 +311,7 @@ export class Type { get isManaged(): bool { if (this.isInternalReference) { let classReference = this.classReference; - if (classReference) return !classReference.hasDecorator(DecoratorFlags.UNMANAGED); + if (classReference) return !classReference.hasDecorator(DecoratorFlags.Unmanaged); return this.signatureReference != null; // function references are managed } return false; @@ -320,22 +320,22 @@ export class Type { /** Tests if this is a class type explicitly annotated as unmanaged. */ get isUnmanaged(): bool { var classReference = this.classReference; - return classReference != null && classReference.hasDecorator(DecoratorFlags.UNMANAGED); + return classReference != null && classReference.hasDecorator(DecoratorFlags.Unmanaged); } get isMemory(): bool { switch (this.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.I64: - case TypeKind.ISIZE: + case TypeKind.Isize: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: case TypeKind.U64: - case TypeKind.USIZE: + case TypeKind.Usize: case TypeKind.F32: case TypeKind.F64: case TypeKind.V128: return true; @@ -364,7 +364,7 @@ export class Type { /** Computes the truncating mask in the target type. */ computeSmallIntegerMask(targetType: Type): i32 { var size = this.size; - if (!this.is(TypeFlags.UNSIGNED)) size -= 1; + if (!this.is(TypeFlags.Unsigned)) size -= 1; return ~0 >>> (targetType.size - size); } @@ -379,7 +379,7 @@ export class Type { var nullableType = this._nullableType; if (!nullableType) { assert(!this.isNullableReference); - this._nullableType = nullableType = new Type(this.kind, this.flags | TypeFlags.NULLABLE, this.size); + this._nullableType = nullableType = new Type(this.kind, this.flags | TypeFlags.Nullable, this.size); nullableType.classReference = this.classReference; // either a class reference nullableType.signatureReference = this.signatureReference; // or a function reference nullableType._nonNullableType = this; @@ -394,7 +394,7 @@ export class Type { case TypeKind.I16: return Type.u16; case TypeKind.I32: return Type.u32; case TypeKind.I64: return Type.u64; - case TypeKind.ISIZE: return this.size == 64 ? Type.usize64 : Type.usize32; + case TypeKind.Isize: return this.size == 64 ? Type.usize64 : Type.usize32; } return this; } @@ -432,7 +432,7 @@ export class Type { } else if (this.isExternalReference) { if ( this.kind == target.kind || - (target.kind == TypeKind.ANYREF && this.kind != TypeKind.EXTERNREF) + (target.kind == TypeKind.Anyref && this.kind != TypeKind.Externref) ) { return true; } @@ -484,11 +484,11 @@ export class Type { /** Tests if a value of this type can be changed to the target type using `changetype`. */ isChangeableTo(target: Type): bool { // special in that it allows integer references as well - if (this.is(TypeFlags.INTEGER) && target.is(TypeFlags.INTEGER)) { + if (this.is(TypeFlags.Integer) && target.is(TypeFlags.Integer)) { let size = this.size; return size == target.size && ( size >= 32 || - this.is(TypeFlags.SIGNED) == target.is(TypeFlags.SIGNED) + this.is(TypeFlags.Signed) == target.is(TypeFlags.Signed) ); } return this.kind == target.kind; @@ -520,28 +520,28 @@ export class Type { } } switch (this.kind) { - case TypeKind.BOOL: return "bool"; + case TypeKind.Bool: return "bool"; case TypeKind.I8: return "i8"; case TypeKind.I16: return "i16"; case TypeKind.I32: return "i32"; case TypeKind.I64: return "i64"; - case TypeKind.ISIZE: return "isize"; + case TypeKind.Isize: return "isize"; case TypeKind.U8: return "u8"; case TypeKind.U16: return "u16"; case TypeKind.U32: return "u32"; case TypeKind.U64: return "u64"; - case TypeKind.USIZE: return "usize"; + case TypeKind.Usize: return "usize"; case TypeKind.F32: return "f32"; case TypeKind.F64: return "f64"; case TypeKind.V128: return "v128"; - case TypeKind.FUNCREF: return "funcref"; - case TypeKind.EXTERNREF: return "externref"; - case TypeKind.ANYREF: return "anyref"; - case TypeKind.EQREF: return "eqref"; - case TypeKind.I31REF: return "i31ref"; - case TypeKind.DATAREF: return "dataref"; + case TypeKind.Funcref: return "funcref"; + case TypeKind.Externref: return "externref"; + case TypeKind.Anyref: return "anyref"; + case TypeKind.Eqref: return "eqref"; + case TypeKind.I31ref: return "i31ref"; + case TypeKind.Dataref: return "dataref"; default: assert(false); - case TypeKind.VOID: return "void"; + case TypeKind.Void: return "void"; } } @@ -551,28 +551,28 @@ export class Type { toRef(): TypeRef { switch (this.kind) { default: assert(false); - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: case TypeKind.U32: return TypeRef.I32; - case TypeKind.ISIZE: - case TypeKind.USIZE: if (this.size != 64) return TypeRef.I32; + case TypeKind.Isize: + case TypeKind.Usize: if (this.size != 64) return TypeRef.I32; case TypeKind.I64: case TypeKind.U64: return TypeRef.I64; case TypeKind.F32: return TypeRef.F32; case TypeKind.F64: return TypeRef.F64; case TypeKind.V128: return TypeRef.V128; // TODO: nullable/non-nullable refs have different type refs - case TypeKind.FUNCREF: return TypeRef.Funcref; - case TypeKind.EXTERNREF: return TypeRef.Externref; - case TypeKind.ANYREF: return TypeRef.Anyref; - case TypeKind.EQREF: return TypeRef.Eqref; - case TypeKind.I31REF: return TypeRef.I31ref; - case TypeKind.DATAREF: return TypeRef.Dataref; - case TypeKind.VOID: return TypeRef.None; + case TypeKind.Funcref: return TypeRef.Funcref; + case TypeKind.Externref: return TypeRef.Externref; + case TypeKind.Anyref: return TypeRef.Anyref; + case TypeKind.Eqref: return TypeRef.Eqref; + case TypeKind.I31ref: return TypeRef.I31ref; + case TypeKind.Dataref: return TypeRef.Dataref; + case TypeKind.Void: return TypeRef.None; } } @@ -580,173 +580,173 @@ export class Type { /** An 8-bit signed integer. */ static readonly i8: Type = new Type(TypeKind.I8, - TypeFlags.SIGNED | - TypeFlags.SHORT | - TypeFlags.INTEGER | - TypeFlags.VALUE, 8 + TypeFlags.Signed | + TypeFlags.Short | + TypeFlags.Integer | + TypeFlags.Value, 8 ); /** A 16-bit signed integer. */ static readonly i16: Type = new Type(TypeKind.I16, - TypeFlags.SIGNED | - TypeFlags.SHORT | - TypeFlags.INTEGER | - TypeFlags.VALUE, 16 + TypeFlags.Signed | + TypeFlags.Short | + TypeFlags.Integer | + TypeFlags.Value, 16 ); /** A 32-bit signed integer. */ static readonly i32: Type = new Type(TypeKind.I32, - TypeFlags.SIGNED | - TypeFlags.INTEGER | - TypeFlags.VALUE, 32 + TypeFlags.Signed | + TypeFlags.Integer | + TypeFlags.Value, 32 ); /** A 64-bit signed integer. */ static readonly i64: Type = new Type(TypeKind.I64, - TypeFlags.SIGNED | - TypeFlags.LONG | - TypeFlags.INTEGER | - TypeFlags.VALUE, 64 + TypeFlags.Signed | + TypeFlags.Long | + TypeFlags.Integer | + TypeFlags.Value, 64 ); /** A 32-bit signed size. WASM32 only. */ - static readonly isize32: Type = new Type(TypeKind.ISIZE, - TypeFlags.SIGNED | - TypeFlags.INTEGER | - TypeFlags.VARYING | - TypeFlags.VALUE, 32 + static readonly isize32: Type = new Type(TypeKind.Isize, + TypeFlags.Signed | + TypeFlags.Integer | + TypeFlags.Varying | + TypeFlags.Value, 32 ); /** A 64-bit signed size. WASM64 only. */ - static readonly isize64: Type = new Type(TypeKind.ISIZE, - TypeFlags.SIGNED | - TypeFlags.LONG | - TypeFlags.INTEGER | - TypeFlags.VARYING | - TypeFlags.VALUE, 64 + static readonly isize64: Type = new Type(TypeKind.Isize, + TypeFlags.Signed | + TypeFlags.Long | + TypeFlags.Integer | + TypeFlags.Varying | + TypeFlags.Value, 64 ); /** An 8-bit unsigned integer. */ static readonly u8: Type = new Type(TypeKind.U8, - TypeFlags.UNSIGNED | - TypeFlags.SHORT | - TypeFlags.INTEGER | - TypeFlags.VALUE, 8 + TypeFlags.Unsigned | + TypeFlags.Short | + TypeFlags.Integer | + TypeFlags.Value, 8 ); /** A 16-bit unsigned integer. */ static readonly u16: Type = new Type(TypeKind.U16, - TypeFlags.UNSIGNED | - TypeFlags.SHORT | - TypeFlags.INTEGER | - TypeFlags.VALUE, 16 + TypeFlags.Unsigned | + TypeFlags.Short | + TypeFlags.Integer | + TypeFlags.Value, 16 ); /** A 32-bit unsigned integer. */ static readonly u32: Type = new Type(TypeKind.U32, - TypeFlags.UNSIGNED | - TypeFlags.INTEGER | - TypeFlags.VALUE, 32 + TypeFlags.Unsigned | + TypeFlags.Integer | + TypeFlags.Value, 32 ); /** A 64-bit unsigned integer. */ static readonly u64: Type = new Type(TypeKind.U64, - TypeFlags.UNSIGNED | - TypeFlags.LONG | - TypeFlags.INTEGER | - TypeFlags.VALUE, 64 + TypeFlags.Unsigned | + TypeFlags.Long | + TypeFlags.Integer | + TypeFlags.Value, 64 ); /** A 32-bit unsigned size. WASM32 only. */ - static readonly usize32: Type = new Type(TypeKind.USIZE, - TypeFlags.UNSIGNED | - TypeFlags.INTEGER | - TypeFlags.VARYING | - TypeFlags.VALUE, 32 + static readonly usize32: Type = new Type(TypeKind.Usize, + TypeFlags.Unsigned | + TypeFlags.Integer | + TypeFlags.Varying | + TypeFlags.Value, 32 ); /** A 64-bit unsigned size. WASM64 only. */ - static readonly usize64: Type = new Type(TypeKind.USIZE, - TypeFlags.UNSIGNED | - TypeFlags.LONG | - TypeFlags.INTEGER | - TypeFlags.VARYING | - TypeFlags.VALUE, 64 + static readonly usize64: Type = new Type(TypeKind.Usize, + TypeFlags.Unsigned | + TypeFlags.Long | + TypeFlags.Integer | + TypeFlags.Varying | + TypeFlags.Value, 64 ); /** A 1-bit unsigned integer. */ - static readonly bool: Type = new Type(TypeKind.BOOL, - TypeFlags.UNSIGNED | - TypeFlags.SHORT | - TypeFlags.INTEGER | - TypeFlags.VALUE, 1 + static readonly bool: Type = new Type(TypeKind.Bool, + TypeFlags.Unsigned | + TypeFlags.Short | + TypeFlags.Integer | + TypeFlags.Value, 1 ); /** A 32-bit float. */ static readonly f32: Type = new Type(TypeKind.F32, - TypeFlags.SIGNED | - TypeFlags.FLOAT | - TypeFlags.VALUE, 32 + TypeFlags.Signed | + TypeFlags.Float | + TypeFlags.Value, 32 ); /** A 64-bit float. */ static readonly f64: Type = new Type(TypeKind.F64, - TypeFlags.SIGNED | - TypeFlags.LONG | - TypeFlags.FLOAT | - TypeFlags.VALUE, 64 + TypeFlags.Signed | + TypeFlags.Long | + TypeFlags.Float | + TypeFlags.Value, 64 ); /** A 128-bit vector. */ static readonly v128: Type = new Type(TypeKind.V128, - TypeFlags.VECTOR | - TypeFlags.VALUE, 128 + TypeFlags.Vector | + TypeFlags.Value, 128 ); /** Function reference. */ - static readonly funcref: Type = new Type(TypeKind.FUNCREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly funcref: Type = new Type(TypeKind.Funcref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** External reference. */ - static readonly externref: Type = new Type(TypeKind.EXTERNREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly externref: Type = new Type(TypeKind.Externref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** Any reference. */ - static readonly anyref: Type = new Type(TypeKind.ANYREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly anyref: Type = new Type(TypeKind.Anyref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** Equatable reference. */ - static readonly eqref: Type = new Type(TypeKind.EQREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly eqref: Type = new Type(TypeKind.Eqref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** 31-bit integer reference. */ - static readonly i31ref: Type = new Type(TypeKind.I31REF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly i31ref: Type = new Type(TypeKind.I31ref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** Data reference. */ - static readonly dataref: Type = new Type(TypeKind.DATAREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly dataref: Type = new Type(TypeKind.Dataref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** No return type. */ - static readonly void: Type = new Type(TypeKind.VOID, TypeFlags.NONE, 0); + static readonly void: Type = new Type(TypeKind.Void, TypeFlags.None, 0); /** Alias of i32 indicating type inference of locals and globals with just an initializer. */ static readonly auto: Type = new Type(Type.i32.kind, Type.i32.flags, Type.i32.size); @@ -808,7 +808,7 @@ export class Signature { var usizeType = program.options.usizeType; var type = new Type( usizeType.kind, - usizeType.flags & ~TypeFlags.VALUE | TypeFlags.REFERENCE, + usizeType.flags & ~TypeFlags.Value | TypeFlags.Reference, usizeType.size ); this.type = type; diff --git a/std/assembly/shared/feature.ts b/std/assembly/shared/feature.ts index c8ca417a25..cbfc1cd571 100644 --- a/std/assembly/shared/feature.ts +++ b/std/assembly/shared/feature.ts @@ -3,54 +3,54 @@ /** Indicates specific features to activate. */ export const enum Feature { /** No additional features. */ - NONE = 0, + None = 0, /** Sign extension operations. */ - SIGN_EXTENSION = 1 << 0, // see: https://github.com/WebAssembly/sign-extension-ops + SignExtension = 1 << 0, // see: https://github.com/WebAssembly/sign-extension-ops /** Mutable global imports and exports. */ - MUTABLE_GLOBALS = 1 << 1, // see: https://github.com/WebAssembly/mutable-global + MutableGlobals = 1 << 1, // see: https://github.com/WebAssembly/mutable-global /** Non-trapping float to integer operations. */ - NONTRAPPING_F2I = 1 << 2, // see: https://github.com/WebAssembly/nontrapping-float-to-int-conversions + NontrappingF2I = 1 << 2, // see: https://github.com/WebAssembly/nontrapping-float-to-int-conversions /** Bulk memory operations. */ - BULK_MEMORY = 1 << 3, // see: https://github.com/WebAssembly/bulk-memory-operations + BulkMemory = 1 << 3, // see: https://github.com/WebAssembly/bulk-memory-operations /** SIMD types and operations. */ - SIMD = 1 << 4, // see: https://github.com/WebAssembly/simd + Simd = 1 << 4, // see: https://github.com/WebAssembly/simd /** Threading and atomic operations. */ - THREADS = 1 << 5, // see: https://github.com/WebAssembly/threads + Threads = 1 << 5, // see: https://github.com/WebAssembly/threads /** Exception handling operations. */ - EXCEPTION_HANDLING = 1 << 6, // see: https://github.com/WebAssembly/exception-handling + ExceptionHandling = 1 << 6, // see: https://github.com/WebAssembly/exception-handling /** Tail call operations. */ - TAIL_CALLS = 1 << 7, // see: https://github.com/WebAssembly/tail-call + TailCalls = 1 << 7, // see: https://github.com/WebAssembly/tail-call /** Reference types. */ - REFERENCE_TYPES = 1 << 8, // see: https://github.com/WebAssembly/reference-types + ReferenceTypes = 1 << 8, // see: https://github.com/WebAssembly/reference-types /** Multi value types. */ - MULTI_VALUE = 1 << 9, // see: https://github.com/WebAssembly/multi-value + MultiValue = 1 << 9, // see: https://github.com/WebAssembly/multi-value /** Garbage collection. */ GC = 1 << 10, // see: https://github.com/WebAssembly/gc /** Memory64. */ - MEMORY64 = 1 << 11, // see: https://github.com/WebAssembly/memory64 + Memory64 = 1 << 11, // see: https://github.com/WebAssembly/memory64 /** Function references. */ - FUNCTION_REFERENCES = 1 << 12, // see: https://github.com/WebAssembly/function-references + FunctionReferences = 1 << 12, // see: https://github.com/WebAssembly/function-references /** Relaxed SIMD. */ - RELAXED_SIMD = 1 << 13, // see: https://github.com/WebAssembly/relaxed-simd + RelaxedSimd = 1 << 13, // see: https://github.com/WebAssembly/relaxed-simd /** Extended const expressions. */ - EXTENDED_CONST = 1 << 14 // see: https://github.com/WebAssembly/extended-const + ExtendedConst = 1 << 14 // see: https://github.com/WebAssembly/extended-const } /** Gets the name of the specified feature one would specify on the command line. */ export function featureToString(feature: Feature): string { switch (feature) { - case Feature.SIGN_EXTENSION: return "sign-extension"; - case Feature.MUTABLE_GLOBALS: return "mutable-globals"; - case Feature.NONTRAPPING_F2I: return "nontrapping-f2i"; - case Feature.BULK_MEMORY: return "bulk-memory"; - case Feature.SIMD: return "simd"; - case Feature.THREADS: return "threads"; - case Feature.EXCEPTION_HANDLING: return "exception-handling"; - case Feature.TAIL_CALLS: return "tail-calls"; - case Feature.REFERENCE_TYPES: return "reference-types"; - case Feature.MULTI_VALUE: return "multi-value"; + case Feature.SignExtension: return "sign-extension"; + case Feature.MutableGlobals: return "mutable-globals"; + case Feature.NontrappingF2I: return "nontrapping-f2i"; + case Feature.BulkMemory: return "bulk-memory"; + case Feature.Simd: return "simd"; + case Feature.Threads: return "threads"; + case Feature.ExceptionHandling: return "exception-handling"; + case Feature.TailCalls: return "tail-calls"; + case Feature.ReferenceTypes: return "reference-types"; + case Feature.MultiValue: return "multi-value"; case Feature.GC: return "gc"; - case Feature.MEMORY64: return "memory64"; + case Feature.Memory64: return "memory64"; } assert(false); return ""; diff --git a/std/assembly/shared/target.ts b/std/assembly/shared/target.ts index 680037f34f..42e51ffe71 100644 --- a/std/assembly/shared/target.ts +++ b/std/assembly/shared/target.ts @@ -3,9 +3,9 @@ /** Compilation target. */ export enum Target { /** Portable. */ - JS = 0, + Js = 0, /** WebAssembly with 32-bit pointers. */ - WASM32 = 1, + Wasm32 = 1, /** WebAssembly with 64-bit pointers. Experimental and not supported by any runtime yet. */ - WASM64 = 2, + Wasm64 = 2, } From c4951260de7b40dc95c57c7fbea1ed2792d5b2f3 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 08:15:27 +0300 Subject: [PATCH 07/22] more refactorings (wip) --- src/ast.ts | 6 +- src/compiler.ts | 90 ++--- src/extra/ast.ts | 4 +- src/parser.ts | 992 +++++++++++++++++++++++------------------------ src/program.ts | 78 ++-- src/resolver.ts | 98 ++--- src/tokenizer.ts | 636 +++++++++++++++--------------- 7 files changed, 952 insertions(+), 952 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index cd47676852..2c86506eed 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -940,11 +940,11 @@ export class TypeParameterNode extends Node { /** Represents the kind of a parameter. */ export const enum ParameterKind { /** No specific flags. */ - DEFAULT, + Default, /** Is an optional parameter. */ - OPTIONAL, + Optional, /** Is a rest parameter. */ - REST + Rest } /** Represents a function parameter. */ diff --git a/src/compiler.ts b/src/compiler.ts index 937261c96b..b94718f582 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3831,7 +3831,7 @@ export class Compiler extends DiagnosticEmitter { var operator = expression.operator; switch (operator) { - case Token.LESSTHAN: { + case Token.LessThan: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3866,7 +3866,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.GREATERTHAN: { + case Token.GreaterThan: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3901,7 +3901,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.LESSTHAN_EQUALS: { + case Token.LessThanEquals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3936,7 +3936,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.GREATERTHAN_EQUALS: { + case Token.GreaterThanEquals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3972,8 +3972,8 @@ export class Compiler extends DiagnosticEmitter { break; } - case Token.EQUALS_EQUALS_EQUALS: - case Token.EQUALS_EQUALS: { + case Token.EqualsEqualsEquals: + case Token.EqualsEquals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4024,8 +4024,8 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.EXCLAMATION_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS: { + case Token.ExclamationEqualsEquals: + case Token.ExclamationEquals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4076,11 +4076,11 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.EQUALS: { + case Token.Equals: { return this.compileAssignment(left, right, contextualType); } - case Token.PLUS_EQUALS: compound = true; - case Token.PLUS: { + case Token.PlusEquals: compound = true; + case Token.Plus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4123,8 +4123,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAdd(leftExpr, rightExpr, commonType); break; } - case Token.MINUS_EQUALS: compound = true; - case Token.MINUS: { + case Token.MinusEquals: compound = true; + case Token.Minus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4168,8 +4168,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeSub(leftExpr, rightExpr, commonType); break; } - case Token.ASTERISK_EQUALS: compound = true; - case Token.ASTERISK: { + case Token.AsteriskEquals: compound = true; + case Token.Asterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4213,8 +4213,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeMul(leftExpr, rightExpr, commonType); break; } - case Token.ASTERISK_ASTERISK_EQUALS: compound = true; - case Token.ASTERISK_ASTERISK: { + case Token.AsteriskAsteriskEquals: compound = true; + case Token.AsteriskAsterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4258,8 +4258,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makePow(leftExpr, rightExpr, commonType, expression); break; } - case Token.SLASH_EQUALS: compound = true; - case Token.SLASH: { + case Token.SlashEquals: compound = true; + case Token.Slash: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4303,8 +4303,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeDiv(leftExpr, rightExpr, commonType); break; } - case Token.PERCENT_EQUALS: compound = true; - case Token.PERCENT: { + case Token.PercentEquals: compound = true; + case Token.Percent: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4348,8 +4348,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeRem(leftExpr, rightExpr, commonType, expression); break; } - case Token.LESSTHAN_LESSTHAN_EQUALS: compound = true; - case Token.LESSTHAN_LESSTHAN: { + case Token.LessThanLessThanEquals: compound = true; + case Token.LessThanLessThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4375,8 +4375,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShl(leftExpr, rightExpr, rightType); break; } - case Token.GREATERTHAN_GREATERTHAN_EQUALS: compound = true; - case Token.GREATERTHAN_GREATERTHAN: { + case Token.GreaterThanGreaterThanEquals: compound = true; + case Token.GreaterThanGreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4403,8 +4403,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShr(leftExpr, rightExpr, rightType); break; } - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: compound = true; - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: { + case Token.GreaterThanGreaterThanGreaterThanEquals: compound = true; + case Token.GreaterThanGreaterThanGreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4430,8 +4430,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShru(leftExpr, rightExpr, rightType); break; } - case Token.AMPERSAND_EQUALS: compound = true; - case Token.AMPERSAND: { + case Token.AmpersandEquals: compound = true; + case Token.Ampersand: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4475,8 +4475,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAnd(leftExpr, rightExpr, commonType); break; } - case Token.BAR_EQUALS: compound = true; - case Token.BAR: { + case Token.BarEquals: compound = true; + case Token.Bar: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4520,8 +4520,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeOr(leftExpr, rightExpr, commonType); break; } - case Token.CARET_EQUALS: compound = true; - case Token.CARET: { + case Token.CaretEquals: compound = true; + case Token.Caret: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4568,7 +4568,7 @@ export class Compiler extends DiagnosticEmitter { // logical (no overloading) - case Token.AMPERSAND_AMPERSAND: { // left && right -> (t = left) ? right : t + case Token.AmpersandAmpersand: { // left && right -> (t = left) ? right : t let flow = this.currentFlow; let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); @@ -4632,7 +4632,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.BAR_BAR: { // left || right -> ((t = left) ? t : right) + case Token.BarBar: { // left || right -> ((t = left) ? t : right) let flow = this.currentFlow; let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); @@ -9081,7 +9081,7 @@ export class Compiler extends DiagnosticEmitter { var expr: ExpressionRef; switch (expression.operator) { - case Token.PLUS_PLUS: { + case Token.PlusPlus: { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); @@ -9167,7 +9167,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MINUS_MINUS: { + case Token.MinusMinus: { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); @@ -9310,7 +9310,7 @@ export class Compiler extends DiagnosticEmitter { var expr: ExpressionRef; switch (expression.operator) { - case Token.PLUS: { + case Token.Plus: { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, @@ -9334,7 +9334,7 @@ export class Compiler extends DiagnosticEmitter { // nop break; } - case Token.MINUS: { + case Token.Minus: { let operand = expression.operand; if (operand.isNumericLiteral) { // implicitly negate integer and float literals. also enables proper checking of literal ranges. @@ -9407,7 +9407,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.PLUS_PLUS: { + case Token.PlusPlus: { compound = true; expr = this.compileExpression( expression.operand, @@ -9476,7 +9476,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MINUS_MINUS: { + case Token.MinusMinus: { compound = true; expr = this.compileExpression( expression.operand, @@ -9545,7 +9545,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.EXCLAMATION: { + case Token.Exclamation: { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, @@ -9564,7 +9564,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.TILDE: { + case Token.Tilde: { expr = this.compileExpression( expression.operand, contextualType == Type.void @@ -9626,10 +9626,10 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.TYPEOF: { + case Token.TypeOf: { return this.compileTypeof(expression, contextualType, constraints); } - case Token.DOT_DOT_DOT: { + case Token.DotDotDot: { this.error( DiagnosticCode.Not_implemented_0, expression.range, "Spread operator" diff --git a/src/extra/ast.ts b/src/extra/ast.ts index b99e2de07a..0364a58db3 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -1570,14 +1570,14 @@ export class ASTBuilder { if (implicitFieldDeclaration) { this.serializeAccessModifiers(implicitFieldDeclaration); } - if (kind == ParameterKind.REST) { + if (kind == ParameterKind.Rest) { sb.push("..."); } this.visitIdentifierExpression(node.name); var type = node.type; var initializer = node.initializer; if (type) { - if (kind == ParameterKind.OPTIONAL && !initializer) sb.push("?"); + if (kind == ParameterKind.Optional && !initializer) sb.push("?"); if (!isTypeOmitted(type)) { sb.push(": "); this.visitTypeNode(type); diff --git a/src/parser.ts b/src/parser.ts index 621423bb4c..1c58fb9158 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -182,7 +182,7 @@ export class Parser extends DiagnosticEmitter { var tn = new Tokenizer(source, this.diagnostics); tn.onComment = this.onComment; var statements = source.statements; - while (!tn.skip(Token.ENDOFFILE)) { + while (!tn.skip(Token.EndOfFile)) { let statement = this.parseTopLevelStatement(tn, null); if (statement) { statements.push(statement); @@ -202,7 +202,7 @@ export class Parser extends DiagnosticEmitter { // check decorators var decorators: DecoratorNode[] | null = null; - while (tn.skip(Token.AT)) { + while (tn.skip(Token.At)) { if (startPos < 0) startPos = tn.tokenPos; let decorator = this.parseDecorator(tn); if (!decorator) { @@ -218,12 +218,12 @@ export class Parser extends DiagnosticEmitter { var exportEnd = 0; var defaultStart = 0; var defaultEnd = 0; - if (tn.skip(Token.EXPORT)) { + if (tn.skip(Token.Export)) { if (startPos < 0) startPos = tn.tokenPos; flags |= CommonFlags.Export; exportStart = tn.tokenPos; exportEnd = tn.pos; - if (tn.skip(Token.DEFAULT)) { + if (tn.skip(Token.Default)) { defaultStart = tn.tokenPos; defaultEnd = tn.pos; } @@ -232,7 +232,7 @@ export class Parser extends DiagnosticEmitter { var declareStart = 0; var declareEnd = 0; var contextIsAmbient = namespace != null && namespace.is(CommonFlags.Ambient); - if (tn.skip(Token.DECLARE)) { + if (tn.skip(Token.Declare)) { if (contextIsAmbient) { this.error( DiagnosticCode.A_declare_modifier_cannot_be_used_in_an_already_ambient_context, @@ -255,10 +255,10 @@ export class Parser extends DiagnosticEmitter { var first = tn.peek(); if (startPos < 0) startPos = tn.nextTokenPos; switch (first) { - case Token.CONST: { + case Token.Const: { tn.next(); flags |= CommonFlags.Const; - if (tn.skip(Token.ENUM)) { + if (tn.skip(Token.Enum)) { statement = this.parseEnum(tn, flags, decorators, startPos); } else { statement = this.parseVariable(tn, flags, decorators, startPos); @@ -266,26 +266,26 @@ export class Parser extends DiagnosticEmitter { decorators = null; break; } - case Token.LET: flags |= CommonFlags.Let; - case Token.VAR: { + case Token.Let: flags |= CommonFlags.Let; + case Token.Var: { tn.next(); statement = this.parseVariable(tn, flags, decorators, startPos); decorators = null; break; } - case Token.ENUM: { + case Token.Enum: { tn.next(); statement = this.parseEnum(tn, flags, decorators, startPos); decorators = null; break; } - case Token.FUNCTION: { + case Token.Function: { tn.next(); statement = this.parseFunction(tn, flags, decorators, startPos); decorators = null; break; } - case Token.ABSTRACT: { + case Token.Abstract: { let state = tn.mark(); tn.next(); let abstractStart = tn.tokenPos; @@ -296,8 +296,8 @@ export class Parser extends DiagnosticEmitter { statement = this.parseStatement(tn, true); break; } - if (next != Token.CLASS) { - if (next == Token.INTERFACE) { + if (next != Token.Class) { + if (next == Token.Interface) { this.error( DiagnosticCode._abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration, tn.range(abstractStart, abstractEnd) @@ -312,17 +312,17 @@ export class Parser extends DiagnosticEmitter { flags |= CommonFlags.Abstract; // fall through } - case Token.CLASS: - case Token.INTERFACE: { + case Token.Class: + case Token.Interface: { tn.next(); statement = this.parseClassOrInterface(tn, flags, decorators, startPos); decorators = null; break; } - case Token.NAMESPACE: { + case Token.Namespace: { let state = tn.mark(); tn.next(); - if (tn.peek(false, IdentifierHandling.PREFER) == Token.IDENTIFIER) { + if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { tn.discard(state); statement = this.parseNamespace(tn, flags, decorators, startPos); decorators = null; @@ -332,7 +332,7 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.IMPORT: { + case Token.Import: { tn.next(); flags |= CommonFlags.Import; if (flags & CommonFlags.Export) { @@ -342,10 +342,10 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.TYPE: { // also identifier + case Token.Type: { // also identifier let state = tn.mark(); tn.next(); - if (tn.peek(false, IdentifierHandling.PREFER) == Token.IDENTIFIER) { + if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { tn.discard(state); statement = this.parseTypeDeclaration(tn, flags, decorators, startPos); decorators = null; @@ -355,10 +355,10 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.MODULE: { // also identifier + case Token.Module: { // also identifier let state = tn.mark(); tn.next(); - if (tn.peek(true) == Token.STRINGLITERAL && !tn.nextTokenOnNewLine) { + if (tn.peek(true) == Token.StringLiteral && !tn.nextTokenOnNewLine) { tn.discard(state); statement = this.parseModuleDeclaration(tn, flags); } else { @@ -473,8 +473,8 @@ export class Parser extends DiagnosticEmitter { var first = Node.createSimpleTypeName(tn.readIdentifier(), tn.range()); var current = first; - while (tn.skip(Token.DOT)) { - if (tn.skip(Token.IDENTIFIER)) { + while (tn.skip(Token.Dot)) { + if (tn.skip(Token.Identifier)) { let next = Node.createSimpleTypeName(tn.readIdentifier(), tn.range()); current.next = next; current = next; @@ -505,29 +505,29 @@ export class Parser extends DiagnosticEmitter { var type: TypeNode; // '(' ... - if (token == Token.OPENPAREN) { + if (token == Token.OpenParen) { // '(' FunctionSignature ')' '|' 'null'? - let isNullableSignature = tn.skip(Token.OPENPAREN); + let isNullableSignature = tn.skip(Token.OpenParen); // FunctionSignature? let signature = this.tryParseFunctionType(tn); if (signature) { if (isNullableSignature) { - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { this.error( DiagnosticCode._0_expected, tn.range(), ")" ); return null; } - if (!tn.skip(Token.BAR)) { + if (!tn.skip(Token.Bar)) { this.error( DiagnosticCode._0_expected, tn.range(), "|" ); return null; } - if (!tn.skip(Token.NULL)) { + if (!tn.skip(Token.Null)) { this.error( DiagnosticCode._0_expected, tn.range(), "null" @@ -548,7 +548,7 @@ export class Parser extends DiagnosticEmitter { if (acceptParenthesized) { let innerType = this.parseType(tn, false, suppressErrors); if (!innerType) return null; - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { if (!suppressErrors) { this.error( DiagnosticCode._0_expected, @@ -569,51 +569,51 @@ export class Parser extends DiagnosticEmitter { } // 'void' - } else if (token == Token.VOID) { + } else if (token == Token.Void) { type = Node.createNamedType( Node.createSimpleTypeName("void", tn.range()), [], false, tn.range(startPos, tn.pos) ); // 'this' - } else if (token == Token.THIS) { + } else if (token == Token.This) { type = Node.createNamedType( Node.createSimpleTypeName("this", tn.range()), [], false, tn.range(startPos, tn.pos) ); // 'true' - } else if (token == Token.TRUE || token == Token.FALSE) { + } else if (token == Token.True || token == Token.False) { type = Node.createNamedType( Node.createSimpleTypeName("bool", tn.range()), [], false, tn.range(startPos, tn.pos) ); // 'null' - } else if (token == Token.NULL) { + } else if (token == Token.Null) { type = Node.createNamedType( Node.createSimpleTypeName("null", tn.range()), [], false, tn.range(startPos, tn.pos) ); // StringLiteral - } else if (token == Token.STRINGLITERAL) { + } else if (token == Token.StringLiteral) { tn.readString(); type = Node.createNamedType( Node.createSimpleTypeName("string", tn.range()), [], false, tn.range(startPos, tn.pos) ); // Identifier - } else if (token == Token.IDENTIFIER) { + } else if (token == Token.Identifier) { let name = this.parseTypeName(tn); if (!name) return null; let parameters: TypeNode[] | null = null; // Name - if (tn.skip(Token.LESSTHAN)) { + if (tn.skip(Token.LessThan)) { do { let parameter = this.parseType(tn, true, suppressErrors); if (!parameter) return null; if (!parameters) parameters = [ parameter ]; else parameters.push(parameter); - } while (tn.skip(Token.COMMA)); - if (!tn.skip(Token.GREATERTHAN)) { + } while (tn.skip(Token.Comma)); + if (!tn.skip(Token.GreaterThan)) { if (!suppressErrors) { this.error( DiagnosticCode._0_expected, @@ -635,8 +635,8 @@ export class Parser extends DiagnosticEmitter { return null; } // ... | null - while (tn.skip(Token.BAR)) { - if (tn.skip(Token.NULL)) { + while (tn.skip(Token.Bar)) { + if (tn.skip(Token.Null)) { type.isNullable = true; } else { let notNullStart = tn.pos; @@ -651,9 +651,9 @@ export class Parser extends DiagnosticEmitter { } } // ... [][] - while (tn.skip(Token.OPENBRACKET)) { + while (tn.skip(Token.OpenBracket)) { let bracketStart = tn.tokenPos; - if (!tn.skip(Token.CLOSEBRACKET)) { + if (!tn.skip(Token.CloseBracket)) { if (!suppressErrors) { this.error( DiagnosticCode._0_expected, @@ -666,8 +666,8 @@ export class Parser extends DiagnosticEmitter { // ...[] | null let nullable = false; - if (tn.skip(Token.BAR)) { - if (tn.skip(Token.NULL)) { + if (tn.skip(Token.Bar)) { + if (tn.skip(Token.Null)) { nullable = true; } else { if (!suppressErrors) { @@ -707,9 +707,9 @@ export class Parser extends DiagnosticEmitter { var thisType: NamedTypeNode | null = null; var isSignature: bool = false; var firstParamNameNoType: IdentifierExpression | null = null; - var firstParamKind: ParameterKind = ParameterKind.DEFAULT; + var firstParamKind: ParameterKind = ParameterKind.Default; - if (tn.skip(Token.CLOSEPAREN)) { + if (tn.skip(Token.CloseParen)) { isSignature = true; tn.discard(state); parameters = []; @@ -718,16 +718,16 @@ export class Parser extends DiagnosticEmitter { isSignature = false; // not yet known do { let paramStart = -1; - let kind = ParameterKind.DEFAULT; - if (tn.skip(Token.DOT_DOT_DOT)) { + let kind = ParameterKind.Default; + if (tn.skip(Token.DotDotDot)) { paramStart = tn.tokenPos; isSignature = true; tn.discard(state); - kind = ParameterKind.REST; + kind = ParameterKind.Rest; } - if (tn.skip(Token.THIS)) { + if (tn.skip(Token.This)) { if (paramStart < 0) paramStart = tn.tokenPos; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { isSignature = true; tn.discard(state); let type = this.parseType(tn, false); @@ -749,19 +749,19 @@ export class Parser extends DiagnosticEmitter { } else if (tn.skipIdentifier()) { if (paramStart < 0) paramStart = tn.tokenPos; let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range(tn.tokenPos, tn.pos)); - if (tn.skip(Token.QUESTION)) { + if (tn.skip(Token.Question)) { isSignature = true; tn.discard(state); - if (kind == ParameterKind.REST) { + if (kind == ParameterKind.Rest) { this.error( DiagnosticCode.A_rest_parameter_cannot_be_optional, tn.range() ); // recoverable } else { - kind = ParameterKind.OPTIONAL; + kind = ParameterKind.Optional; } } - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { isSignature = true; tn.discard(state); let type = this.parseType(tn); // not suppressing errors because known @@ -774,7 +774,7 @@ export class Parser extends DiagnosticEmitter { else parameters.push(param); } else { if (!isSignature) { - if (tn.peek() == Token.COMMA) { + if (tn.peek() == Token.Comma) { isSignature = true; tn.discard(state); } @@ -807,8 +807,8 @@ export class Parser extends DiagnosticEmitter { this.tryParseSignatureIsSignature = isSignature; return null; } - } while (tn.skip(Token.COMMA)); - if (!tn.skip(Token.CLOSEPAREN)) { + } while (tn.skip(Token.Comma)); + if (!tn.skip(Token.CloseParen)) { if (isSignature) { this.error( DiagnosticCode._0_expected, @@ -823,7 +823,7 @@ export class Parser extends DiagnosticEmitter { } var returnType: TypeNode | null; - if (tn.skip(Token.EQUALS_GREATERTHAN)) { + if (tn.skip(Token.EqualsGreaterThan)) { if (!isSignature) { isSignature = true; tn.discard(state); @@ -885,7 +885,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { let name = tn.readIdentifier(); let expression: Expression = Node.createIdentifierExpression(name, tn.range(startPos, tn.pos)); - while (tn.skip(Token.DOT)) { + while (tn.skip(Token.Dot)) { if (tn.skipIdentifier(IdentifierHandling.PREFER)) { name = tn.readIdentifier(); expression = Node.createPropertyAccessExpression( @@ -902,7 +902,7 @@ export class Parser extends DiagnosticEmitter { } } let args: Expression[] | null; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { args = this.parseArguments(tn); if (args) { return Node.createDecorator(expression, args, tn.range(startPos, tn.pos)); @@ -935,10 +935,10 @@ export class Parser extends DiagnosticEmitter { if (!declaration) return null; declaration.overriddenModuleName = this.currentModuleName; declarations.push(declaration); - } while (tn.skip(Token.COMMA)); + } while (tn.skip(Token.Comma)); var ret = Node.createVariableStatement(decorators, declarations, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -966,24 +966,24 @@ export class Parser extends DiagnosticEmitter { ); } var flags = parentFlags; - if (tn.skip(Token.EXCLAMATION)) { + if (tn.skip(Token.Exclamation)) { flags |= CommonFlags.DefinitelyAssigned; } var type: TypeNode | null = null; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { type = this.parseType(tn, true); } var initializer: Expression | null = null; - if (tn.skip(Token.EQUALS)) { + if (tn.skip(Token.Equals)) { if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts, tn.range() ); // recoverable } - initializer = this.parseExpression(tn, Precedence.COMMA + 1); + initializer = this.parseExpression(tn, Precedence.Comma + 1); if (!initializer) return null; } else if (!isFor) { if (flags & CommonFlags.Const) { @@ -1026,7 +1026,7 @@ export class Parser extends DiagnosticEmitter { // at 'enum': Identifier '{' (EnumValueDeclaration (',' EnumValueDeclaration )*)? '}' ';'? - if (tn.next() != Token.IDENTIFIER) { + if (tn.next() != Token.Identifier) { this.error( DiagnosticCode.Identifier_expected, tn.range() @@ -1034,7 +1034,7 @@ export class Parser extends DiagnosticEmitter { return null; } var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); - if (tn.next() != Token.OPENBRACE) { + if (tn.next() != Token.OpenBrace) { this.error( DiagnosticCode._0_expected, tn.range(), "{" @@ -1042,12 +1042,12 @@ export class Parser extends DiagnosticEmitter { return null; } var members = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let member = this.parseEnumValue(tn, CommonFlags.None); if (!member) return null; members.push(member); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseBrace)) { break; } else { this.error( @@ -1066,7 +1066,7 @@ export class Parser extends DiagnosticEmitter { tn.range(startPos, tn.pos) ); ret.overriddenModuleName = this.currentModuleName; - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -1086,8 +1086,8 @@ export class Parser extends DiagnosticEmitter { } var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); var value: Expression | null = null; - if (tn.skip(Token.EQUALS)) { - value = this.parseExpression(tn, Precedence.COMMA + 1); + if (tn.skip(Token.Equals)) { + value = this.parseExpression(tn, Precedence.Comma + 1); if (!value) return null; } return Node.createEnumValueDeclaration( @@ -1107,15 +1107,15 @@ export class Parser extends DiagnosticEmitter { var startPos = tn.tokenPos; var expr: Expression | null = null; if ( - tn.peek(true) != Token.SEMICOLON && - tn.nextToken != Token.CLOSEBRACE && + tn.peek(true) != Token.Semicolon && + tn.nextToken != Token.CloseBrace && !tn.nextTokenOnNewLine ) { if (!(expr = this.parseExpression(tn))) return null; } var ret = Node.createReturnStatement(expr, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -1128,7 +1128,7 @@ export class Parser extends DiagnosticEmitter { var typeParameters = new Array(); var seenOptional = false; var start = tn.tokenPos; - while (!tn.skip(Token.GREATERTHAN)) { + while (!tn.skip(Token.GreaterThan)) { let typeParameter = this.parseTypeParameter(tn); if (!typeParameter) return null; if (typeParameter.defaultType) { @@ -1141,8 +1141,8 @@ export class Parser extends DiagnosticEmitter { typeParameter.defaultType = null; } typeParameters.push(typeParameter); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.GREATERTHAN)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.GreaterThan)) { break; } else { this.error( @@ -1168,13 +1168,13 @@ export class Parser extends DiagnosticEmitter { // before: Identifier ('extends' Type)? ('=' Type)? - if (tn.next() == Token.IDENTIFIER) { + if (tn.next() == Token.Identifier) { let identifier = Node.createIdentifierExpression( tn.readIdentifier(), tn.range() ); let extendsType: NamedTypeNode | null = null; - if (tn.skip(Token.EXTENDS)) { + if (tn.skip(Token.Extends)) { let type = this.parseType(tn); if (!type) return null; if (type.kind != NodeKind.NamedType) { @@ -1187,7 +1187,7 @@ export class Parser extends DiagnosticEmitter { extendsType = type; } let defaultType: NamedTypeNode | null = null; - if (tn.skip(Token.EQUALS)) { + if (tn.skip(Token.Equals)) { let type = this.parseType(tn); if (!type) return null; if (type.kind != NodeKind.NamedType) { @@ -1231,8 +1231,8 @@ export class Parser extends DiagnosticEmitter { // check if there is a leading `this` parameter this.parseParametersThis = null; - if (tn.skip(Token.THIS)) { - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.This)) { + if (tn.skip(Token.Colon)) { thisType = this.parseType(tn); // reports if (!thisType) return null; if (thisType.kind == NodeKind.NamedType) { @@ -1250,8 +1250,8 @@ export class Parser extends DiagnosticEmitter { ); return null; } - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseParen)) { return parameters; } else { this.error( @@ -1263,7 +1263,7 @@ export class Parser extends DiagnosticEmitter { } } - while (!tn.skip(Token.CLOSEPAREN)) { + while (!tn.skip(Token.CloseParen)) { let param = this.parseParameter(tn, isConstructor); // reports if (!param) return null; if (seenRest && !reportedRest) { @@ -1283,18 +1283,18 @@ export class Parser extends DiagnosticEmitter { } break; } - case ParameterKind.OPTIONAL: { + case ParameterKind.Optional: { seenOptional = true; break; } - case ParameterKind.REST: { + case ParameterKind.Rest: { seenRest = param; break; } } parameters.push(param); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseParen)) { break; } else { this.error( @@ -1320,20 +1320,20 @@ export class Parser extends DiagnosticEmitter { var startRange: Range | null = null; var accessFlags: CommonFlags = CommonFlags.None; if (isConstructor) { - if (tn.skip(Token.PUBLIC)) { + if (tn.skip(Token.Public)) { startRange = tn.range(); accessFlags |= CommonFlags.Public; - } else if (tn.skip(Token.PROTECTED)) { + } else if (tn.skip(Token.Protected)) { startRange = tn.range(); accessFlags |= CommonFlags.Protected; - } else if (tn.skip(Token.PRIVATE)) { + } else if (tn.skip(Token.Private)) { startRange = tn.range(); accessFlags |= CommonFlags.Private; } - if (tn.peek() == Token.READONLY) { + if (tn.peek() == Token.Readonly) { let state = tn.mark(); tn.next(); - if (tn.peek() != Token.COLON) { // modifier + if (tn.peek() != Token.Colon) { // modifier tn.discard(state); if (!startRange) startRange = tn.range(); accessFlags |= CommonFlags.Readonly; @@ -1342,7 +1342,7 @@ export class Parser extends DiagnosticEmitter { } } } - if (tn.skip(Token.DOT_DOT_DOT)) { + if (tn.skip(Token.DotDotDot)) { if (accessFlags) { this.error( DiagnosticCode.A_parameter_property_cannot_be_declared_using_a_rest_parameter, @@ -1357,7 +1357,7 @@ export class Parser extends DiagnosticEmitter { if (!isRest) startRange = tn.range(); let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let type: TypeNode | null = null; - if (isOptional = tn.skip(Token.QUESTION)) { + if (isOptional = tn.skip(Token.Question)) { if (isRest) { this.error( DiagnosticCode.A_rest_parameter_cannot_be_optional, @@ -1365,14 +1365,14 @@ export class Parser extends DiagnosticEmitter { ); } } - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { type = this.parseType(tn); if (!type) return null; } else { type = Node.createOmittedType(tn.range(tn.pos)); } let initializer: Expression | null = null; - if (tn.skip(Token.EQUALS)) { + if (tn.skip(Token.Equals)) { if (isRest) { this.error( DiagnosticCode.A_rest_parameter_cannot_have_an_initializer, @@ -1387,15 +1387,15 @@ export class Parser extends DiagnosticEmitter { } else { isOptional = true; } - initializer = this.parseExpression(tn, Precedence.COMMA + 1); + initializer = this.parseExpression(tn, Precedence.Comma + 1); if (!initializer) return null; } let param = Node.createParameter( isRest - ? ParameterKind.REST + ? ParameterKind.Rest : isOptional - ? ParameterKind.OPTIONAL - : ParameterKind.DEFAULT, + ? ParameterKind.Optional + : ParameterKind.Default, identifier, type, initializer, @@ -1438,14 +1438,14 @@ export class Parser extends DiagnosticEmitter { var signatureStart = -1; var typeParameters: TypeParameterNode[] | null = null; - if (tn.skip(Token.LESSTHAN)) { + if (tn.skip(Token.LessThan)) { signatureStart = tn.tokenPos; typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; flags |= CommonFlags.Generic; } - if (!tn.skip(Token.OPENPAREN)) { + if (!tn.skip(Token.OpenParen)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "(" @@ -1487,7 +1487,7 @@ export class Parser extends DiagnosticEmitter { } var returnType: TypeNode | null = null; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { returnType = this.parseType(tn, true, isSetter); if (!returnType) return null; } @@ -1513,7 +1513,7 @@ export class Parser extends DiagnosticEmitter { ); var body: Statement | null = null; - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, @@ -1541,7 +1541,7 @@ export class Parser extends DiagnosticEmitter { tn.range(startPos, tn.pos) ); ret.overriddenModuleName = this.currentModuleName; - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -1555,13 +1555,13 @@ export class Parser extends DiagnosticEmitter { // '(' Parameters (':' Type)? // Statement - if (tn.token == Token.FUNCTION) { + if (tn.token == Token.Function) { if (tn.skipIdentifier()) { name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { // empty name name = Node.createEmptyIdentifierExpression(tn.range(tn.pos)); } - if (!tn.skip(Token.OPENPAREN)) { + if (!tn.skip(Token.OpenParen)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "(" @@ -1575,7 +1575,7 @@ export class Parser extends DiagnosticEmitter { } else { arrowKind = ArrowKind.Parenthesized; - assert(tn.token == Token.OPENPAREN); + assert(tn.token == Token.OpenParen); name = Node.createEmptyIdentifierExpression(tn.range(tn.tokenPos)); } @@ -1601,7 +1601,7 @@ export class Parser extends DiagnosticEmitter { if (signatureStart < 0) signatureStart = startPos; var returnType: TypeNode | null = null; - if (arrowKind != ArrowKind.Single && tn.skip(Token.COLON)) { + if (arrowKind != ArrowKind.Single && tn.skip(Token.Colon)) { returnType = this.parseType(tn); if (!returnType) return null; } else { @@ -1609,7 +1609,7 @@ export class Parser extends DiagnosticEmitter { } if (arrowKind) { - if (!tn.skip(Token.EQUALS_GREATERTHAN)) { + if (!tn.skip(Token.EqualsGreaterThan)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "=>" @@ -1628,14 +1628,14 @@ export class Parser extends DiagnosticEmitter { var body: Statement | null = null; if (arrowKind) { - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { body = this.parseBlockStatement(tn, false); } else { - let bodyExpression = this.parseExpression(tn, Precedence.COMMA + 1); + let bodyExpression = this.parseExpression(tn, Precedence.Comma + 1); if (bodyExpression) body = Node.createExpressionStatement(bodyExpression); } } else { - if (!tn.skip(Token.OPENBRACE)) { + if (!tn.skip(Token.OpenBrace)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "{" @@ -1673,7 +1673,7 @@ export class Parser extends DiagnosticEmitter { // ('implements' Type (',' Type)*)? // '{' ClassMember* '}' - var isInterface = tn.token == Token.INTERFACE; + var isInterface = tn.token == Token.Interface; if (!tn.skipIdentifier()) { this.error( @@ -1689,14 +1689,14 @@ export class Parser extends DiagnosticEmitter { ); var typeParameters: TypeParameterNode[] | null = null; - if (tn.skip(Token.LESSTHAN)) { + if (tn.skip(Token.LessThan)) { typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; flags |= CommonFlags.Generic; } var extendsType: NamedTypeNode | null = null; - if (tn.skip(Token.EXTENDS)) { + if (tn.skip(Token.Extends)) { let type = this.parseType(tn); if (!type) return null; if (type.kind != NodeKind.NamedType) { @@ -1710,7 +1710,7 @@ export class Parser extends DiagnosticEmitter { } var implementsTypes: NamedTypeNode[] | null = null; - if (tn.skip(Token.IMPLEMENTS)) { + if (tn.skip(Token.Implements)) { if (isInterface) { this.error( DiagnosticCode.Interface_declaration_cannot_have_implements_clause, @@ -1731,10 +1731,10 @@ export class Parser extends DiagnosticEmitter { if (!implementsTypes) implementsTypes = []; implementsTypes.push(type); } - } while (tn.skip(Token.COMMA)); + } while (tn.skip(Token.Comma)); } - if (!tn.skip(Token.OPENBRACE)) { + if (!tn.skip(Token.OpenBrace)) { this.error( DiagnosticCode._0_expected, tn.range(), "{" @@ -1768,7 +1768,7 @@ export class Parser extends DiagnosticEmitter { tn.range(startPos, tn.pos) ); } - if (!tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.CloseBrace)) { do { let member = this.parseClassMember(tn, declaration); if (member) { @@ -1780,7 +1780,7 @@ export class Parser extends DiagnosticEmitter { } } else { this.skipStatement(tn); - if (tn.skip(Token.ENDOFFILE)) { + if (tn.skip(Token.EndOfFile)) { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -1788,7 +1788,7 @@ export class Parser extends DiagnosticEmitter { return null; } } - } while (!tn.skip(Token.CLOSEBRACE)); + } while (!tn.skip(Token.CloseBrace)); } declaration.range.end = tn.pos; declaration.overriddenModuleName = this.currentModuleName; @@ -1808,7 +1808,7 @@ export class Parser extends DiagnosticEmitter { name = Node.createEmptyIdentifierExpression(tn.range(tn.pos)); } - if (!tn.skip(Token.OPENBRACE)) { + if (!tn.skip(Token.OpenBrace)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "{" @@ -1827,7 +1827,7 @@ export class Parser extends DiagnosticEmitter { members, tn.range(startPos, tn.pos) ); - if (!tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.CloseBrace)) { do { let member = this.parseClassMember(tn, declaration); if (member) { @@ -1839,7 +1839,7 @@ export class Parser extends DiagnosticEmitter { } } else { this.skipStatement(tn); - if (tn.skip(Token.ENDOFFILE)) { + if (tn.skip(Token.EndOfFile)) { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -1847,7 +1847,7 @@ export class Parser extends DiagnosticEmitter { return null; } } - } while (!tn.skip(Token.CLOSEBRACE)); + } while (!tn.skip(Token.CloseBrace)); } declaration.range.end = tn.pos; return Node.createClassExpression(declaration); @@ -1870,14 +1870,14 @@ export class Parser extends DiagnosticEmitter { var isInterface = parent.kind == NodeKind.InterfaceDeclaration; var startPos = 0; var decorators: DecoratorNode[] | null = null; - if (tn.skip(Token.AT)) { + if (tn.skip(Token.At)) { startPos = tn.tokenPos; do { let decorator = this.parseDecorator(tn); if (!decorator) break; if (!decorators) decorators = new Array(); decorators.push(decorator); - } while (tn.skip(Token.AT)); + } while (tn.skip(Token.At)); if (isInterface && decorators) { this.error( DiagnosticCode.Decorators_are_not_valid_here, @@ -1895,7 +1895,7 @@ export class Parser extends DiagnosticEmitter { var declareStart = 0; var declareEnd = 0; var contextIsAmbient = parent.is(CommonFlags.Ambient); - if (tn.skip(Token.DECLARE)) { + if (tn.skip(Token.Declare)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1920,7 +1920,7 @@ export class Parser extends DiagnosticEmitter { var accessStart = 0; var accessEnd = 0; - if (tn.skip(Token.PUBLIC)) { + if (tn.skip(Token.Public)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1932,7 +1932,7 @@ export class Parser extends DiagnosticEmitter { accessEnd = tn.pos; } if (!startPos) startPos = tn.tokenPos; - } else if (tn.skip(Token.PRIVATE)) { + } else if (tn.skip(Token.Private)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1944,7 +1944,7 @@ export class Parser extends DiagnosticEmitter { accessEnd = tn.pos; } if (!startPos) startPos = tn.tokenPos; - } else if (tn.skip(Token.PROTECTED)) { + } else if (tn.skip(Token.Protected)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1962,7 +1962,7 @@ export class Parser extends DiagnosticEmitter { var staticEnd = 0; var abstractStart = 0; var abstractEnd = 0; - if (tn.skip(Token.STATIC)) { + if (tn.skip(Token.Static)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1976,7 +1976,7 @@ export class Parser extends DiagnosticEmitter { if (!startPos) startPos = tn.tokenPos; } else { flags |= CommonFlags.Instance; - if (tn.skip(Token.ABSTRACT)) { + if (tn.skip(Token.Abstract)) { if (isInterface || !parent.is(CommonFlags.Abstract)) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1994,7 +1994,7 @@ export class Parser extends DiagnosticEmitter { var overrideStart = 0; var overrideEnd = 0; - if (tn.skip(Token.OVERRIDE)) { + if (tn.skip(Token.Override)) { if (isInterface || parent.extendsType == null) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -2010,10 +2010,10 @@ export class Parser extends DiagnosticEmitter { var readonlyStart = 0; var readonlyEnd = 0; - if (tn.peek() == Token.READONLY) { + if (tn.peek() == Token.Readonly) { let state = tn.mark(); tn.next(); - if (tn.peek() != Token.COLON) { // modifier + if (tn.peek() != Token.Colon) { // modifier tn.discard(state); flags |= CommonFlags.Readonly; readonlyStart = tn.tokenPos; @@ -2034,8 +2034,8 @@ export class Parser extends DiagnosticEmitter { var setStart = 0; var setEnd = 0; if (!isInterface) { - if (tn.skip(Token.GET)) { - if (tn.peek(true, IdentifierHandling.PREFER) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { + if (tn.skip(Token.Get)) { + if (tn.peek(true, IdentifierHandling.PREFER) == Token.Identifier && !tn.nextTokenOnNewLine) { flags |= CommonFlags.Get; isGetter = true; getStart = tn.tokenPos; @@ -2050,8 +2050,8 @@ export class Parser extends DiagnosticEmitter { } else { tn.reset(state); } - } else if (tn.skip(Token.SET)) { - if (tn.peek(true, IdentifierHandling.PREFER) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { + } else if (tn.skip(Token.Set)) { + if (tn.peek(true, IdentifierHandling.PREFER) == Token.Identifier && !tn.nextTokenOnNewLine) { flags |= CommonFlags.Set; isSetter = true; setStart = tn.tokenPos; @@ -2066,7 +2066,7 @@ export class Parser extends DiagnosticEmitter { } else { tn.reset(state); } - } else if (tn.skip(Token.CONSTRUCTOR)) { + } else if (tn.skip(Token.Constructor)) { flags |= CommonFlags.Constructor; isConstructor = true; if (!startPos) startPos = tn.tokenPos; @@ -2096,7 +2096,7 @@ export class Parser extends DiagnosticEmitter { if (isConstructor) { name = Node.createConstructorExpression(tn.range()); } else { - if (!isGetterOrSetter && tn.skip(Token.OPENBRACKET)) { + if (!isGetterOrSetter && tn.skip(Token.OpenBracket)) { if (!startPos) startPos = tn.tokenPos; // TODO: also handle symbols, which might have some of these modifiers if (flags & CommonFlags.Public) { @@ -2143,7 +2143,7 @@ export class Parser extends DiagnosticEmitter { } return null; } - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return retIndex; } if (!tn.skipIdentifier(IdentifierHandling.ALWAYS)) { @@ -2157,7 +2157,7 @@ export class Parser extends DiagnosticEmitter { name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } var typeParameters: TypeParameterNode[] | null = null; - if (tn.skip(Token.LESSTHAN)) { + if (tn.skip(Token.LessThan)) { let typeParametersStart = tn.tokenPos; typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; @@ -2177,7 +2177,7 @@ export class Parser extends DiagnosticEmitter { } // method: '(' Parameters (':' Type)? '{' Statement* '}' ';'? - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { if (flags & CommonFlags.Declare) { this.error( DiagnosticCode._0_modifier_cannot_appear_on_class_elements_of_this_kind, @@ -2239,7 +2239,7 @@ export class Parser extends DiagnosticEmitter { } let returnType: TypeNode | null = null; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { if (name.kind == NodeKind.Constructor) { this.error( DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration, @@ -2272,7 +2272,7 @@ export class Parser extends DiagnosticEmitter { ); let body: Statement | null = null; - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, @@ -2307,8 +2307,8 @@ export class Parser extends DiagnosticEmitter { body, tn.range(startPos, tn.pos) ); - if (!(isInterface && tn.skip(Token.COMMA))) { - tn.skip(Token.SEMICOLON); + if (!(isInterface && tn.skip(Token.Comma))) { + tn.skip(Token.Semicolon); } return retMethod; @@ -2355,16 +2355,16 @@ export class Parser extends DiagnosticEmitter { } let type: TypeNode | null = null; - if (tn.skip(Token.QUESTION)) { + if (tn.skip(Token.Question)) { this.error( DiagnosticCode.Optional_properties_are_not_supported, tn.range(startPos, tn.pos) ); } - if (tn.skip(Token.EXCLAMATION)) { + if (tn.skip(Token.Exclamation)) { flags |= CommonFlags.DefinitelyAssigned; } - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { type = this.parseType(tn); if (!type) return null; } else { @@ -2374,7 +2374,7 @@ export class Parser extends DiagnosticEmitter { ); // recoverable } let initializer: Expression | null = null; - if (tn.skip(Token.EQUALS)) { + if (tn.skip(Token.Equals)) { if (flags & CommonFlags.Ambient) { this.error( DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts, @@ -2402,8 +2402,8 @@ export class Parser extends DiagnosticEmitter { initializer, range ); - if (!(isInterface && tn.skip(Token.COMMA))) { - tn.skip(Token.SEMICOLON); + if (!(isInterface && tn.skip(Token.Comma))) { + tn.skip(Token.Semicolon); } return retField; } @@ -2429,7 +2429,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { let id = tn.readIdentifier(); if (id == "key") { - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { let keyType = this.parseType(tn); if (!keyType) return null; if (keyType.kind != NodeKind.NamedType) { @@ -2439,8 +2439,8 @@ export class Parser extends DiagnosticEmitter { ); return null; } - if (tn.skip(Token.CLOSEBRACKET)) { - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.CloseBracket)) { + if (tn.skip(Token.Colon)) { let valueType = this.parseType(tn); if (!valueType) return null; if (valueType.kind != NodeKind.NamedType) { @@ -2495,7 +2495,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { let members = new Array(); let declaration = Node.createNamespaceDeclaration( identifier, @@ -2504,7 +2504,7 @@ export class Parser extends DiagnosticEmitter { members, tn.range(startPos, tn.pos) ); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let member = this.parseTopLevelStatement(tn, declaration); if (member) { if (member.kind == NodeKind.Export) { @@ -2517,7 +2517,7 @@ export class Parser extends DiagnosticEmitter { members.push(member); } else { this.skipStatement(tn); - if (tn.skip(Token.ENDOFFILE)) { + if (tn.skip(Token.EndOfFile)) { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -2528,7 +2528,7 @@ export class Parser extends DiagnosticEmitter { } declaration.range.end = tn.pos; declaration.overriddenModuleName = this.currentModuleName; - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return declaration; } else { this.error( @@ -2555,14 +2555,14 @@ export class Parser extends DiagnosticEmitter { var path: StringLiteralExpression | null = null; var currentSource = assert(this.currentSource); - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { let members = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let member = this.parseExportMember(tn); if (!member) return null; members.push(member); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseBrace)) { break; } else { this.error( @@ -2573,8 +2573,8 @@ export class Parser extends DiagnosticEmitter { } } } - if (tn.skip(Token.FROM)) { - if (tn.skip(Token.STRINGLITERAL)) { + if (tn.skip(Token.From)) { + if (tn.skip(Token.StringLiteral)) { path = Node.createStringLiteralExpression(tn.readString(), tn.range()); } else { this.error( @@ -2593,11 +2593,11 @@ export class Parser extends DiagnosticEmitter { this.seenlog.add(internalPath); } } - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; - } else if (tn.skip(Token.ASTERISK)) { - if (tn.skip(Token.FROM)) { - if (tn.skip(Token.STRINGLITERAL)) { + } else if (tn.skip(Token.Asterisk)) { + if (tn.skip(Token.From)) { + if (tn.skip(Token.StringLiteral)) { path = Node.createStringLiteralExpression(tn.readString(), tn.range()); let ret = Node.createExportStatement(null, path, isDeclare, tn.range(startPos, tn.pos)); let internalPath = assert(ret.internalPath); @@ -2609,7 +2609,7 @@ export class Parser extends DiagnosticEmitter { this.dependees.set(internalPath, new Dependee(currentSource, path)); this.backlog.push(internalPath); } - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -2641,7 +2641,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let asIdentifier: IdentifierExpression | null = null; - if (tn.skip(Token.AS)) { + if (tn.skip(Token.As)) { if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { @@ -2691,7 +2691,7 @@ export class Parser extends DiagnosticEmitter { range ) ], null, false, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -2707,14 +2707,14 @@ export class Parser extends DiagnosticEmitter { var members: ImportDeclaration[] | null = null; var namespaceName: IdentifierExpression | null = null; var skipFrom = false; - if (tn.skip(Token.OPENBRACE)) { // import { ... } from "file" + if (tn.skip(Token.OpenBrace)) { // import { ... } from "file" members = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let member = this.parseImportDeclaration(tn); if (!member) return null; members.push(member); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseBrace)) { break; } else { this.error( @@ -2725,8 +2725,8 @@ export class Parser extends DiagnosticEmitter { } } } - } else if (tn.skip(Token.ASTERISK)) { // import * from "file" - if (tn.skip(Token.AS)) { + } else if (tn.skip(Token.Asterisk)) { // import * from "file" + if (tn.skip(Token.As)) { if (tn.skipIdentifier()) { namespaceName = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { @@ -2743,7 +2743,7 @@ export class Parser extends DiagnosticEmitter { ); return null; } - } else if (tn.skip(Token.IDENTIFIER, IdentifierHandling.PREFER)) { // import Name from "file" + } else if (tn.skip(Token.Identifier, IdentifierHandling.PREFER)) { // import Name from "file" let name = tn.readIdentifier(); let range = tn.range(); members = [ @@ -2753,7 +2753,7 @@ export class Parser extends DiagnosticEmitter { range ) ]; - if (tn.skip(Token.COMMA)) { + if (tn.skip(Token.Comma)) { // TODO: default + star, default + members this.error( DiagnosticCode.Not_implemented_0, @@ -2766,8 +2766,8 @@ export class Parser extends DiagnosticEmitter { skipFrom = true; } - if (skipFrom || tn.skip(Token.FROM)) { - if (tn.skip(Token.STRINGLITERAL)) { + if (skipFrom || tn.skip(Token.From)) { + if (tn.skip(Token.StringLiteral)) { let path = Node.createStringLiteralExpression(tn.readString(), tn.range()); let ret: ImportStatement; if (namespaceName) { @@ -2781,7 +2781,7 @@ export class Parser extends DiagnosticEmitter { this.dependees.set(internalPath, new Dependee(assert(this.currentSource), path)); this.backlog.push(internalPath); } - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -2807,7 +2807,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let asIdentifier: IdentifierExpression | null = null; - if (tn.skip(Token.AS)) { + if (tn.skip(Token.As)) { if (tn.skipIdentifier()) { asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { @@ -2848,11 +2848,11 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { let asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); - if (tn.skip(Token.EQUALS)) { + if (tn.skip(Token.Equals)) { if (tn.skipIdentifier()) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let ret = Node.createExportImportStatement(identifier, asIdentifier, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -2886,43 +2886,43 @@ export class Parser extends DiagnosticEmitter { var token = tn.next(); var statement: Statement | null = null; switch (token) { - case Token.BREAK: { + case Token.Break: { statement = this.parseBreak(tn); break; } - case Token.CONST: { + case Token.Const: { statement = this.parseVariable(tn, CommonFlags.Const, null, tn.tokenPos); break; } - case Token.CONTINUE: { + case Token.Continue: { statement = this.parseContinue(tn); break; } - case Token.DO: { + case Token.Do: { statement = this.parseDoStatement(tn); break; } - case Token.FOR: { + case Token.For: { statement = this.parseForStatement(tn); break; } - case Token.IF: { + case Token.If: { statement = this.parseIfStatement(tn); break; } - case Token.LET: { + case Token.Let: { statement = this.parseVariable(tn, CommonFlags.Let, null, tn.tokenPos); break; } - case Token.VAR: { + case Token.Var: { statement = this.parseVariable(tn, CommonFlags.None, null, tn.tokenPos); break; } - case Token.OPENBRACE: { + case Token.OpenBrace: { statement = this.parseBlockStatement(tn, topLevel); break; } - case Token.RETURN: { + case Token.Return: { if (topLevel) { this.error( DiagnosticCode.A_return_statement_can_only_be_used_within_a_function_body, @@ -2932,31 +2932,31 @@ export class Parser extends DiagnosticEmitter { statement = this.parseReturn(tn); break; } - case Token.SEMICOLON: { + case Token.Semicolon: { return Node.createEmptyStatement(tn.range(tn.tokenPos)); } - case Token.SWITCH: { + case Token.Switch: { statement = this.parseSwitchStatement(tn); break; } - case Token.THROW: { + case Token.Throw: { statement = this.parseThrowStatement(tn); break; } - case Token.TRY: { + case Token.Try: { statement = this.parseTryStatement(tn); break; } - case Token.VOID: { + case Token.Void: { statement = this.parseVoidStatement(tn); break; } - case Token.WHILE: { + case Token.While: { statement = this.parseWhileStatement(tn); break; } - case Token.TYPE: { // also identifier - if (tn.peek(false, IdentifierHandling.PREFER) == Token.IDENTIFIER) { + case Token.Type: { // also identifier + if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { statement = this.parseTypeDeclaration(tn, CommonFlags.None, null, tn.tokenPos); break; } @@ -2986,11 +2986,11 @@ export class Parser extends DiagnosticEmitter { var startPos = tn.tokenPos; var statements = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let state = tn.mark(); let statement = this.parseStatement(tn, topLevel); if (!statement) { - if (tn.token == Token.ENDOFFILE) return null; + if (tn.token == Token.EndOfFile) return null; tn.reset(state); this.skipStatement(tn); } else { @@ -2999,7 +2999,7 @@ export class Parser extends DiagnosticEmitter { } } var ret = Node.createBlockStatement(statements, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3010,12 +3010,12 @@ export class Parser extends DiagnosticEmitter { // at 'break': Identifier? ';'? var identifier: IdentifierExpression | null = null; - if (tn.peek(true) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { + if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { tn.next(IdentifierHandling.PREFER); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } var ret = Node.createBreakStatement(identifier, tn.range()); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3026,12 +3026,12 @@ export class Parser extends DiagnosticEmitter { // at 'continue': Identifier? ';'? var identifier: IdentifierExpression | null = null; - if (tn.peek(true) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { + if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { tn.next(IdentifierHandling.PREFER); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } var ret = Node.createContinueStatement(identifier, tn.range()); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3045,15 +3045,15 @@ export class Parser extends DiagnosticEmitter { var statement = this.parseStatement(tn); if (!statement) return null; - if (tn.skip(Token.WHILE)) { + if (tn.skip(Token.While)) { - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let condition = this.parseExpression(tn); if (!condition) return null; - if (tn.skip(Token.CLOSEPAREN)) { + if (tn.skip(Token.CloseParen)) { let ret = Node.createDoStatement(statement, condition, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -3086,7 +3086,7 @@ export class Parser extends DiagnosticEmitter { if (!expr) return null; var ret = Node.createExpressionStatement(expr); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3098,23 +3098,23 @@ export class Parser extends DiagnosticEmitter { var startPos = tn.tokenPos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let initializer: Statement | null = null; - if (tn.skip(Token.CONST)) { + if (tn.skip(Token.Const)) { initializer = this.parseVariable(tn, CommonFlags.Const, null, tn.tokenPos, true); - } else if (tn.skip(Token.LET)) { + } else if (tn.skip(Token.Let)) { initializer = this.parseVariable(tn, CommonFlags.Let, null, tn.tokenPos, true); - } else if (tn.skip(Token.VAR)) { + } else if (tn.skip(Token.Var)) { initializer = this.parseVariable(tn, CommonFlags.None, null, tn.tokenPos, true); - } else if (!tn.skip(Token.SEMICOLON)) { + } else if (!tn.skip(Token.Semicolon)) { initializer = this.parseExpressionStatement(tn); if (!initializer) return null; } if (initializer) { - if (tn.skip(Token.OF)) { + if (tn.skip(Token.Of)) { // TODO: for (let [key, val] of ...) if (initializer.kind == NodeKind.Expression) { if ((initializer).expression.kind != NodeKind.Identifier) { @@ -3168,20 +3168,20 @@ export class Parser extends DiagnosticEmitter { } } - if (tn.token == Token.SEMICOLON) { + if (tn.token == Token.Semicolon) { let condition: ExpressionStatement | null = null; - if (!tn.skip(Token.SEMICOLON)) { + if (!tn.skip(Token.Semicolon)) { condition = this.parseExpressionStatement(tn); if (!condition) return null; } - if (tn.token == Token.SEMICOLON) { + if (tn.token == Token.Semicolon) { let incrementor: Expression | null = null; - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { incrementor = this.parseExpression(tn); if (!incrementor) return null; - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { this.error( DiagnosticCode._0_expected, tn.range(), ")" @@ -3235,7 +3235,7 @@ export class Parser extends DiagnosticEmitter { var iterable = this.parseExpression(tn); if (!iterable) return null; - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { this.error( DiagnosticCode._0_expected, tn.range(), ")" @@ -3261,14 +3261,14 @@ export class Parser extends DiagnosticEmitter { // at 'if': '(' Expression ')' Statement ('else' Statement)? var startPos = tn.tokenPos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let condition = this.parseExpression(tn); if (!condition) return null; - if (tn.skip(Token.CLOSEPAREN)) { + if (tn.skip(Token.CloseParen)) { let statement = this.parseStatement(tn); if (!statement) return null; let elseStatement: Statement | null = null; - if (tn.skip(Token.ELSE)) { + if (tn.skip(Token.Else)) { elseStatement = this.parseStatement(tn); if (!elseStatement) return null; } @@ -3300,19 +3300,19 @@ export class Parser extends DiagnosticEmitter { // at 'switch': '(' Expression ')' '{' SwitchCase* '}' ';'? var startPos = tn.tokenPos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let condition = this.parseExpression(tn); if (!condition) return null; - if (tn.skip(Token.CLOSEPAREN)) { - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.CloseParen)) { + if (tn.skip(Token.OpenBrace)) { let switchCases = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { let switchCase = this.parseSwitchCase(tn); if (!switchCase) return null; switchCases.push(switchCase); } let ret = Node.createSwitchStatement(condition, switchCases, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -3345,15 +3345,15 @@ export class Parser extends DiagnosticEmitter { // 'case' Expression ':' Statement* - if (tn.skip(Token.CASE)) { + if (tn.skip(Token.Case)) { let label = this.parseExpression(tn); if (!label) return null; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { statements = new Array(); while ( - tn.peek() != Token.CASE && - tn.nextToken != Token.DEFAULT && - tn.nextToken != Token.CLOSEBRACE + tn.peek() != Token.Case && + tn.nextToken != Token.Default && + tn.nextToken != Token.CloseBrace ) { statement = this.parseStatement(tn); if (!statement) return null; @@ -3369,13 +3369,13 @@ export class Parser extends DiagnosticEmitter { // 'default' ':' Statement* - } else if (tn.skip(Token.DEFAULT)) { - if (tn.skip(Token.COLON)) { + } else if (tn.skip(Token.Default)) { + if (tn.skip(Token.Colon)) { statements = new Array(); while ( - tn.peek() != Token.CASE && - tn.nextToken != Token.DEFAULT && - tn.nextToken != Token.CLOSEBRACE + tn.peek() != Token.Case && + tn.nextToken != Token.Default && + tn.nextToken != Token.CloseBrace ) { statement = this.parseStatement(tn); if (!statement) return null; @@ -3407,7 +3407,7 @@ export class Parser extends DiagnosticEmitter { var expression = this.parseExpression(tn); if (!expression) return null; var ret = Node.createThrowStatement(expression, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3422,9 +3422,9 @@ export class Parser extends DiagnosticEmitter { var startPos = tn.tokenPos; var stmt: Statement | null; - if (tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.OpenBrace)) { let bodyStatements = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { stmt = this.parseStatement(tn); if (!stmt) return null; bodyStatements.push(stmt); @@ -3432,8 +3432,8 @@ export class Parser extends DiagnosticEmitter { let catchVariable: IdentifierExpression | null = null; let catchStatements: Statement[] | null = null; let finallyStatements: Statement[] | null = null; - if (tn.skip(Token.CATCH)) { - if (!tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.Catch)) { + if (!tn.skip(Token.OpenParen)) { this.error( DiagnosticCode._0_expected, tn.range(), "(" @@ -3448,14 +3448,14 @@ export class Parser extends DiagnosticEmitter { return null; } catchVariable = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { this.error( DiagnosticCode._0_expected, tn.range(), ")" ); return null; } - if (!tn.skip(Token.OPENBRACE)) { + if (!tn.skip(Token.OpenBrace)) { this.error( DiagnosticCode._0_expected, tn.range(), "{" @@ -3463,14 +3463,14 @@ export class Parser extends DiagnosticEmitter { return null; } catchStatements = []; - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { stmt = this.parseStatement(tn); if (!stmt) return null; catchStatements.push(stmt); } } - if (tn.skip(Token.FINALLY)) { - if (!tn.skip(Token.OPENBRACE)) { + if (tn.skip(Token.Finally)) { + if (!tn.skip(Token.OpenBrace)) { this.error( DiagnosticCode._0_expected, tn.range(), "{" @@ -3478,7 +3478,7 @@ export class Parser extends DiagnosticEmitter { return null; } finallyStatements = []; - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { stmt = this.parseStatement(tn); if (!stmt) return null; finallyStatements.push(stmt); @@ -3498,7 +3498,7 @@ export class Parser extends DiagnosticEmitter { finallyStatements, tn.range(startPos, tn.pos) ); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -3555,13 +3555,13 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let typeParameters: TypeParameterNode[] | null = null; - if (tn.skip(Token.LESSTHAN)) { + if (tn.skip(Token.LessThan)) { typeParameters = this.parseTypeParameters(tn); if (!typeParameters) return null; flags |= CommonFlags.Generic; } - if (tn.skip(Token.EQUALS)) { - tn.skip(Token.BAR); + if (tn.skip(Token.Equals)) { + tn.skip(Token.Bar); let type = this.parseType(tn); if (!type) return null; let depth = this.getRecursiveDepthForTypeDeclaration(name.text, type); @@ -3587,7 +3587,7 @@ export class Parser extends DiagnosticEmitter { type, tn.range(startPos, tn.pos) ); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); ret.overriddenModuleName = this.currentModuleName; return ret; } else { @@ -3613,11 +3613,11 @@ export class Parser extends DiagnosticEmitter { // at 'module': StringLiteral ';'? var startPos = tn.tokenPos; - assert(tn.next() == Token.STRINGLITERAL); // checked earlier + assert(tn.next() == Token.StringLiteral); // checked earlier var moduleName = tn.readString(); var ret = Node.createModuleDeclaration(moduleName, flags, tn.range(startPos, tn.pos)); this.currentModuleName = moduleName; - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3628,10 +3628,10 @@ export class Parser extends DiagnosticEmitter { // at 'void': Expression ';'? var startPos = tn.tokenPos; - var expression = this.parseExpression(tn, Precedence.GROUPING); + var expression = this.parseExpression(tn, Precedence.Grouping); if (!expression) return null; var ret = Node.createVoidStatement(expression, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3642,14 +3642,14 @@ export class Parser extends DiagnosticEmitter { // at 'while': '(' Expression ')' Statement ';'? var startPos = tn.tokenPos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let expression = this.parseExpression(tn); if (!expression) return null; - if (tn.skip(Token.CLOSEPAREN)) { + if (tn.skip(Token.CloseParen)) { let statement = this.parseStatement(tn); if (!statement) return null; let ret = Node.createWhileStatement(expression, statement, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -3676,24 +3676,24 @@ export class Parser extends DiagnosticEmitter { switch (token) { // TODO: SpreadExpression, YieldExpression - case Token.DOT_DOT_DOT: - case Token.YIELD: // fallthrough to unsupported UnaryPrefixExpression + case Token.DotDotDot: + case Token.Yield: // fallthrough to unsupported UnaryPrefixExpression // UnaryPrefixExpression - case Token.EXCLAMATION: - case Token.TILDE: - case Token.PLUS: - case Token.MINUS: - case Token.TYPEOF: - case Token.VOID: - case Token.DELETE: { - let operand = this.parseExpression(tn, Precedence.UNARY_PREFIX); + case Token.Exclamation: + case Token.Tilde: + case Token.Plus: + case Token.Minus: + case Token.TypeOf: + case Token.Void: + case Token.Delete: { + let operand = this.parseExpression(tn, Precedence.UnaryPrefix); if (!operand) return null; return Node.createUnaryPrefixExpression(token, operand, tn.range(startPos, tn.pos)); } - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { - let operand = this.parseExpression(tn, Precedence.UNARY_PREFIX); + case Token.PlusPlus: + case Token.MinusMinus: { + let operand = this.parseExpression(tn, Precedence.UnaryPrefix); if (!operand) return null; switch (operand.kind) { case NodeKind.Identifier: @@ -3710,7 +3710,7 @@ export class Parser extends DiagnosticEmitter { } // NewExpression - case Token.NEW: { + case Token.New: { if (!tn.skipIdentifier()) { this.error( DiagnosticCode.Identifier_expected, @@ -3723,7 +3723,7 @@ export class Parser extends DiagnosticEmitter { let typeArguments: TypeNode[] | null = null; let arguments_: Expression[] | null = null; if ( - tn.skip(Token.OPENPAREN) || + tn.skip(Token.OpenParen) || (typeArguments = this.tryParseTypeArgumentsBeforeArguments(tn)) ) { arguments_ = this.parseArguments(tn); @@ -3740,17 +3740,17 @@ export class Parser extends DiagnosticEmitter { } // Special IdentifierExpression - case Token.NULL: return Node.createNullExpression(tn.range()); - case Token.TRUE: return Node.createTrueExpression(tn.range()); - case Token.FALSE: return Node.createFalseExpression(tn.range()); - case Token.THIS: return Node.createThisExpression(tn.range()); - case Token.CONSTRUCTOR: return Node.createConstructorExpression(tn.range()); + case Token.Null: return Node.createNullExpression(tn.range()); + case Token.True: return Node.createTrueExpression(tn.range()); + case Token.False: return Node.createFalseExpression(tn.range()); + case Token.This: return Node.createThisExpression(tn.range()); + case Token.Constructor: return Node.createConstructorExpression(tn.range()); // ParenthesizedExpression or FunctionExpression - case Token.OPENPAREN: { + case Token.OpenParen: { // determine whether this is a function expression - if (tn.skip(Token.CLOSEPAREN)) { // must be a function expression (fast route) + if (tn.skip(Token.CloseParen)) { // must be a function expression (fast route) return this.parseFunctionExpressionCommon( tn, Node.createEmptyIdentifierExpression(tn.range(startPos)), @@ -3765,20 +3765,20 @@ export class Parser extends DiagnosticEmitter { switch (tn.next(IdentifierHandling.PREFER)) { // function expression - case Token.DOT_DOT_DOT: { + case Token.DotDotDot: { tn.reset(state); return this.parseFunctionExpression(tn); } // can be both - case Token.IDENTIFIER: { + case Token.Identifier: { tn.readIdentifier(); switch (tn.next()) { // if we got here, check for arrow - case Token.CLOSEPAREN: { + case Token.CloseParen: { if ( - !tn.skip(Token.COLON) && - !tn.skip(Token.EQUALS_GREATERTHAN) + !tn.skip(Token.Colon) && + !tn.skip(Token.EqualsGreaterThan) ) { again = false; break; @@ -3786,16 +3786,16 @@ export class Parser extends DiagnosticEmitter { // fall-through } // function expression - case Token.COLON: { // type annotation + case Token.Colon: { // type annotation tn.reset(state); return this.parseFunctionExpression(tn); } // optional parameter or parenthesized - case Token.QUESTION: { + case Token.Question: { if ( - tn.skip(Token.COLON) || // optional parameter with type - tn.skip(Token.COMMA) || // optional parameter without type - tn.skip(Token.CLOSEPAREN) // last optional parameter without type + tn.skip(Token.Colon) || // optional parameter with type + tn.skip(Token.Comma) || // optional parameter without type + tn.skip(Token.CloseParen) // last optional parameter without type ) { tn.reset(state); return this.parseFunctionExpression(tn); @@ -3803,7 +3803,7 @@ export class Parser extends DiagnosticEmitter { again = false; // parenthesized break; } - case Token.COMMA: { + case Token.Comma: { break; // continue } // parenthesized expression @@ -3827,7 +3827,7 @@ export class Parser extends DiagnosticEmitter { // parse parenthesized let inner = this.parseExpression(tn); if (!inner) return null; - if (!tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.CloseParen)) { this.error( DiagnosticCode._0_expected, tn.range(), ")" @@ -3838,19 +3838,19 @@ export class Parser extends DiagnosticEmitter { return this.maybeParseCallExpression(tn, inner); } // ArrayLiteralExpression - case Token.OPENBRACKET: { + case Token.OpenBracket: { let elementExpressions = new Array(); - while (!tn.skip(Token.CLOSEBRACKET)) { + while (!tn.skip(Token.CloseBracket)) { let expr: Expression | null; - if (tn.peek() == Token.COMMA) { + if (tn.peek() == Token.Comma) { expr = Node.createOmittedExpression(tn.range(tn.pos)); } else { - expr = this.parseExpression(tn, Precedence.COMMA + 1); + expr = this.parseExpression(tn, Precedence.Comma + 1); if (!expr) return null; } elementExpressions.push(expr); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEBRACKET)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseBracket)) { break; } else { this.error( @@ -3864,14 +3864,14 @@ export class Parser extends DiagnosticEmitter { return Node.createArrayLiteralExpression(elementExpressions, tn.range(startPos, tn.pos)); } // ObjectLiteralExpression - case Token.OPENBRACE: { + case Token.OpenBrace: { let startPos = tn.tokenPos; let names = new Array(); let values = new Array(); let name: IdentifierExpression; - while (!tn.skip(Token.CLOSEBRACE)) { + while (!tn.skip(Token.CloseBrace)) { if (!tn.skipIdentifier()) { - if (!tn.skip(Token.STRINGLITERAL)) { + if (!tn.skip(Token.StringLiteral)) { this.error( DiagnosticCode.Identifier_expected, tn.range(), @@ -3884,8 +3884,8 @@ export class Parser extends DiagnosticEmitter { name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } names.push(name); - if (tn.skip(Token.COLON)) { - let value = this.parseExpression(tn, Precedence.COMMA + 1); + if (tn.skip(Token.Colon)) { + let value = this.parseExpression(tn, Precedence.Comma + 1); if (!value) return null; values.push(value); } else if (!name.isQuoted) { @@ -3897,8 +3897,8 @@ export class Parser extends DiagnosticEmitter { ); return null; } - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseBrace)) { break; } else { this.error( @@ -3912,17 +3912,17 @@ export class Parser extends DiagnosticEmitter { return Node.createObjectLiteralExpression(names, values, tn.range(startPos, tn.pos)); } // AssertionExpression (unary prefix) - case Token.LESSTHAN: { + case Token.LessThan: { let toType = this.parseType(tn); if (!toType) return null; - if (!tn.skip(Token.GREATERTHAN)) { + if (!tn.skip(Token.GreaterThan)) { this.error( DiagnosticCode._0_expected, tn.range(), ">" ); return null; } - let expr = this.parseExpression(tn, Precedence.CALL); + let expr = this.parseExpression(tn, Precedence.Call); if (!expr) return null; return Node.createAssertionExpression( AssertionKind.Prefix, @@ -3931,20 +3931,20 @@ export class Parser extends DiagnosticEmitter { tn.range(startPos, tn.pos) ); } - case Token.IDENTIFIER: { + case Token.Identifier: { let identifierText = tn.readIdentifier(); if (identifierText == "null") return Node.createNullExpression(tn.range()); // special let identifier = Node.createIdentifierExpression(identifierText, tn.range(startPos, tn.pos)); - if (tn.skip(Token.TEMPLATELITERAL)) { + if (tn.skip(Token.TemplateLiteral)) { return this.parseTemplateLiteral(tn, identifier); } - if (tn.peek(true) == Token.EQUALS_GREATERTHAN && !tn.nextTokenOnNewLine) { + if (tn.peek(true) == Token.EqualsGreaterThan && !tn.nextTokenOnNewLine) { return this.parseFunctionExpressionCommon( tn, Node.createEmptyIdentifierExpression(tn.range(startPos)), [ Node.createParameter( - ParameterKind.DEFAULT, + ParameterKind.Default, identifier, Node.createOmittedType(identifier.range.atEnd), null, @@ -3958,8 +3958,8 @@ export class Parser extends DiagnosticEmitter { } return this.maybeParseCallExpression(tn, identifier, true); } - case Token.SUPER: { - if (tn.peek() != Token.DOT && tn.nextToken != Token.OPENPAREN) { + case Token.Super: { + if (tn.peek() != Token.Dot && tn.nextToken != Token.OpenParen) { this.error( DiagnosticCode._super_must_be_followed_by_an_argument_list_or_member_access, tn.range() @@ -3968,27 +3968,27 @@ export class Parser extends DiagnosticEmitter { let expr = Node.createSuperExpression(tn.range(startPos, tn.pos)); return this.maybeParseCallExpression(tn, expr); } - case Token.STRINGLITERAL: { + case Token.StringLiteral: { return Node.createStringLiteralExpression(tn.readString(), tn.range(startPos, tn.pos)); } - case Token.TEMPLATELITERAL: { + case Token.TemplateLiteral: { return this.parseTemplateLiteral(tn); } - case Token.INTEGERLITERAL: { + case Token.IntegerLiteral: { let value = tn.readInteger(); tn.checkForIdentifierStartAfterNumericLiteral(); return Node.createIntegerLiteralExpression(value, tn.range(startPos, tn.pos)); } - case Token.FLOATLITERAL: { + case Token.FloatLiteral: { let value = tn.readFloat(); tn.checkForIdentifierStartAfterNumericLiteral(); return Node.createFloatLiteralExpression(value, tn.range(startPos, tn.pos)); } // RegexpLiteralExpression // note that this also continues on invalid ones so the surrounding AST remains intact - case Token.SLASH: { + case Token.Slash: { let regexpPattern = tn.readRegexpPattern(); // also reports - if (!tn.skip(Token.SLASH)) { + if (!tn.skip(Token.Slash)) { this.error( DiagnosticCode._0_expected, tn.range(), "/" @@ -4001,16 +4001,16 @@ export class Parser extends DiagnosticEmitter { tn.range(startPos, tn.pos) ); } - case Token.FUNCTION: { + case Token.Function: { let expr = this.parseFunctionExpression(tn); if (!expr) return null; return this.maybeParseCallExpression(tn, expr); } - case Token.CLASS: { + case Token.Class: { return this.parseClassExpression(tn); } default: { - if (token == Token.ENDOFFILE) { + if (token == Token.EndOfFile) { this.error( DiagnosticCode.Unexpected_end_of_text, tn.range(startPos) @@ -4033,11 +4033,11 @@ export class Parser extends DiagnosticEmitter { // at '<': Type (',' Type)* '>' '(' var state = tn.mark(); - if (!tn.skip(Token.LESSTHAN)) return null; + if (!tn.skip(Token.LessThan)) return null; var start = tn.tokenPos; var typeArguments: TypeNode[] | null = null; do { - if (tn.peek() == Token.GREATERTHAN) { + if (tn.peek() == Token.GreaterThan) { break; } let type = this.parseType(tn, true, true); @@ -4047,10 +4047,10 @@ export class Parser extends DiagnosticEmitter { } if (!typeArguments) typeArguments = [ type ]; else typeArguments.push(type); - } while (tn.skip(Token.COMMA)); - if (tn.skip(Token.GREATERTHAN)) { + } while (tn.skip(Token.Comma)); + if (tn.skip(Token.GreaterThan)) { let end = tn.pos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { if (!typeArguments) { this.error( DiagnosticCode.Type_argument_list_cannot_be_empty, @@ -4071,12 +4071,12 @@ export class Parser extends DiagnosticEmitter { // at '(': (Expression (',' Expression)*)? ')' var args = new Array(); - while (!tn.skip(Token.CLOSEPAREN)) { - let expr = this.parseExpression(tn, Precedence.COMMA + 1); + while (!tn.skip(Token.CloseParen)) { + let expr = this.parseExpression(tn, Precedence.Comma + 1); if (!expr) return null; args.push(expr); - if (!tn.skip(Token.COMMA)) { - if (tn.skip(Token.CLOSEPAREN)) { + if (!tn.skip(Token.Comma)) { + if (tn.skip(Token.CloseParen)) { break; } else { this.error( @@ -4092,9 +4092,9 @@ export class Parser extends DiagnosticEmitter { parseExpression( tn: Tokenizer, - precedence: Precedence = Precedence.COMMA + precedence: Precedence = Precedence.Comma ): Expression | null { - assert(precedence != Precedence.NONE); + assert(precedence != Precedence.None); var expr = this.parseExpressionStart(tn); if (!expr) return null; var startPos = expr.range.start; @@ -4109,8 +4109,8 @@ export class Parser extends DiagnosticEmitter { switch (token) { // AssertionExpression - case Token.AS: { - if (tn.skip(Token.CONST)) { + case Token.As: { + if (tn.skip(Token.Const)) { expr = Node.createAssertionExpression( AssertionKind.Const, expr, @@ -4129,7 +4129,7 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.EXCLAMATION: { + case Token.Exclamation: { expr = Node.createAssertionExpression( AssertionKind.NonNull, expr, @@ -4140,7 +4140,7 @@ export class Parser extends DiagnosticEmitter { break; } // InstanceOfExpression - case Token.INSTANCEOF: { + case Token.InstanceOf: { let isType = this.parseType(tn); // reports if (!isType) return null; expr = Node.createInstanceOfExpression( @@ -4151,10 +4151,10 @@ export class Parser extends DiagnosticEmitter { break; } // ElementAccessExpression - case Token.OPENBRACKET: { + case Token.OpenBracket: { let next = this.parseExpression(tn); // reports if (!next) return null; - if (!tn.skip(Token.CLOSEBRACKET)) { + if (!tn.skip(Token.CloseBracket)) { this.error( DiagnosticCode._0_expected, tn.range(), "]" @@ -4170,8 +4170,8 @@ export class Parser extends DiagnosticEmitter { break; } // UnaryPostfixExpression - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { + case Token.PlusPlus: + case Token.MinusMinus: { if ( expr.kind != NodeKind.Identifier && expr.kind != NodeKind.ElementAccess && @@ -4190,19 +4190,19 @@ export class Parser extends DiagnosticEmitter { break; } // TernaryExpression - case Token.QUESTION: { + case Token.Question: { let ifThen = this.parseExpression(tn); if (!ifThen) return null; - if (!tn.skip(Token.COLON)) { + if (!tn.skip(Token.Colon)) { this.error( DiagnosticCode._0_expected, tn.range(), ":" ); return null; } - let ifElse = this.parseExpression(tn, precedence > Precedence.COMMA - ? Precedence.COMMA + 1 - : Precedence.COMMA + let ifElse = this.parseExpression(tn, precedence > Precedence.Comma + ? Precedence.Comma + 1 + : Precedence.Comma ); if (!ifElse) return null; expr = Node.createTernaryExpression( @@ -4214,18 +4214,18 @@ export class Parser extends DiagnosticEmitter { break; } // CommaExpression - case Token.COMMA: { + case Token.Comma: { let commaExprs: Expression[] = [ expr ]; do { - expr = this.parseExpression(tn, Precedence.COMMA + 1); + expr = this.parseExpression(tn, Precedence.Comma + 1); if (!expr) return null; commaExprs.push(expr); - } while (tn.skip(Token.COMMA)); + } while (tn.skip(Token.Comma)); expr = Node.createCommaExpression(commaExprs, tn.range(startPos, tn.pos)); break; } // PropertyAccessExpression - case Token.DOT: { + case Token.Dot: { if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { // expr '.' Identifier let next = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); expr = Node.createPropertyAccessExpression( @@ -4247,7 +4247,7 @@ export class Parser extends DiagnosticEmitter { return null; } } - if (tn.skip(Token.TEMPLATELITERAL)) { + if (tn.skip(Token.TemplateLiteral)) { expr = this.parseTemplateLiteral(tn, expr); if (!expr) return null; } else { @@ -4256,47 +4256,47 @@ export class Parser extends DiagnosticEmitter { break; } // BinaryExpression (right associative) - case Token.EQUALS: - case Token.PLUS_EQUALS: - case Token.MINUS_EQUALS: - case Token.ASTERISK_ASTERISK_EQUALS: - case Token.ASTERISK_EQUALS: - case Token.SLASH_EQUALS: - case Token.PERCENT_EQUALS: - case Token.LESSTHAN_LESSTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: - case Token.AMPERSAND_EQUALS: - case Token.CARET_EQUALS: - case Token.BAR_EQUALS: - case Token.ASTERISK_ASTERISK: { + case Token.Equals: + case Token.PlusEquals: + case Token.MinusEquals: + case Token.AsteriskAsteriskEquals: + case Token.AsteriskEquals: + case Token.SlashEquals: + case Token.PercentEquals: + case Token.LessThanLessThanEquals: + case Token.GreaterThanGreaterThanEquals: + case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.AmpersandEquals: + case Token.CaretEquals: + case Token.BarEquals: + case Token.AsteriskAsterisk: { let next = this.parseExpression(tn, nextPrecedence); if (!next) return null; expr = Node.createBinaryExpression(token, expr, next, tn.range(startPos, tn.pos)); break; } // BinaryExpression - case Token.LESSTHAN: - case Token.GREATERTHAN: - case Token.LESSTHAN_EQUALS: - case Token.GREATERTHAN_EQUALS: - case Token.EQUALS_EQUALS: - case Token.EQUALS_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS: - case Token.PLUS: - case Token.MINUS: - case Token.ASTERISK: - case Token.SLASH: - case Token.PERCENT: - case Token.LESSTHAN_LESSTHAN: - case Token.GREATERTHAN_GREATERTHAN: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: - case Token.AMPERSAND: - case Token.BAR: - case Token.CARET: - case Token.AMPERSAND_AMPERSAND: - case Token.BAR_BAR: { + case Token.LessThan: + case Token.GreaterThan: + case Token.LessThanEquals: + case Token.GreaterThanEquals: + case Token.EqualsEquals: + case Token.EqualsEqualsEquals: + case Token.ExclamationEqualsEquals: + case Token.ExclamationEquals: + case Token.Plus: + case Token.Minus: + case Token.Asterisk: + case Token.Slash: + case Token.Percent: + case Token.LessThanLessThan: + case Token.GreaterThanGreaterThan: + case Token.GreaterThanGreaterThanGreaterThan: + case Token.Ampersand: + case Token.Bar: + case Token.Caret: + case Token.AmpersandAmpersand: + case Token.BarBar: { let next = this.parseExpression(tn, nextPrecedence + 1); if (!next) return null; expr = Node.createBinaryExpression(token, expr, next, tn.range(startPos, tn.pos)); @@ -4320,7 +4320,7 @@ export class Parser extends DiagnosticEmitter { let expr = this.parseExpression(tn); if (!expr) return null; exprs.push(expr); - if (!tn.skip(Token.CLOSEBRACE)) { + if (!tn.skip(Token.CloseBrace)) { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -4374,7 +4374,7 @@ export class Parser extends DiagnosticEmitter { ): Expression { var typeArguments: TypeNode[] | null = null; while ( - tn.skip(Token.OPENPAREN) || + tn.skip(Token.OpenParen) || potentiallyGeneric && (typeArguments = this.tryParseTypeArgumentsBeforeArguments(tn)) ) { @@ -4398,34 +4398,34 @@ export class Parser extends DiagnosticEmitter { do { let nextToken = tn.peek(true); if ( - nextToken == Token.ENDOFFILE || // next step should handle this - nextToken == Token.SEMICOLON // end of the statement for sure + nextToken == Token.EndOfFile || // next step should handle this + nextToken == Token.Semicolon // end of the statement for sure ) { tn.next(); break; } if (tn.nextTokenOnNewLine) break; // end of the statement maybe switch (tn.next()) { - case Token.IDENTIFIER: { + case Token.Identifier: { tn.readIdentifier(); break; } - case Token.STRINGLITERAL: - case Token.TEMPLATELITERAL: { + case Token.StringLiteral: + case Token.TemplateLiteral: { tn.readString(); break; } - case Token.INTEGERLITERAL: { + case Token.IntegerLiteral: { tn.readInteger(); tn.checkForIdentifierStartAfterNumericLiteral(); break; } - case Token.FLOATLITERAL: { + case Token.FloatLiteral: { tn.readFloat(); tn.checkForIdentifierStartAfterNumericLiteral(); break; } - case Token.OPENBRACE: { + case Token.OpenBrace: { this.skipBlock(tn); break; } @@ -4441,7 +4441,7 @@ export class Parser extends DiagnosticEmitter { var again = true; do { switch (tn.next()) { - case Token.ENDOFFILE: { + case Token.EndOfFile: { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -4449,24 +4449,24 @@ export class Parser extends DiagnosticEmitter { again = false; break; } - case Token.OPENBRACE: { + case Token.OpenBrace: { ++depth; break; } - case Token.CLOSEBRACE: { + case Token.CloseBrace: { --depth; if (!depth) again = false; break; } - case Token.IDENTIFIER: { + case Token.Identifier: { tn.readIdentifier(); break; } - case Token.STRINGLITERAL:{ + case Token.StringLiteral:{ tn.readString(); break; } - case Token.TEMPLATELITERAL: { + case Token.TemplateLiteral: { tn.readString(); while(tn.readingTemplateString){ this.skipBlock(tn); @@ -4474,12 +4474,12 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.INTEGERLITERAL: { + case Token.IntegerLiteral: { tn.readInteger(); tn.checkForIdentifierStartAfterNumericLiteral(); break; } - case Token.FLOATLITERAL: { + case Token.FloatLiteral: { tn.readFloat(); tn.checkForIdentifierStartAfterNumericLiteral(); break; @@ -4491,78 +4491,78 @@ export class Parser extends DiagnosticEmitter { /** Operator precedence from least to largest. */ export const enum Precedence { - NONE, - COMMA, - SPREAD, - YIELD, - ASSIGNMENT, - CONDITIONAL, - LOGICAL_OR, - LOGICAL_AND, - BITWISE_OR, - BITWISE_XOR, - BITWISE_AND, - EQUALITY, - RELATIONAL, - SHIFT, - ADDITIVE, - MULTIPLICATIVE, - EXPONENTIATED, - UNARY_PREFIX, - UNARY_POSTFIX, - CALL, - MEMBERACCESS, - GROUPING + None, + Comma, + Spread, + Yield, + Assignment, + Conditional, + LogicalOr, + LogicalAnd, + BitwiseOr, + BitwiseXor, + BitwiseAnd, + Equality, + Relational, + Shift, + Additive, + Multiplicative, + Exponentiated, + UnaryPrefix, + UnaryPostfix, + Call, + MemberAccess, + Grouping } /** Determines the precende of a non-starting token. */ function determinePrecedence(kind: Token): Precedence { switch (kind) { - case Token.COMMA: return Precedence.COMMA; - case Token.EQUALS: - case Token.PLUS_EQUALS: - case Token.MINUS_EQUALS: - case Token.ASTERISK_ASTERISK_EQUALS: - case Token.ASTERISK_EQUALS: - case Token.SLASH_EQUALS: - case Token.PERCENT_EQUALS: - case Token.LESSTHAN_LESSTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: - case Token.AMPERSAND_EQUALS: - case Token.CARET_EQUALS: - case Token.BAR_EQUALS: return Precedence.ASSIGNMENT; - case Token.QUESTION: return Precedence.CONDITIONAL; - case Token.BAR_BAR: return Precedence.LOGICAL_OR; - case Token.AMPERSAND_AMPERSAND: return Precedence.LOGICAL_AND; - case Token.BAR: return Precedence.BITWISE_OR; - case Token.CARET: return Precedence.BITWISE_XOR; - case Token.AMPERSAND: return Precedence.BITWISE_AND; - case Token.EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS: - case Token.EQUALS_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS_EQUALS: return Precedence.EQUALITY; - case Token.AS: - case Token.IN: - case Token.INSTANCEOF: - case Token.LESSTHAN: - case Token.GREATERTHAN: - case Token.LESSTHAN_EQUALS: - case Token.GREATERTHAN_EQUALS: return Precedence.RELATIONAL; - case Token.LESSTHAN_LESSTHAN: - case Token.GREATERTHAN_GREATERTHAN: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: return Precedence.SHIFT; - case Token.PLUS: - case Token.MINUS: return Precedence.ADDITIVE; - case Token.ASTERISK: - case Token.SLASH: - case Token.PERCENT: return Precedence.MULTIPLICATIVE; - case Token.ASTERISK_ASTERISK: return Precedence.EXPONENTIATED; - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: return Precedence.UNARY_POSTFIX; - case Token.DOT: - case Token.OPENBRACKET: - case Token.EXCLAMATION: return Precedence.MEMBERACCESS; + case Token.Comma: return Precedence.Comma; + case Token.Equals: + case Token.PlusEquals: + case Token.MinusEquals: + case Token.AsteriskAsteriskEquals: + case Token.AsteriskEquals: + case Token.SlashEquals: + case Token.PercentEquals: + case Token.LessThanLessThanEquals: + case Token.GreaterThanGreaterThanEquals: + case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.AmpersandEquals: + case Token.CaretEquals: + case Token.BarEquals: return Precedence.Assignment; + case Token.Question: return Precedence.Conditional; + case Token.BarBar: return Precedence.LogicalOr; + case Token.AmpersandAmpersand: return Precedence.LogicalAnd; + case Token.Bar: return Precedence.BitwiseOr; + case Token.Caret: return Precedence.BitwiseXor; + case Token.Ampersand: return Precedence.BitwiseAnd; + case Token.EqualsEquals: + case Token.ExclamationEquals: + case Token.EqualsEqualsEquals: + case Token.ExclamationEqualsEquals: return Precedence.Equality; + case Token.As: + case Token.In: + case Token.InstanceOf: + case Token.LessThan: + case Token.GreaterThan: + case Token.LessThanEquals: + case Token.GreaterThanEquals: return Precedence.Relational; + case Token.LessThanLessThan: + case Token.GreaterThanGreaterThan: + case Token.GreaterThanGreaterThanGreaterThan: return Precedence.Shift; + case Token.Plus: + case Token.Minus: return Precedence.Additive; + case Token.Asterisk: + case Token.Slash: + case Token.Percent: return Precedence.Multiplicative; + case Token.AsteriskAsterisk: return Precedence.Exponentiated; + case Token.PlusPlus: + case Token.MinusMinus: return Precedence.UnaryPostfix; + case Token.Dot: + case Token.OpenBracket: + case Token.Exclamation: return Precedence.MemberAccess; } - return Precedence.NONE; + return Precedence.None; } diff --git a/src/program.ts b/src/program.ts index 39ab687cb0..ffac13af0d 100644 --- a/src/program.ts +++ b/src/program.ts @@ -361,36 +361,36 @@ export namespace OperatorKind { /** Converts a binary operator token to the respective operator kind. */ export function fromBinaryToken(token: Token): OperatorKind { switch (token) { - case Token.PLUS: - case Token.PLUS_EQUALS: return OperatorKind.ADD; - case Token.MINUS: - case Token.MINUS_EQUALS: return OperatorKind.SUB; - case Token.ASTERISK: - case Token.ASTERISK_EQUALS: return OperatorKind.MUL; - case Token.SLASH: - case Token.SLASH_EQUALS: return OperatorKind.DIV; - case Token.PERCENT: - case Token.PERCENT_EQUALS: return OperatorKind.REM; - case Token.ASTERISK_ASTERISK: - case Token.ASTERISK_ASTERISK_EQUALS: return OperatorKind.POW; - case Token.AMPERSAND: - case Token.AMPERSAND_EQUALS: return OperatorKind.BITWISE_AND; - case Token.BAR: - case Token.BAR_EQUALS: return OperatorKind.BITWISE_OR; - case Token.CARET: - case Token.CARET_EQUALS: return OperatorKind.BITWISE_XOR; - case Token.LESSTHAN_LESSTHAN: - case Token.LESSTHAN_LESSTHAN_EQUALS: return OperatorKind.BITWISE_SHL; - case Token.GREATERTHAN_GREATERTHAN: - case Token.GREATERTHAN_GREATERTHAN_EQUALS: return OperatorKind.BITWISE_SHR; - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: return OperatorKind.BITWISE_SHR_U; - case Token.EQUALS_EQUALS: return OperatorKind.EQ; - case Token.EXCLAMATION_EQUALS: return OperatorKind.NE; - case Token.GREATERTHAN: return OperatorKind.GT; - case Token.GREATERTHAN_EQUALS: return OperatorKind.GE; - case Token.LESSTHAN: return OperatorKind.LT; - case Token.LESSTHAN_EQUALS: return OperatorKind.LE; + case Token.Plus: + case Token.PlusEquals: return OperatorKind.ADD; + case Token.Minus: + case Token.MinusEquals: return OperatorKind.SUB; + case Token.Asterisk: + case Token.AsteriskEquals: return OperatorKind.MUL; + case Token.Slash: + case Token.SlashEquals: return OperatorKind.DIV; + case Token.Percent: + case Token.PercentEquals: return OperatorKind.REM; + case Token.AsteriskAsterisk: + case Token.AsteriskAsteriskEquals: return OperatorKind.POW; + case Token.Ampersand: + case Token.AmpersandEquals: return OperatorKind.BITWISE_AND; + case Token.Bar: + case Token.BarEquals: return OperatorKind.BITWISE_OR; + case Token.Caret: + case Token.CaretEquals: return OperatorKind.BITWISE_XOR; + case Token.LessThanLessThan: + case Token.LessThanLessThanEquals: return OperatorKind.BITWISE_SHL; + case Token.GreaterThanGreaterThan: + case Token.GreaterThanGreaterThanEquals: return OperatorKind.BITWISE_SHR; + case Token.GreaterThanGreaterThanGreaterThan: + case Token.GreaterThanGreaterThanGreaterThanEquals: return OperatorKind.BITWISE_SHR_U; + case Token.EqualsEquals: return OperatorKind.EQ; + case Token.ExclamationEquals: return OperatorKind.NE; + case Token.GreaterThan: return OperatorKind.GT; + case Token.GreaterThanEquals: return OperatorKind.GE; + case Token.LessThan: return OperatorKind.LT; + case Token.LessThanEquals: return OperatorKind.LE; } return OperatorKind.INVALID; } @@ -398,12 +398,12 @@ export namespace OperatorKind { /** Converts a unary prefix operator token to the respective operator kind. */ export function fromUnaryPrefixToken(token: Token): OperatorKind { switch (token) { - case Token.PLUS: return OperatorKind.PLUS; - case Token.MINUS: return OperatorKind.MINUS; - case Token.EXCLAMATION: return OperatorKind.NOT; - case Token.TILDE: return OperatorKind.BITWISE_NOT; - case Token.PLUS_PLUS: return OperatorKind.PREFIX_INC; - case Token.MINUS_MINUS: return OperatorKind.PREFIX_DEC; + case Token.Plus: return OperatorKind.PLUS; + case Token.Minus: return OperatorKind.MINUS; + case Token.Exclamation: return OperatorKind.NOT; + case Token.Tilde: return OperatorKind.BITWISE_NOT; + case Token.PlusPlus: return OperatorKind.PREFIX_INC; + case Token.MinusMinus: return OperatorKind.PREFIX_DEC; } return OperatorKind.INVALID; } @@ -411,8 +411,8 @@ export namespace OperatorKind { /** Converts a unary postfix operator token to the respective operator kind. */ export function fromUnaryPostfixToken(token: Token): OperatorKind { switch (token) { - case Token.PLUS_PLUS: return OperatorKind.POSTFIX_INC; - case Token.MINUS_MINUS: return OperatorKind.POSTFIX_DEC; + case Token.PlusPlus: return OperatorKind.POSTFIX_INC; + case Token.MinusMinus: return OperatorKind.POSTFIX_DEC; } return OperatorKind.INVALID; } @@ -2506,7 +2506,7 @@ export class Program extends DiagnosticEmitter { Node.createFunctionType( [ Node.createParameter( - ParameterKind.DEFAULT, + ParameterKind.Default, declaration.name, typeNode, null, diff --git a/src/resolver.ts b/src/resolver.ts index cd61430977..37d394b1de 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -376,11 +376,11 @@ export class Resolver extends DiagnosticEmitter { for (let i = 0; i < numParameters; ++i) { let parameterNode = parameterNodes[i]; switch (parameterNode.parameterKind) { - case ParameterKind.DEFAULT: { + case ParameterKind.Default: { requiredParameters = i + 1; break; } - case ParameterKind.REST: { + case ParameterKind.Rest: { assert(i == numParameters); hasRest = true; break; @@ -737,7 +737,7 @@ export class Resolver extends DiagnosticEmitter { : parameterNodes[i].initializer; if (!argumentExpression) { // optional but not have initializer should be handled in the other place - if (parameterNodes[i].parameterKind == ParameterKind.OPTIONAL) { + if (parameterNodes[i].parameterKind == ParameterKind.Optional) { continue; } // missing initializer -> too few arguments @@ -1812,7 +1812,7 @@ export class Resolver extends DiagnosticEmitter { var operand = node.operand; var operator = node.operator; switch (operator) { - case Token.MINUS: { + case Token.Minus: { // implicitly negate if an integer literal to distinguish between i32/u32/i64 if (operand.isLiteralKind(LiteralKind.Integer)) { return this.determineIntegerLiteralType( @@ -1823,9 +1823,9 @@ export class Resolver extends DiagnosticEmitter { } // fall-through } - case Token.PLUS: - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { + case Token.Plus: + case Token.PlusPlus: + case Token.MinusMinus: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -1844,7 +1844,7 @@ export class Resolver extends DiagnosticEmitter { } return type; } - case Token.EXCLAMATION: { + case Token.Exclamation: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -1854,7 +1854,7 @@ export class Resolver extends DiagnosticEmitter { } return Type.bool; // incl. references } - case Token.TILDE: { + case Token.Tilde: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -1873,7 +1873,7 @@ export class Resolver extends DiagnosticEmitter { } return type.intType; } - case Token.DOT_DOT_DOT: { + case Token.DotDotDot: { if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Not_implemented_0, @@ -1882,7 +1882,7 @@ export class Resolver extends DiagnosticEmitter { } return null; } - case Token.TYPEOF: { + case Token.TypeOf: { return this.program.stringInstance.type; } default: assert(false); @@ -1928,8 +1928,8 @@ export class Resolver extends DiagnosticEmitter { ): Type | null { var operator = node.operator; switch (operator) { - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { + case Token.PlusPlus: + case Token.MinusMinus: { let type = this.resolveExpression(node.operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -1996,28 +1996,28 @@ export class Resolver extends DiagnosticEmitter { // assignment: result is the target's type - case Token.EQUALS: - case Token.PLUS_EQUALS: - case Token.MINUS_EQUALS: - case Token.ASTERISK_EQUALS: - case Token.ASTERISK_ASTERISK_EQUALS: - case Token.SLASH_EQUALS: - case Token.PERCENT_EQUALS: - case Token.LESSTHAN_LESSTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_EQUALS: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: - case Token.AMPERSAND_EQUALS: - case Token.BAR_EQUALS: - case Token.CARET_EQUALS: { + case Token.Equals: + case Token.PlusEquals: + case Token.MinusEquals: + case Token.AsteriskEquals: + case Token.AsteriskAsteriskEquals: + case Token.SlashEquals: + case Token.PercentEquals: + case Token.LessThanLessThanEquals: + case Token.GreaterThanGreaterThanEquals: + case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.AmpersandEquals: + case Token.BarEquals: + case Token.CaretEquals: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } // comparison: result is Bool, preferring overloads, integer/float only - case Token.LESSTHAN: - case Token.GREATERTHAN: - case Token.LESSTHAN_EQUALS: - case Token.GREATERTHAN_EQUALS: { + case Token.LessThan: + case Token.GreaterThan: + case Token.LessThanEquals: + case Token.GreaterThanEquals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2039,8 +2039,8 @@ export class Resolver extends DiagnosticEmitter { // equality: result is Bool, preferring overloads, incl. references - case Token.EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS: { + case Token.EqualsEquals: + case Token.ExclamationEquals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2053,19 +2053,19 @@ export class Resolver extends DiagnosticEmitter { // identity: result is Bool, not supporting overloads - case Token.EQUALS_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS_EQUALS: { + case Token.EqualsEqualsEquals: + case Token.ExclamationEqualsEquals: { return Type.bool; } // arithmetics: result is common type of LHS and RHS, preferring overloads - case Token.PLUS: - case Token.MINUS: - case Token.ASTERISK: - case Token.SLASH: - case Token.PERCENT: // mod has special logic, but also behaves like this - case Token.ASTERISK_ASTERISK: { + case Token.Plus: + case Token.Minus: + case Token.Asterisk: + case Token.Slash: + case Token.Percent: // mod has special logic, but also behaves like this + case Token.AsteriskAsterisk: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2089,9 +2089,9 @@ export class Resolver extends DiagnosticEmitter { // shift: result is LHS (RHS is converted to LHS), preferring overloads - case Token.LESSTHAN_LESSTHAN: - case Token.GREATERTHAN_GREATERTHAN: - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: { + case Token.LessThanLessThan: + case Token.GreaterThanGreaterThan: + case Token.GreaterThanGreaterThanGreaterThan: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2113,9 +2113,9 @@ export class Resolver extends DiagnosticEmitter { // bitwise: result is common type of LHS and RHS with floats not being supported, preferring overloads - case Token.AMPERSAND: - case Token.BAR: - case Token.CARET: { + case Token.Ampersand: + case Token.Bar: + case Token.Caret: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2139,8 +2139,8 @@ export class Resolver extends DiagnosticEmitter { // logical: result is LHS (RHS is converted to LHS), not supporting overloads - case Token.AMPERSAND_AMPERSAND: - case Token.BAR_BAR: { + case Token.AmpersandAmpersand: + case Token.BarBar: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } } @@ -2798,7 +2798,7 @@ export class Resolver extends DiagnosticEmitter { var requiredParameters = 0; for (let i = 0; i < numSignatureParameters; ++i) { let parameterDeclaration = signatureParameters[i]; - if (parameterDeclaration.parameterKind == ParameterKind.DEFAULT) { + if (parameterDeclaration.parameterKind == ParameterKind.Default) { requiredParameters = i + 1; } let typeNode = parameterDeclaration.type; diff --git a/src/tokenizer.ts b/src/tokenizer.ts index b931a98438..8b0b91b017 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -42,137 +42,137 @@ export const enum Token { // keywords // discarded: ANY, BOOLEAN, NEVER, NUMBER, STRING, SYMBOL, UNDEFINED, LESSTHAN_SLASH - ABSTRACT, - AS, - ASYNC, - AWAIT, // ES2017 - BREAK, // ES2017 - CASE, // ES2017 - CATCH, // ES2017 - CLASS, // ES2017 - CONST, // ES2017 - CONTINUE, // ES2017 - CONSTRUCTOR, - DEBUGGER, // ES2017 - DECLARE, - DEFAULT, // ES2017 - DELETE, // ES2017 - DO, // ES2017 - ELSE, // ES2017 - ENUM, // ES2017 future - EXPORT, // ES2017 - EXTENDS, // ES2017 - FALSE, // ES - FINALLY, // ES2017 - FOR, // ES2017 - FROM, // AS possible identifier - FUNCTION, // ES2017 - GET, - IF, // ES2017 - IMPLEMENTS, // ES2017 non-lexical - IMPORT, // ES2017 - IN, // ES2017 - INSTANCEOF, // ES2017 - INTERFACE, // ES2017 non-lexical - IS, - KEYOF, - LET, // ES2017 non-lexical - MODULE, // AS possible identifier - NAMESPACE, // AS possible identifier - NEW, // ES2017 - NULL, // ES - OF, - OVERRIDE, - PACKAGE, // ES2017 non-lexical - PRIVATE, // ES2017 non-lexical - PROTECTED, // ES2017 non-lexical - PUBLIC, // ES2017 non-lexical - READONLY, - RETURN, // ES2017 - SET, - STATIC, // ES2017 non-lexical - SUPER, // ES2017 - SWITCH, // ES2017 - THIS, // ES2017 - THROW, // ES2017 - TRUE, // ES - TRY, // ES2017 - TYPE, // AS possible identifier - TYPEOF, // ES2017 - VAR, // ES2017 - VOID, // ES2017 - WHILE, // ES2017 - WITH, // ES2017 - YIELD, // ES2017 + Abstract, + As, + Async, + Await, // ES2017 + Break, // ES2017 + Case, // ES2017 + Catch, // ES2017 + Class, // ES2017 + Const, // ES2017 + Continue, // ES2017 + Constructor, + Debugger, // ES2017 + Declare, + Default, // ES2017 + Delete, // ES2017 + Do, // ES2017 + Else, // ES2017 + Enum, // ES2017 future + Export, // ES2017 + Extends, // ES2017 + False, // ES + Finally, // ES2017 + For, // ES2017 + From, // AS possible identifier + Function, // ES2017 + Get, + If, // ES2017 + Implements, // ES2017 non-lexical + Import, // ES2017 + In, // ES2017 + InstanceOf, // ES2017 + Interface, // ES2017 non-lexical + Is, + KeyOf, + Let, // ES2017 non-lexical + Module, // AS possible identifier + Namespace, // AS possible identifier + New, // ES2017 + Null, // ES + Of, + Override, + Package, // ES2017 non-lexical + Private, // ES2017 non-lexical + Protected, // ES2017 non-lexical + Public, // ES2017 non-lexical + Readonly, + Return, // ES2017 + Set, + Static, // ES2017 non-lexical + Super, // ES2017 + Switch, // ES2017 + This, // ES2017 + Throw, // ES2017 + True, // ES + Try, // ES2017 + Type, // AS possible identifier + TypeOf, // ES2017 + Var, // ES2017 + Void, // ES2017 + While, // ES2017 + With, // ES2017 + Yield, // ES2017 // punctuation - OPENBRACE, - CLOSEBRACE, - OPENPAREN, - CLOSEPAREN, - OPENBRACKET, - CLOSEBRACKET, - DOT, - DOT_DOT_DOT, - SEMICOLON, - COMMA, - LESSTHAN, - GREATERTHAN, - LESSTHAN_EQUALS, - GREATERTHAN_EQUALS, - EQUALS_EQUALS, - EXCLAMATION_EQUALS, - EQUALS_EQUALS_EQUALS, - EXCLAMATION_EQUALS_EQUALS, - EQUALS_GREATERTHAN, - PLUS, - MINUS, - ASTERISK_ASTERISK, - ASTERISK, - SLASH, - PERCENT, - PLUS_PLUS, - MINUS_MINUS, - LESSTHAN_LESSTHAN, - GREATERTHAN_GREATERTHAN, - GREATERTHAN_GREATERTHAN_GREATERTHAN, - AMPERSAND, - BAR, - CARET, - EXCLAMATION, - TILDE, - AMPERSAND_AMPERSAND, - BAR_BAR, - QUESTION, - COLON, - EQUALS, - PLUS_EQUALS, - MINUS_EQUALS, - ASTERISK_EQUALS, - ASTERISK_ASTERISK_EQUALS, - SLASH_EQUALS, - PERCENT_EQUALS, - LESSTHAN_LESSTHAN_EQUALS, - GREATERTHAN_GREATERTHAN_EQUALS, - GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS, - AMPERSAND_EQUALS, - BAR_EQUALS, - CARET_EQUALS, - AT, + OpenBrace, + CloseBrace, + OpenParen, + CloseParen, + OpenBracket, + CloseBracket, + Dot, + DotDotDot, + Semicolon, + Comma, + LessThan, + GreaterThan, + LessThanEquals, + GreaterThanEquals, + EqualsEquals, + ExclamationEquals, + EqualsEqualsEquals, + ExclamationEqualsEquals, + EqualsGreaterThan, + Plus, + Minus, + AsteriskAsterisk, + Asterisk, + Slash, + Percent, + PlusPlus, + MinusMinus, + LessThanLessThan, + GreaterThanGreaterThan, + GreaterThanGreaterThanGreaterThan, + Ampersand, + Bar, + Caret, + Exclamation, + Tilde, + AmpersandAmpersand, + BarBar, + Question, + Colon, + Equals, + PlusEquals, + MinusEquals, + AsteriskEquals, + AsteriskAsteriskEquals, + SlashEquals, + PercentEquals, + LessThanLessThanEquals, + GreaterThanGreaterThanEquals, + GreaterThanGreaterThanGreaterThanEquals, + AmpersandEquals, + BarEquals, + CaretEquals, + At, // literals - IDENTIFIER, - STRINGLITERAL, - INTEGERLITERAL, - FLOATLITERAL, - TEMPLATELITERAL, + Identifier, + StringLiteral, + IntegerLiteral, + FloatLiteral, + TemplateLiteral, // meta - INVALID, - ENDOFFILE + Invalid, + EndOfFile } export const enum IdentifierHandling { @@ -187,191 +187,191 @@ export function tokenFromKeyword(text: string): Token { switch (text.charCodeAt(0)) { case CharCode.a: { if (len == 5) { - if (text == "async") return Token.ASYNC; - if (text == "await") return Token.AWAIT; + if (text == "async") return Token.Async; + if (text == "await") return Token.Await; break; } - if (text == "as") return Token.AS; - if (text == "abstract") return Token.ABSTRACT; + if (text == "as") return Token.As; + if (text == "abstract") return Token.Abstract; break; } case CharCode.b: { - if (text == "break") return Token.BREAK; + if (text == "break") return Token.Break; break; } case CharCode.c: { if (len == 5) { - if (text == "const") return Token.CONST; - if (text == "class") return Token.CLASS; - if (text == "catch") return Token.CATCH; + if (text == "const") return Token.Const; + if (text == "class") return Token.Class; + if (text == "catch") return Token.Catch; break; } - if (text == "case") return Token.CASE; - if (text == "continue") return Token.CONTINUE; - if (text == "constructor") return Token.CONSTRUCTOR; + if (text == "case") return Token.Case; + if (text == "continue") return Token.Continue; + if (text == "constructor") return Token.Constructor; break; } case CharCode.d: { if (len == 7) { - if (text == "default") return Token.DEFAULT; - if (text == "declare") return Token.DECLARE; + if (text == "default") return Token.Default; + if (text == "declare") return Token.Declare; break; } - if (text == "do") return Token.DO; - if (text == "delete") return Token.DELETE; - if (text == "debugger") return Token.DEBUGGER; + if (text == "do") return Token.Do; + if (text == "delete") return Token.Delete; + if (text == "debugger") return Token.Debugger; break; } case CharCode.e: { if (len == 4) { - if (text == "else") return Token.ELSE; - if (text == "enum") return Token.ENUM; + if (text == "else") return Token.Else; + if (text == "enum") return Token.Enum; break; } - if (text == "export") return Token.EXPORT; - if (text == "extends") return Token.EXTENDS; + if (text == "export") return Token.Export; + if (text == "extends") return Token.Extends; break; } case CharCode.f: { if (len <= 5) { - if (text == "false") return Token.FALSE; - if (text == "for") return Token.FOR; - if (text == "from") return Token.FROM; + if (text == "false") return Token.False; + if (text == "for") return Token.For; + if (text == "from") return Token.From; break; } - if (text == "function") return Token.FUNCTION; - if (text == "finally") return Token.FINALLY; + if (text == "function") return Token.Function; + if (text == "finally") return Token.Finally; break; } case CharCode.g: { - if (text == "get") return Token.GET; + if (text == "get") return Token.Get; break; } case CharCode.i: { if (len == 2) { - if (text == "if") return Token.IF; - if (text == "in") return Token.IN; - if (text == "is") return Token.IS; + if (text == "if") return Token.If; + if (text == "in") return Token.In; + if (text == "is") return Token.Is; break; } switch (text.charCodeAt(3)) { case CharCode.l: { - if (text == "implements") return Token.IMPLEMENTS; + if (text == "implements") return Token.Implements; break; } case CharCode.o: { - if (text == "import") return Token.IMPORT; + if (text == "import") return Token.Import; break; } case CharCode.t: { - if (text == "instanceof") return Token.INSTANCEOF; + if (text == "instanceof") return Token.InstanceOf; break; } case CharCode.e: { - if (text == "interface") return Token.INTERFACE; + if (text == "interface") return Token.Interface; break; } } break; } case CharCode.k: { - if (text == "keyof") return Token.KEYOF; + if (text == "keyof") return Token.KeyOf; break; } case CharCode.l: { - if (text == "let") return Token.LET; + if (text == "let") return Token.Let; break; } case CharCode.m: { - if (text == "module") return Token.MODULE; + if (text == "module") return Token.Module; break; } case CharCode.n: { - if (text == "new") return Token.NEW; - if (text == "null") return Token.NULL; - if (text == "namespace") return Token.NAMESPACE; + if (text == "new") return Token.New; + if (text == "null") return Token.Null; + if (text == "namespace") return Token.Namespace; break; } case CharCode.o: { - if (text == "of") return Token.OF; - if (text == "override") return Token.OVERRIDE; + if (text == "of") return Token.Of; + if (text == "override") return Token.Override; break; } case CharCode.p: { if (len == 7) { - if (text == "private") return Token.PRIVATE; - if (text == "package") return Token.PACKAGE; + if (text == "private") return Token.Private; + if (text == "package") return Token.Package; break; } - if (text == "public") return Token.PUBLIC; - if (text == "protected") return Token.PROTECTED; + if (text == "public") return Token.Public; + if (text == "protected") return Token.Protected; break; } case CharCode.r: { - if (text == "return") return Token.RETURN; - if (text == "readonly") return Token.READONLY; + if (text == "return") return Token.Return; + if (text == "readonly") return Token.Readonly; break; } case CharCode.s: { if (len == 6) { - if (text == "switch") return Token.SWITCH; - if (text == "static") return Token.STATIC; + if (text == "switch") return Token.Switch; + if (text == "static") return Token.Static; break; } - if (text == "set") return Token.SET; - if (text == "super") return Token.SUPER; + if (text == "set") return Token.Set; + if (text == "super") return Token.Super; break; } case CharCode.t: { if (len == 4) { - if (text == "true") return Token.TRUE; - if (text == "this") return Token.THIS; - if (text == "type") return Token.TYPE; + if (text == "true") return Token.True; + if (text == "this") return Token.This; + if (text == "type") return Token.Type; break; } - if (text == "try") return Token.TRY; - if (text == "throw") return Token.THROW; - if (text == "typeof") return Token.TYPEOF; + if (text == "try") return Token.Try; + if (text == "throw") return Token.Throw; + if (text == "typeof") return Token.TypeOf; break; } case CharCode.v: { - if (text == "var") return Token.VAR; - if (text == "void") return Token.VOID; + if (text == "var") return Token.Var; + if (text == "void") return Token.Void; break; } case CharCode.w: { - if (text == "while") return Token.WHILE; - if (text == "with") return Token.WITH; + if (text == "while") return Token.While; + if (text == "with") return Token.With; break; } case CharCode.y: { - if (text == "yield") return Token.YIELD; + if (text == "yield") return Token.Yield; break; } } - return Token.INVALID; + return Token.Invalid; } export function tokenIsAlsoIdentifier(token: Token): bool { switch (token) { - case Token.ABSTRACT: - case Token.AS: - case Token.CONSTRUCTOR: - case Token.DECLARE: - case Token.DELETE: - case Token.FROM: - case Token.FOR: - case Token.GET: - case Token.INSTANCEOF: - case Token.IS: - case Token.KEYOF: - case Token.MODULE: - case Token.NAMESPACE: - case Token.NULL: - case Token.READONLY: - case Token.SET: - case Token.TYPE: - case Token.VOID: return true; + case Token.Abstract: + case Token.As: + case Token.Constructor: + case Token.Declare: + case Token.Delete: + case Token.From: + case Token.For: + case Token.Get: + case Token.InstanceOf: + case Token.Is: + case Token.KeyOf: + case Token.Module: + case Token.Namespace: + case Token.Null: + case Token.Readonly: + case Token.Set: + case Token.Type: + case Token.Void: return true; default: return false; } } @@ -390,54 +390,54 @@ export function isIllegalVariableIdentifier(name: string): bool { export function operatorTokenToString(token: Token): string { switch (token) { - case Token.DELETE: return "delete"; - case Token.IN: return "in"; - case Token.INSTANCEOF: return "instanceof"; - case Token.NEW: return "new"; - case Token.TYPEOF: return "typeof"; - case Token.VOID: return "void"; - case Token.YIELD: return "yield"; - case Token.DOT_DOT_DOT: return "..."; - case Token.COMMA: return ","; - case Token.LESSTHAN: return "<"; - case Token.GREATERTHAN: return ">"; - case Token.LESSTHAN_EQUALS: return "<="; - case Token.GREATERTHAN_EQUALS: return ">="; - case Token.EQUALS_EQUALS: return "=="; - case Token.EXCLAMATION_EQUALS: return "!="; - case Token.EQUALS_EQUALS_EQUALS: return "==="; - case Token.EXCLAMATION_EQUALS_EQUALS: return "!=="; - case Token.PLUS: return "+"; - case Token.MINUS: return "-"; - case Token.ASTERISK_ASTERISK: return "**"; - case Token.ASTERISK: return "*"; - case Token.SLASH: return "/"; - case Token.PERCENT: return "%"; - case Token.PLUS_PLUS: return "++"; - case Token.MINUS_MINUS: return "--"; - case Token.LESSTHAN_LESSTHAN: return "<<"; - case Token.GREATERTHAN_GREATERTHAN: return ">>"; - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: return ">>>"; - case Token.AMPERSAND: return "&"; - case Token.BAR: return "|"; - case Token.CARET: return "^"; - case Token.EXCLAMATION: return "!"; - case Token.TILDE: return "~"; - case Token.AMPERSAND_AMPERSAND: return "&&"; - case Token.BAR_BAR: return "||"; - case Token.EQUALS: return "="; - case Token.PLUS_EQUALS: return "+="; - case Token.MINUS_EQUALS: return "-="; - case Token.ASTERISK_EQUALS: return "*="; - case Token.ASTERISK_ASTERISK_EQUALS: return "**="; - case Token.SLASH_EQUALS: return "/="; - case Token.PERCENT_EQUALS: return "%="; - case Token.LESSTHAN_LESSTHAN_EQUALS: return "<<="; - case Token.GREATERTHAN_GREATERTHAN_EQUALS: return ">>="; - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: return ">>>="; - case Token.AMPERSAND_EQUALS: return "&="; - case Token.BAR_EQUALS: return "|="; - case Token.CARET_EQUALS: return "^="; + case Token.Delete: return "delete"; + case Token.In: return "in"; + case Token.InstanceOf: return "instanceof"; + case Token.New: return "new"; + case Token.TypeOf: return "typeof"; + case Token.Void: return "void"; + case Token.Yield: return "yield"; + case Token.DotDotDot: return "..."; + case Token.Comma: return ","; + case Token.LessThan: return "<"; + case Token.GreaterThan: return ">"; + case Token.LessThanEquals: return "<="; + case Token.GreaterThanEquals: return ">="; + case Token.EqualsEquals: return "=="; + case Token.ExclamationEquals: return "!="; + case Token.EqualsEqualsEquals: return "==="; + case Token.ExclamationEqualsEquals: return "!=="; + case Token.Plus: return "+"; + case Token.Minus: return "-"; + case Token.AsteriskAsterisk: return "**"; + case Token.Asterisk: return "*"; + case Token.Slash: return "/"; + case Token.Percent: return "%"; + case Token.PlusPlus: return "++"; + case Token.MinusMinus: return "--"; + case Token.LessThanLessThan: return "<<"; + case Token.GreaterThanGreaterThan: return ">>"; + case Token.GreaterThanGreaterThanGreaterThan: return ">>>"; + case Token.Ampersand: return "&"; + case Token.Bar: return "|"; + case Token.Caret: return "^"; + case Token.Exclamation: return "!"; + case Token.Tilde: return "~"; + case Token.AmpersandAmpersand: return "&&"; + case Token.BarBar: return "||"; + case Token.Equals: return "="; + case Token.PlusEquals: return "+="; + case Token.MinusEquals: return "-="; + case Token.AsteriskEquals: return "*="; + case Token.AsteriskAsteriskEquals: return "**="; + case Token.SlashEquals: return "/="; + case Token.PercentEquals: return "%="; + case Token.LessThanLessThanEquals: return "<<="; + case Token.GreaterThanGreaterThanEquals: return ">>="; + case Token.GreaterThanGreaterThanGreaterThanEquals: return ">>>="; + case Token.AmpersandEquals: return "&="; + case Token.BarEquals: return "|="; + case Token.CaretEquals: return "^="; default: { assert(false); return ""; @@ -506,7 +506,7 @@ export class Tokenizer extends DiagnosticEmitter { this.nextToken = -1; var token: Token; do token = this.unsafeNext(identifierHandling); - while (token == Token.INVALID); + while (token == Token.Invalid); this.token = token; return token; } @@ -549,22 +549,22 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.EXCLAMATION_EQUALS_EQUALS; + return Token.ExclamationEqualsEquals; } this.pos = pos; - return Token.EXCLAMATION_EQUALS; + return Token.ExclamationEquals; } this.pos = pos; - return Token.EXCLAMATION; + return Token.Exclamation; } case CharCode.DOUBLEQUOTE: case CharCode.SINGLEQUOTE: { this.pos = pos; - return Token.STRINGLITERAL; + return Token.StringLiteral; } case CharCode.BACKTICK: { this.pos = pos; - return Token.TEMPLATELITERAL; + return Token.TemplateLiteral; } case CharCode.PERCENT: { ++pos; @@ -573,10 +573,10 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.PERCENT_EQUALS; + return Token.PercentEquals; } this.pos = pos; - return Token.PERCENT; + return Token.Percent; } case CharCode.AMPERSAND: { ++pos; @@ -584,23 +584,23 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.AMPERSAND) { this.pos = pos + 1; - return Token.AMPERSAND_AMPERSAND; + return Token.AmpersandAmpersand; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.AMPERSAND_EQUALS; + return Token.AmpersandEquals; } } this.pos = pos; - return Token.AMPERSAND; + return Token.Ampersand; } case CharCode.OPENPAREN: { this.pos = pos + 1; - return Token.OPENPAREN; + return Token.OpenParen; } case CharCode.CLOSEPAREN: { this.pos = pos + 1; - return Token.CLOSEPAREN; + return Token.CloseParen; } case CharCode.ASTERISK: { ++pos; @@ -608,7 +608,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.ASTERISK_EQUALS; + return Token.AsteriskEquals; } if (chr == CharCode.ASTERISK) { ++pos; @@ -617,14 +617,14 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.ASTERISK_ASTERISK_EQUALS; + return Token.AsteriskAsteriskEquals; } this.pos = pos; - return Token.ASTERISK_ASTERISK; + return Token.AsteriskAsterisk; } } this.pos = pos; - return Token.ASTERISK; + return Token.Asterisk; } case CharCode.PLUS: { ++pos; @@ -632,19 +632,19 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.PLUS) { this.pos = pos + 1; - return Token.PLUS_PLUS; + return Token.PlusPlus; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.PLUS_EQUALS; + return Token.PlusEquals; } } this.pos = pos; - return Token.PLUS; + return Token.Plus; } case CharCode.COMMA: { this.pos = pos + 1; - return Token.COMMA; + return Token.Comma; } case CharCode.MINUS: { ++pos; @@ -652,15 +652,15 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.MINUS) { this.pos = pos + 1; - return Token.MINUS_MINUS; + return Token.MinusMinus; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.MINUS_EQUALS; + return Token.MinusEquals; } } this.pos = pos; - return Token.MINUS; + return Token.Minus; } case CharCode.DOT: { ++pos; @@ -668,7 +668,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (isDecimal(chr)) { this.pos = pos - 1; - return Token.FLOATLITERAL; // expects a call to readFloat + return Token.FloatLiteral; // expects a call to readFloat } if ( maxTokenLength > 2 && pos + 1 < end && @@ -676,11 +676,11 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos + 1) == CharCode.DOT ) { this.pos = pos + 2; - return Token.DOT_DOT_DOT; + return Token.DotDotDot; } } this.pos = pos; - return Token.DOT; + return Token.Dot; } case CharCode.SLASH: { let commentStartPos = pos; @@ -741,11 +741,11 @@ export class Tokenizer extends DiagnosticEmitter { } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.SLASH_EQUALS; + return Token.SlashEquals; } } this.pos = pos; - return Token.SLASH; + return Token.Slash; } case CharCode._0: case CharCode._1: @@ -759,16 +759,16 @@ export class Tokenizer extends DiagnosticEmitter { case CharCode._9: { this.pos = pos; return this.testInteger() - ? Token.INTEGERLITERAL // expects a call to readInteger - : Token.FLOATLITERAL; // expects a call to readFloat + ? Token.IntegerLiteral // expects a call to readInteger + : Token.FloatLiteral; // expects a call to readFloat } case CharCode.COLON: { this.pos = pos + 1; - return Token.COLON; + return Token.Colon; } case CharCode.SEMICOLON: { this.pos = pos + 1; - return Token.SEMICOLON; + return Token.Semicolon; } case CharCode.LESSTHAN: { ++pos; @@ -782,18 +782,18 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.LESSTHAN_LESSTHAN_EQUALS; + return Token.LessThanLessThanEquals; } this.pos = pos; - return Token.LESSTHAN_LESSTHAN; + return Token.LessThanLessThan; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.LESSTHAN_EQUALS; + return Token.LessThanEquals; } } this.pos = pos; - return Token.LESSTHAN; + return Token.LessThan; } case CharCode.EQUALS: { ++pos; @@ -807,18 +807,18 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.EQUALS_EQUALS_EQUALS; + return Token.EqualsEqualsEquals; } this.pos = pos; - return Token.EQUALS_EQUALS; + return Token.EqualsEquals; } if (chr == CharCode.GREATERTHAN) { this.pos = pos + 1; - return Token.EQUALS_GREATERTHAN; + return Token.EqualsGreaterThan; } } this.pos = pos; - return Token.EQUALS; + return Token.Equals; } case CharCode.GREATERTHAN: { ++pos; @@ -835,38 +835,38 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS; + return Token.GreaterThanGreaterThanGreaterThanEquals; } this.pos = pos; - return Token.GREATERTHAN_GREATERTHAN_GREATERTHAN; + return Token.GreaterThanGreaterThanGreaterThan; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.GREATERTHAN_GREATERTHAN_EQUALS; + return Token.GreaterThanGreaterThanEquals; } } this.pos = pos; - return Token.GREATERTHAN_GREATERTHAN; + return Token.GreaterThanGreaterThan; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.GREATERTHAN_EQUALS; + return Token.GreaterThanEquals; } } this.pos = pos; - return Token.GREATERTHAN; + return Token.GreaterThan; } case CharCode.QUESTION: { this.pos = pos + 1; - return Token.QUESTION; + return Token.Question; } case CharCode.OPENBRACKET: { this.pos = pos + 1; - return Token.OPENBRACKET; + return Token.OpenBracket; } case CharCode.CLOSEBRACKET: { this.pos = pos + 1; - return Token.CLOSEBRACKET; + return Token.CloseBracket; } case CharCode.CARET: { ++pos; @@ -875,14 +875,14 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.EQUALS ) { this.pos = pos + 1; - return Token.CARET_EQUALS; + return Token.CaretEquals; } this.pos = pos; - return Token.CARET; + return Token.Caret; } case CharCode.OPENBRACE: { this.pos = pos + 1; - return Token.OPENBRACE; + return Token.OpenBrace; } case CharCode.BAR: { ++pos; @@ -890,27 +890,27 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.BAR) { this.pos = pos + 1; - return Token.BAR_BAR; + return Token.BarBar; } if (chr == CharCode.EQUALS) { this.pos = pos + 1; - return Token.BAR_EQUALS; + return Token.BarEquals; } } this.pos = pos; - return Token.BAR; + return Token.Bar; } case CharCode.CLOSEBRACE: { this.pos = pos + 1; - return Token.CLOSEBRACE; + return Token.CloseBrace; } case CharCode.TILDE: { this.pos = pos + 1; - return Token.TILDE; + return Token.Tilde; } case CharCode.AT: { this.pos = pos + 1; - return Token.AT; + return Token.At; } default: { if (isIdentifierStart(c)) { @@ -922,7 +922,7 @@ export class Tokenizer extends DiagnosticEmitter { if (identifierHandling != IdentifierHandling.ALWAYS) { let maybeKeywordToken = tokenFromKeyword(text.substring(posBefore, pos)); if ( - maybeKeywordToken != Token.INVALID && + maybeKeywordToken != Token.Invalid && !( identifierHandling == IdentifierHandling.PREFER && tokenIsAlsoIdentifier(maybeKeywordToken) @@ -933,7 +933,7 @@ export class Tokenizer extends DiagnosticEmitter { } } this.pos = posBefore; - return Token.IDENTIFIER; + return Token.Identifier; } else if (isWhiteSpace(c)) { ++pos; break; @@ -948,12 +948,12 @@ export class Tokenizer extends DiagnosticEmitter { this.range(start, pos) ); this.pos = pos; - return Token.INVALID; + return Token.Invalid; } } } this.pos = pos; - return Token.ENDOFFILE; + return Token.EndOfFile; } peek( @@ -968,7 +968,7 @@ export class Tokenizer extends DiagnosticEmitter { let tokenPosBefore = this.tokenPos; let nextToken: Token; do nextToken = this.unsafeNext(identifierHandling, maxCompoundLength); - while (nextToken == Token.INVALID); + while (nextToken == Token.Invalid); this.nextToken = nextToken; this.nextTokenPos = this.tokenPos; if (checkOnNewLine) { @@ -988,7 +988,7 @@ export class Tokenizer extends DiagnosticEmitter { } skipIdentifier(identifierHandling: IdentifierHandling = IdentifierHandling.PREFER): bool { - return this.skip(Token.IDENTIFIER, identifierHandling); + return this.skip(Token.Identifier, identifierHandling); } skip(token: Token, identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT): bool { @@ -996,12 +996,12 @@ export class Tokenizer extends DiagnosticEmitter { var tokenBefore = this.token; var tokenPosBefore = this.tokenPos; var maxCompoundLength = i32.MAX_VALUE; - if (token == Token.GREATERTHAN) { // where parsing type arguments + if (token == Token.GreaterThan) { // where parsing type arguments maxCompoundLength = 1; } var nextToken: Token; do nextToken = this.unsafeNext(identifierHandling, maxCompoundLength); - while (nextToken == Token.INVALID); + while (nextToken == Token.Invalid); if (nextToken == token) { this.token = token; this.nextToken = -1; From b64f0f42c8c509fca14b52eea784bf859c995ac9 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 09:23:18 +0300 Subject: [PATCH 08/22] minor refactorings in compiler --- src/compiler.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index b94718f582..c7522d351a 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -10319,9 +10319,9 @@ export class Compiler extends DiagnosticEmitter { var abortInstance = program.abortInstance; if (!abortInstance || !this.compileFunction(abortInstance)) return module.unreachable(); - var filenameExpr = this.ensureStaticString(codeLocation.range.source.normalizedPath); var range = codeLocation.range; var source = range.source; + var filenameExpr = this.ensureStaticString(source.normalizedPath); return module.block(null, [ module.call( abortInstance.internalName, [ @@ -10348,8 +10348,9 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var flow = this.currentFlow; var temp = flow.getTempLocal(type); - if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.Wrapped); - flow.setLocalFlag(temp.index, LocalFlags.NonNull); + var tempIndex = temp.index; + if (!flow.canOverflow(expr, type)) flow.setLocalFlag(tempIndex, LocalFlags.Wrapped); + flow.setLocalFlag(tempIndex, LocalFlags.NonNull); var staticAbortCallExpr = this.makeStaticAbort( this.ensureStaticString("unexpected null"), @@ -10357,21 +10358,21 @@ export class Compiler extends DiagnosticEmitter { ); // TODO: throw if (type.isExternalReference) { - let nonNullExpr = module.local_get(temp.index, type.toRef()); + let nonNullExpr = module.local_get(tempIndex, type.toRef()); if (this.options.hasFeature(Feature.GC)) { nonNullExpr = module.ref_as_nonnull(nonNullExpr); } expr = module.if( module.ref_is_null( - module.local_tee(temp.index, expr, false) + module.local_tee(tempIndex, expr, false) ), staticAbortCallExpr, nonNullExpr ); } else { expr = module.if( - module.local_tee(temp.index, expr, type.isManaged), - module.local_get(temp.index, type.toRef()), + module.local_tee(tempIndex, expr, type.isManaged), + module.local_get(tempIndex, type.toRef()), staticAbortCallExpr ); } @@ -10395,6 +10396,7 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var flow = this.currentFlow; var temp = flow.getTempLocal(type); + var tempIndex = temp.index; var instanceofInstance = this.program.instanceofInstance; assert(this.compileFunction(instanceofInstance)); @@ -10408,21 +10410,21 @@ export class Compiler extends DiagnosticEmitter { // null-check would have been emitted separately so is not necessary here. expr = module.if( module.call(instanceofInstance.internalName, [ - module.local_tee(temp.index, expr, type.isManaged), + module.local_tee(tempIndex, expr, type.isManaged), module.i32(toType.classReference!.id) ], TypeRef.I32), - module.local_get(temp.index, type.toRef()), + module.local_get(tempIndex, type.toRef()), staticAbortCallExpr ); } else { expr = module.if( - module.local_tee(temp.index, expr, type.isManaged), + module.local_tee(tempIndex, expr, type.isManaged), module.if( module.call(instanceofInstance.internalName, [ - module.local_get(temp.index, type.toRef()), + module.local_get(tempIndex, type.toRef()), module.i32(toType.classReference!.id) ], TypeRef.I32), - module.local_get(temp.index, type.toRef()), + module.local_get(tempIndex, type.toRef()), staticAbortCallExpr ), module.usize(0) From 59d184663cfeebeeceb384d6b4ca17a6b522d3e1 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 09:48:13 +0300 Subject: [PATCH 09/22] more --- src/compiler.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index c7522d351a..8dd02a76cc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -4683,11 +4683,12 @@ export class Compiler extends DiagnosticEmitter { // if not possible, tee left to a temp. local } else { let temp = flow.getTempLocal(leftType); - if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.Wrapped); - if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(temp.index, LocalFlags.NonNull); + let tempIndex = temp.index; + if (!flow.canOverflow(leftExpr, leftType)) flow.setLocalFlag(tempIndex, LocalFlags.Wrapped); + if (flow.isNonnull(leftExpr, leftType)) flow.setLocalFlag(tempIndex, LocalFlags.NonNull); expr = module.if( - this.makeIsTrueish(module.local_tee(temp.index, leftExpr, leftType.isManaged), leftType, left), - module.local_get(temp.index, leftType.toRef()), + this.makeIsTrueish(module.local_tee(tempIndex, leftExpr, leftType.isManaged), leftType, left), + module.local_get(tempIndex, leftType.toRef()), rightExpr ); flow.freeTempLocal(temp); @@ -7102,10 +7103,11 @@ export class Compiler extends DiagnosticEmitter { if (getSideEffects(functionArg, module.ref) & SideEffects.WritesGlobal) { let flow = this.currentFlow; let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionArg)); + let tempIndex = temp.index; functionArg = module.block(null, [ - module.local_set(temp.index, functionArg, true), // Function + module.local_set(tempIndex, functionArg, true), // Function module.global_set(argumentsLength, module.i32(numArguments)), - module.local_get(temp.index, sizeTypeRef) + module.local_get(tempIndex, sizeTypeRef) ], sizeTypeRef); flow.freeTempLocal(temp); } else { // simplify @@ -7685,6 +7687,7 @@ export class Compiler extends DiagnosticEmitter { let program = this.program; if (!(actualType.isUnmanaged || expectedType.isUnmanaged)) { let temp = flow.getTempLocal(actualType); + let tempIndex = temp.index; let instanceofInstance = assert(program.instanceofInstance); this.compileFunction(instanceofInstance); let ret = module.if( @@ -7692,11 +7695,11 @@ export class Compiler extends DiagnosticEmitter { sizeTypeRef == TypeRef.I64 ? UnaryOp.EqzI64 : UnaryOp.EqzI32, - module.local_tee(temp.index, expr, actualType.isManaged), + module.local_tee(tempIndex, expr, actualType.isManaged), ), module.i32(0), this.makeCallDirect(instanceofInstance, [ - module.local_get(temp.index, sizeTypeRef), + module.local_get(tempIndex, sizeTypeRef), module.i32(expectedType.classReference!.id) ], expression) ); @@ -7731,6 +7734,7 @@ export class Compiler extends DiagnosticEmitter { // perform null checking, which would error earlier when checking // uninitialized (thus zero) `var a: A` to be an instance of something. let temp = flow.getTempLocal(actualType); + let tempIndex = temp.index; let instanceofInstance = assert(program.instanceofInstance); this.compileFunction(instanceofInstance); let ret = module.if( @@ -7738,11 +7742,11 @@ export class Compiler extends DiagnosticEmitter { sizeTypeRef == TypeRef.I64 ? UnaryOp.EqzI64 : UnaryOp.EqzI32, - module.local_tee(temp.index, expr, actualType.isManaged), + module.local_tee(tempIndex, expr, actualType.isManaged), ), module.i32(0), this.makeCallDirect(instanceofInstance, [ - module.local_get(temp.index, sizeTypeRef), + module.local_get(tempIndex, sizeTypeRef), module.i32(expectedType.classReference!.id) ], expression) ); From f4ed40bee9117529c3f77e24b312f963d53ebcea Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 11:20:28 +0300 Subject: [PATCH 10/22] refactor CharCode's enums to TitleCase --- src/ast.ts | 2 +- src/bindings/js.ts | 20 ++--- src/bindings/tsd.ts | 2 +- src/diagnostics.ts | 4 +- src/extra/ast.ts | 12 +-- src/parser.ts | 4 +- src/program.ts | 40 +++++----- src/tokenizer.ts | 182 +++++++++++++++++++++--------------------- src/util/path.ts | 18 ++--- src/util/text.ts | 188 ++++++++++++++++++++++---------------------- 10 files changed, 236 insertions(+), 236 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 2c86506eed..de1cb04dd4 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1676,7 +1676,7 @@ export class Source extends Node { let off = 0; let end = text.length; while (off < end) { - if (text.charCodeAt(off++) == CharCode.LINEFEED) lineCache.push(off); + if (text.charCodeAt(off++) == CharCode.LineFeed) lineCache.push(off); } lineCache.push(0x7fffffff); } diff --git a/src/bindings/js.ts b/src/bindings/js.ts index 8ae6b5be30..3a1af41b18 100644 --- a/src/bindings/js.ts +++ b/src/bindings/js.ts @@ -199,11 +199,11 @@ export class JSBuilder extends ExportsWalker { sb.push(i64_low((value).constantIntegerValue).toString()); } else { sb.push(" = exports[\""); - sb.push(escapeString(name + "." + value.name, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(name + "." + value.name, CharCode.DoubleQuote)); sb.push("\"].valueOf()"); } sb.push("] = \""); - sb.push(escapeString(value.name, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(value.name, CharCode.DoubleQuote)); sb.push("\",\n"); } } @@ -222,7 +222,7 @@ export class JSBuilder extends ExportsWalker { sb.push(name); } else { sb.push("\""); - sb.push(escapeString(name, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(name, CharCode.DoubleQuote)); sb.push("\": "); } let moduleId = this.ensureModuleId(moduleName); @@ -268,7 +268,7 @@ export class JSBuilder extends ExportsWalker { sb.push(name); } else { sb.push("\""); - sb.push(escapeString(name, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(name, CharCode.DoubleQuote)); sb.push("\""); } if (isPlainFunction(signature, Mode.Import) && !code) { @@ -514,7 +514,7 @@ export class JSBuilder extends ExportsWalker { sb.push(moduleName); } else { sb.push("\""); - sb.push(escapeString(moduleName, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(moduleName, CharCode.DoubleQuote)); sb.push("\""); } let resetPos = sb.length; @@ -590,7 +590,7 @@ export class JSBuilder extends ExportsWalker { map.push(moduleName); } else { map.push("[\""); - map.push(escapeString(moduleName, CharCode.DOUBLEQUOTE)); + map.push(escapeString(moduleName, CharCode.DoubleQuote)); map.push("\"]"); } map.push(";\n"); @@ -901,7 +901,7 @@ export class JSBuilder extends ExportsWalker { sb.push(moduleName); } else { sb.push("\""); - sb.push(escapeString(moduleName, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(moduleName, CharCode.DoubleQuote)); sb.push("\""); } sb.push(": __maybeDefault(__import"); @@ -910,14 +910,14 @@ export class JSBuilder extends ExportsWalker { importExpr.push("import * as __import"); importExpr.push(moduleId.toString()); importExpr.push(" from \""); - importExpr.push(escapeString(moduleName, CharCode.DOUBLEQUOTE)); + importExpr.push(escapeString(moduleName, CharCode.DoubleQuote)); importExpr.push("\";\n"); needsMaybeDefault = true; } } sb[0] = importExpr.join(""); sb.push(` } -))(new URL("${escapeString(options.basenameHint, CharCode.DOUBLEQUOTE)}.wasm", import.meta.url)); +))(new URL("${escapeString(options.basenameHint, CharCode.DoubleQuote)}.wasm", import.meta.url)); `); if (needsMaybeDefault) { sb.push(`function __maybeDefault(module) { @@ -1355,7 +1355,7 @@ function indentText(text: string, indentLevel: i32, sb: string[], butFirst: bool var length = text.length; var pos = 0; while (pos < length) { - if (text.charCodeAt(pos) == CharCode.LINEFEED) { + if (text.charCodeAt(pos) == CharCode.LineFeed) { if (butFirst) butFirst = false; else indent(sb, indentLevel); sb.push(text.substring(lineStart, lineStart = pos + 1)); diff --git a/src/bindings/tsd.ts b/src/bindings/tsd.ts index a8ce46c1ce..6085836818 100644 --- a/src/bindings/tsd.ts +++ b/src/bindings/tsd.ts @@ -218,7 +218,7 @@ export class TSDBuilder extends ExportsWalker { sb.push(moduleName); } else { sb.push("\""); - sb.push(escapeString(moduleName, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(moduleName, CharCode.DoubleQuote)); sb.push("\""); } sb.push(": unknown,\n"); diff --git a/src/diagnostics.ts b/src/diagnostics.ts index c82f0fb70a..bab81b26b3 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -282,7 +282,7 @@ function formatDiagnosticContext(range: Range): string { " │ " ]; while (start < range.start) { - if (text.charCodeAt(start) == CharCode.TAB) { + if (text.charCodeAt(start) == CharCode.Tab) { sb.push(" "); start += 2; } else { @@ -296,7 +296,7 @@ function formatDiagnosticContext(range: Range): string { } else { while (start++ < range.end) { let cc = text.charCodeAt(start); - if (cc == CharCode.TAB) { + if (cc == CharCode.Tab) { sb.push("~~"); } else if (isLineBreak(cc)) { sb.push(start == range.start + 1 ? "^" : "~"); diff --git a/src/extra/ast.ts b/src/extra/ast.ts index 0364a58db3..c235463fff 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -686,7 +686,7 @@ export class ASTBuilder { visitStringLiteral(str: string): void { var sb = this.sb; sb.push("\""); - sb.push(escapeString(str, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(str, CharCode.DoubleQuote)); sb.push("\""); } @@ -701,13 +701,13 @@ export class ASTBuilder { var expressions = node.expressions; if (tag) this.visitNode(tag); sb.push("`"); - sb.push(escapeString(parts[0], CharCode.BACKTICK)); + sb.push(escapeString(parts[0], CharCode.Backtick)); assert(parts.length == expressions.length + 1); for (let i = 0, k = expressions.length; i < k; ++i) { sb.push("${"); this.visitNode(expressions[i]); sb.push("}"); - sb.push(escapeString(parts[i + 1], CharCode.BACKTICK)); + sb.push(escapeString(parts[i + 1], CharCode.Backtick)); } sb.push("`"); } @@ -787,8 +787,8 @@ export class ASTBuilder { let last = sb[sb.length - 1]; let lastCharPos = last.length - 1; if (lastCharPos >= 0 && ( - last.charCodeAt(lastCharPos) == CharCode.CLOSEBRACE || - last.charCodeAt(lastCharPos) == CharCode.SEMICOLON) + last.charCodeAt(lastCharPos) == CharCode.CloseBrace || + last.charCodeAt(lastCharPos) == CharCode.Semicolon) ) { sb.push("\n"); } else { @@ -1484,7 +1484,7 @@ export class ASTBuilder { sb.push("declare "); } sb.push("module \""); - sb.push(escapeString(node.moduleName, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(node.moduleName, CharCode.DoubleQuote)); sb.push("\""); } diff --git a/src/parser.ts b/src/parser.ts index 1c58fb9158..70a23c7182 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4327,7 +4327,7 @@ export class Parser extends DiagnosticEmitter { ); return null; } - parts.push(tn.readString(CharCode.BACKTICK, tag != null)); + parts.push(tn.readString(CharCode.Backtick, tag != null)); rawParts.push(tn.source.text.substring(tn.readStringStart, tn.readStringEnd)); } return Node.createTemplateLiteralExpression(tag, parts, rawParts, exprs, tn.range(startPos, tn.pos)); @@ -4470,7 +4470,7 @@ export class Parser extends DiagnosticEmitter { tn.readString(); while(tn.readingTemplateString){ this.skipBlock(tn); - tn.readString(CharCode.BACKTICK); + tn.readString(CharCode.Backtick); } break; } diff --git a/src/program.ts b/src/program.ts index ffac13af0d..92ab72e198 100644 --- a/src/program.ts +++ b/src/program.ts @@ -251,65 +251,65 @@ export namespace OperatorKind { case DecoratorKind.Operator: case DecoratorKind.OperatorBinary: { switch (arg.charCodeAt(0)) { - case CharCode.OPENBRACKET: { + case CharCode.OpenBracket: { if (arg == "[]") return OperatorKind.INDEXED_GET; if (arg == "[]=") return OperatorKind.INDEXED_SET; break; } - case CharCode.OPENBRACE: { + case CharCode.OpenBrace: { if (arg == "{}") return OperatorKind.UNCHECKED_INDEXED_GET; if (arg == "{}=") return OperatorKind.UNCHECKED_INDEXED_SET; break; } - case CharCode.PLUS: { + case CharCode.Plus: { if (arg == "+") return OperatorKind.ADD; break; } - case CharCode.MINUS: { + case CharCode.Minus: { if (arg == "-") return OperatorKind.SUB; break; } - case CharCode.ASTERISK: { + case CharCode.Asterisk: { if (arg == "*") return OperatorKind.MUL; if (arg == "**") return OperatorKind.POW; break; } - case CharCode.SLASH: { + case CharCode.Slash: { if (arg == "/") return OperatorKind.DIV; break; } - case CharCode.PERCENT: { + case CharCode.Percent: { if (arg == "%") return OperatorKind.REM; break; } - case CharCode.AMPERSAND: { + case CharCode.Ampersand: { if (arg == "&") return OperatorKind.BITWISE_AND; break; } - case CharCode.BAR: { + case CharCode.Bar: { if (arg == "|") return OperatorKind.BITWISE_OR; break; } - case CharCode.CARET: { + case CharCode.Caret: { if (arg == "^") return OperatorKind.BITWISE_XOR; break; } - case CharCode.EQUALS: { + case CharCode.Equals: { if (arg == "==") return OperatorKind.EQ; break; } - case CharCode.EXCLAMATION: { + case CharCode.Exclamation: { if (arg == "!=") return OperatorKind.NE; break; } - case CharCode.GREATERTHAN: { + case CharCode.GreaterThan: { if (arg == ">") return OperatorKind.GT; if (arg == ">=") return OperatorKind.GE; if (arg == ">>") return OperatorKind.BITWISE_SHR; if (arg == ">>>") return OperatorKind.BITWISE_SHR_U; break; } - case CharCode.LESSTHAN: { + case CharCode.LessThan: { if (arg == "<") return OperatorKind.LT; if (arg == "<=") return OperatorKind.LE; if (arg == "<<") return OperatorKind.BITWISE_SHL; @@ -320,21 +320,21 @@ export namespace OperatorKind { } case DecoratorKind.OperatorPrefix: { switch (arg.charCodeAt(0)) { - case CharCode.PLUS: { + case CharCode.Plus: { if (arg == "+") return OperatorKind.PLUS; if (arg == "++") return OperatorKind.PREFIX_INC; break; } - case CharCode.MINUS: { + case CharCode.Minus: { if (arg == "-") return OperatorKind.MINUS; if (arg == "--") return OperatorKind.PREFIX_DEC; break; } - case CharCode.EXCLAMATION: { + case CharCode.Exclamation: { if (arg == "!") return OperatorKind.NOT; break; } - case CharCode.TILDE: { + case CharCode.Tilde: { if (arg == "~") return OperatorKind.BITWISE_NOT; break; } @@ -343,11 +343,11 @@ export namespace OperatorKind { } case DecoratorKind.OperatorPostfix: { switch (arg.charCodeAt(0)) { - case CharCode.PLUS: { + case CharCode.Plus: { if (arg == "++") return OperatorKind.POSTFIX_INC; break; } - case CharCode.MINUS: { + case CharCode.Minus: { if (arg == "--") return OperatorKind.POSTFIX_DEC; break; } diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 8b0b91b017..729b918d84 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -478,7 +478,7 @@ export class Tokenizer extends DiagnosticEmitter { // skip bom if ( pos < end && - text.charCodeAt(pos) == CharCode.BYTEORDERMARK + text.charCodeAt(pos) == CharCode.ByteOrderMark ) { ++pos; } @@ -486,13 +486,13 @@ export class Tokenizer extends DiagnosticEmitter { // skip shebang if ( pos + 1 < end && - text.charCodeAt(pos) == CharCode.HASH && - text.charCodeAt(pos + 1) == CharCode.EXCLAMATION + text.charCodeAt(pos) == CharCode.Hash && + text.charCodeAt(pos + 1) == CharCode.Exclamation ) { pos += 2; while ( pos < end && - text.charCodeAt(pos) != CharCode.LINEFEED + text.charCodeAt(pos) != CharCode.LineFeed ) { ++pos; } @@ -522,31 +522,31 @@ export class Tokenizer extends DiagnosticEmitter { this.tokenPos = pos; let c = text.charCodeAt(pos); switch (c) { - case CharCode.CARRIAGERETURN: { + case CharCode.CarriageReturn: { if (!( ++pos < end && - text.charCodeAt(pos) == CharCode.LINEFEED + text.charCodeAt(pos) == CharCode.LineFeed )) break; // otherwise fall-through } - case CharCode.LINEFEED: - case CharCode.TAB: - case CharCode.VERTICALTAB: - case CharCode.FORMFEED: - case CharCode.SPACE: { + case CharCode.LineFeed: + case CharCode.Tab: + case CharCode.VerticalTab: + case CharCode.FormFeed: + case CharCode.Space: { ++pos; break; } - case CharCode.EXCLAMATION: { + case CharCode.Exclamation: { ++pos; if ( maxTokenLength > 1 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { ++pos; if ( maxTokenLength > 2 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.ExclamationEqualsEquals; @@ -557,20 +557,20 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Exclamation; } - case CharCode.DOUBLEQUOTE: - case CharCode.SINGLEQUOTE: { + case CharCode.DoubleQuote: + case CharCode.SingleQuote: { this.pos = pos; return Token.StringLiteral; } - case CharCode.BACKTICK: { + case CharCode.Backtick: { this.pos = pos; return Token.TemplateLiteral; } - case CharCode.PERCENT: { + case CharCode.Percent: { ++pos; if ( maxTokenLength > 1 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.PercentEquals; @@ -578,15 +578,15 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Percent; } - case CharCode.AMPERSAND: { + case CharCode.Ampersand: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.AMPERSAND) { + if (chr == CharCode.Ampersand) { this.pos = pos + 1; return Token.AmpersandAmpersand; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.AmpersandEquals; } @@ -594,27 +594,27 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Ampersand; } - case CharCode.OPENPAREN: { + case CharCode.OpenParen: { this.pos = pos + 1; return Token.OpenParen; } - case CharCode.CLOSEPAREN: { + case CharCode.CloseParen: { this.pos = pos + 1; return Token.CloseParen; } - case CharCode.ASTERISK: { + case CharCode.Asterisk: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.AsteriskEquals; } - if (chr == CharCode.ASTERISK) { + if (chr == CharCode.Asterisk) { ++pos; if ( maxTokenLength > 2 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.AsteriskAsteriskEquals; @@ -626,15 +626,15 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Asterisk; } - case CharCode.PLUS: { + case CharCode.Plus: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.PLUS) { + if (chr == CharCode.Plus) { this.pos = pos + 1; return Token.PlusPlus; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.PlusEquals; } @@ -642,19 +642,19 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Plus; } - case CharCode.COMMA: { + case CharCode.Comma: { this.pos = pos + 1; return Token.Comma; } - case CharCode.MINUS: { + case CharCode.Minus: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.MINUS) { + if (chr == CharCode.Minus) { this.pos = pos + 1; return Token.MinusMinus; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.MinusEquals; } @@ -662,7 +662,7 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Minus; } - case CharCode.DOT: { + case CharCode.Dot: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); @@ -672,8 +672,8 @@ export class Tokenizer extends DiagnosticEmitter { } if ( maxTokenLength > 2 && pos + 1 < end && - chr == CharCode.DOT && - text.charCodeAt(pos + 1) == CharCode.DOT + chr == CharCode.Dot && + text.charCodeAt(pos + 1) == CharCode.Dot ) { this.pos = pos + 2; return Token.DotDotDot; @@ -682,22 +682,22 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Dot; } - case CharCode.SLASH: { + case CharCode.Slash: { let commentStartPos = pos; ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.SLASH) { // single-line + if (chr == CharCode.Slash) { // single-line let commentKind = CommentKind.LINE; if ( pos + 1 < end && - text.charCodeAt(pos + 1) == CharCode.SLASH + text.charCodeAt(pos + 1) == CharCode.Slash ) { ++pos; commentKind = CommentKind.TRIPLE; } while (++pos < end) { - if (text.charCodeAt(pos) == CharCode.LINEFEED) { + if (text.charCodeAt(pos) == CharCode.LineFeed) { ++pos; break; } @@ -711,14 +711,14 @@ export class Tokenizer extends DiagnosticEmitter { } break; } - if (chr == CharCode.ASTERISK) { // multi-line + if (chr == CharCode.Asterisk) { // multi-line let closed = false; while (++pos < end) { c = text.charCodeAt(pos); if ( - c == CharCode.ASTERISK && + c == CharCode.Asterisk && pos + 1 < end && - text.charCodeAt(pos + 1) == CharCode.SLASH + text.charCodeAt(pos + 1) == CharCode.Slash ) { pos += 2; closed = true; @@ -739,7 +739,7 @@ export class Tokenizer extends DiagnosticEmitter { } break; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.SlashEquals; } @@ -762,24 +762,24 @@ export class Tokenizer extends DiagnosticEmitter { ? Token.IntegerLiteral // expects a call to readInteger : Token.FloatLiteral; // expects a call to readFloat } - case CharCode.COLON: { + case CharCode.Colon: { this.pos = pos + 1; return Token.Colon; } - case CharCode.SEMICOLON: { + case CharCode.Semicolon: { this.pos = pos + 1; return Token.Semicolon; } - case CharCode.LESSTHAN: { + case CharCode.LessThan: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.LESSTHAN) { + if (chr == CharCode.LessThan) { ++pos; if ( maxTokenLength > 2 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.LessThanLessThanEquals; @@ -787,7 +787,7 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.LessThanLessThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.LessThanEquals; } @@ -795,16 +795,16 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.LessThan; } - case CharCode.EQUALS: { + case CharCode.Equals: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { ++pos; if ( maxTokenLength > 2 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.EqualsEqualsEquals; @@ -812,7 +812,7 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.EqualsEquals; } - if (chr == CharCode.GREATERTHAN) { + if (chr == CharCode.GreaterThan) { this.pos = pos + 1; return Token.EqualsGreaterThan; } @@ -820,19 +820,19 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Equals; } - case CharCode.GREATERTHAN: { + case CharCode.GreaterThan: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.GREATERTHAN) { + if (chr == CharCode.GreaterThan) { ++pos; if (maxTokenLength > 2 && pos < end) { chr = text.charCodeAt(pos); - if (chr == CharCode.GREATERTHAN) { + if (chr == CharCode.GreaterThan) { ++pos; if ( maxTokenLength > 3 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.GreaterThanGreaterThanGreaterThanEquals; @@ -840,7 +840,7 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.GreaterThanGreaterThanGreaterThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.GreaterThanGreaterThanEquals; } @@ -848,7 +848,7 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.GreaterThanGreaterThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.GreaterThanEquals; } @@ -856,23 +856,23 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.GreaterThan; } - case CharCode.QUESTION: { + case CharCode.Question: { this.pos = pos + 1; return Token.Question; } - case CharCode.OPENBRACKET: { + case CharCode.OpenBracket: { this.pos = pos + 1; return Token.OpenBracket; } - case CharCode.CLOSEBRACKET: { + case CharCode.CloseBracket: { this.pos = pos + 1; return Token.CloseBracket; } - case CharCode.CARET: { + case CharCode.Caret: { ++pos; if ( maxTokenLength > 1 && pos < end && - text.charCodeAt(pos) == CharCode.EQUALS + text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; return Token.CaretEquals; @@ -880,19 +880,19 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Caret; } - case CharCode.OPENBRACE: { + case CharCode.OpenBrace: { this.pos = pos + 1; return Token.OpenBrace; } - case CharCode.BAR: { + case CharCode.Bar: { ++pos; if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); - if (chr == CharCode.BAR) { + if (chr == CharCode.Bar) { this.pos = pos + 1; return Token.BarBar; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; return Token.BarEquals; } @@ -900,15 +900,15 @@ export class Tokenizer extends DiagnosticEmitter { this.pos = pos; return Token.Bar; } - case CharCode.CLOSEBRACE: { + case CharCode.CloseBrace: { this.pos = pos + 1; return Token.CloseBrace; } - case CharCode.TILDE: { + case CharCode.Tilde: { this.pos = pos + 1; return Token.Tilde; } - case CharCode.AT: { + case CharCode.At: { this.pos = pos + 1; return Token.At; } @@ -1092,7 +1092,7 @@ export class Tokenizer extends DiagnosticEmitter { result += text.substring(start, pos++); break; } - if (c == CharCode.BACKSLASH) { + if (c == CharCode.Backslash) { result += text.substring(start, pos); this.pos = pos; // save result += this.readEscapeSequence(isTaggedTemplate); @@ -1100,8 +1100,8 @@ export class Tokenizer extends DiagnosticEmitter { start = pos; continue; } - if (quote == CharCode.BACKTICK) { - if (c == CharCode.DOLLAR && pos + 1 < end && text.charCodeAt(pos + 1) == CharCode.OPENBRACE) { + if (quote == CharCode.Backtick) { + if (c == CharCode.Dollar && pos + 1 < end && text.charCodeAt(pos + 1) == CharCode.OpenBrace) { result += text.substring(start, pos); this.readStringEnd = pos; this.pos = pos + 2; @@ -1152,12 +1152,12 @@ export class Tokenizer extends DiagnosticEmitter { case CharCode.v: return "\v"; case CharCode.f: return "\f"; case CharCode.r: return "\r"; - case CharCode.SINGLEQUOTE: return "'"; - case CharCode.DOUBLEQUOTE: return "\""; + case CharCode.SingleQuote: return "'"; + case CharCode.DoubleQuote: return "\""; case CharCode.u: { if ( this.pos < end && - text.charCodeAt(this.pos) == CharCode.OPENBRACE + text.charCodeAt(this.pos) == CharCode.OpenBrace ) { ++this.pos; return this.readExtendedUnicodeEscape(isTaggedTemplate ? start : -1); // \u{DDDDDDDD} @@ -1167,18 +1167,18 @@ export class Tokenizer extends DiagnosticEmitter { case CharCode.x: { return this.readHexadecimalEscape(2, isTaggedTemplate ? start : - 1); // \xDD } - case CharCode.CARRIAGERETURN: { + case CharCode.CarriageReturn: { if ( this.pos < end && - text.charCodeAt(this.pos) == CharCode.LINEFEED + text.charCodeAt(this.pos) == CharCode.LineFeed ) { ++this.pos; } // fall through } - case CharCode.LINEFEED: - case CharCode.LINESEPARATOR: - case CharCode.PARAGRAPHSEPARATOR: return ""; + case CharCode.LineFeed: + case CharCode.LineSeparator: + case CharCode.ParagraphSeparator: return ""; default: return String.fromCodePoint(c); } } @@ -1196,13 +1196,13 @@ export class Tokenizer extends DiagnosticEmitter { ); break; } - if (text.charCodeAt(this.pos) == CharCode.BACKSLASH) { + if (text.charCodeAt(this.pos) == CharCode.Backslash) { ++this.pos; escaped = true; continue; } let c = text.charCodeAt(this.pos); - if (!escaped && c == CharCode.SLASH) break; + if (!escaped && c == CharCode.Slash) break; if (isLineBreak(c)) { this.error( DiagnosticCode.Unterminated_regular_expression_literal, @@ -1268,7 +1268,7 @@ export class Tokenizer extends DiagnosticEmitter { } while (pos < end) { let c = text.charCodeAt(pos); - if (c == CharCode.DOT || (c | 32) == CharCode.e) return false; + if (c == CharCode.Dot || (c | 32) == CharCode.e) return false; if (c != CharCode._ && (c < CharCode._0 || c > CharCode._9)) break; // does not validate separator placement (this is done in readXYInteger) pos++; @@ -1581,7 +1581,7 @@ export class Tokenizer extends DiagnosticEmitter { var end = this.end; var start = this.pos; var sepCount = this.readDecimalFloatPartial(false); - if (this.pos < end && text.charCodeAt(this.pos) == CharCode.DOT) { + if (this.pos < end && text.charCodeAt(this.pos) == CharCode.Dot) { ++this.pos; sepCount += this.readDecimalFloatPartial(); } @@ -1590,7 +1590,7 @@ export class Tokenizer extends DiagnosticEmitter { if ((c | 32) == CharCode.e) { if ( ++this.pos < end && - (c = text.charCodeAt(this.pos)) == CharCode.MINUS || c == CharCode.PLUS && + (c = text.charCodeAt(this.pos)) == CharCode.Minus || c == CharCode.Plus && isDecimal(text.charCodeAt(this.pos + 1)) ) { ++this.pos; @@ -1733,7 +1733,7 @@ export class Tokenizer extends DiagnosticEmitter { ); } invalid = true; - } else if (text.charCodeAt(this.pos) == CharCode.CLOSEBRACE) { + } else if (text.charCodeAt(this.pos) == CharCode.CloseBrace) { ++this.pos; } else { if (startIfTaggedTemplate == -1) { diff --git a/src/util/path.ts b/src/util/path.ts index a219388972..b1d39960d2 100644 --- a/src/util/path.ts +++ b/src/util/path.ts @@ -11,7 +11,7 @@ import { PATH_DELIMITER } from "../common"; -const separator = CharCode.SLASH; +const separator = CharCode.Slash; /** * Normalizes the specified path, removing interior placeholders. @@ -23,7 +23,7 @@ export function normalizePath(path: string): string { // trim leading './' while (pos + 1 < len && - path.charCodeAt(pos) == CharCode.DOT && + path.charCodeAt(pos) == CharCode.Dot && path.charCodeAt(pos + 1) == separator ) { pos += 2; @@ -42,7 +42,7 @@ export function normalizePath(path: string): string { // we are only interested in '/.' sequences ... if ( path.charCodeAt(pos) == separator && - path.charCodeAt(pos + 1) == CharCode.DOT + path.charCodeAt(pos + 1) == CharCode.Dot ) { // '/.' ( '/' | $ ) atEnd = pos + 2 == len; @@ -59,9 +59,9 @@ export function normalizePath(path: string): string { // '/.' ( './' | '.' $ ) atEnd = pos + 3 == len; - if (atEnd && path.charCodeAt(pos + 2) == CharCode.DOT || + if (atEnd && path.charCodeAt(pos + 2) == CharCode.Dot || pos + 3 < len && - path.charCodeAt(pos + 2) == CharCode.DOT && + path.charCodeAt(pos + 2) == CharCode.Dot && path.charCodeAt(pos + 3) == separator ) { // find preceeding '/' @@ -69,8 +69,8 @@ export function normalizePath(path: string): string { while (--ipos >= 0) { if (path.charCodeAt(ipos) == separator) { if (pos - ipos != 3 || - path.charCodeAt(ipos + 1) != CharCode.DOT || - path.charCodeAt(ipos + 2) != CharCode.DOT + path.charCodeAt(ipos + 1) != CharCode.Dot || + path.charCodeAt(ipos + 2) != CharCode.Dot ) { // exclude '..' itself path = atEnd ? path.substring(0, ipos) @@ -85,8 +85,8 @@ export function normalizePath(path: string): string { // if there's no preceeding '/', trim start if non-empty if (ipos < 0 && pos > 0) { if (pos != 2 || - path.charCodeAt(0) != CharCode.DOT || - path.charCodeAt(1) != CharCode.DOT + path.charCodeAt(0) != CharCode.Dot || + path.charCodeAt(1) != CharCode.Dot ) { // exclude '..' itself path = path.substring(pos + 4); len = path.length; diff --git a/src/util/text.ts b/src/util/text.ts index 60fe6a5410..1d041ea447 100644 --- a/src/util/text.ts +++ b/src/util/text.ts @@ -6,31 +6,31 @@ /** An enum of named character codes. */ export const enum CharCode { - NULL = 0, - LINEFEED = 0x0A, - CARRIAGERETURN = 0x0D, - LINESEPARATOR = 0x2028, - PARAGRAPHSEPARATOR = 0x2029, - NEXTLINE = 0x0085, - - SPACE = 0x20, - NONBREAKINGSPACE = 0xA0, - ENQUAD = 0x2000, - EMQUAD = 0x2001, - ENSPACE = 0x2002, - EMSPACE = 0x2003, - THREEPEREMSPACE = 0x2004, - FOURPEREMSPACE = 0x2005, - SIXPEREMSPACE = 0x2006, - FIGURESPACE = 0x2007, - PUNCTUATIONSPACE = 0x2008, - THINSPACE = 0x2009, - HAIRSPACE = 0x200A, - ZEROWIDTHSPACE = 0x200B, - NARROWNOBREAKSPACE = 0x202F, - IDEOGRAPHICSPACE = 0x3000, - MATHEMATICALSPACE = 0x205F, - OGHAM = 0x1680, + Null = 0, + LineFeed = 0x0A, + CarriageReturn = 0x0D, + LineSeparator = 0x2028, + ParagraphSeparator = 0x2029, + NextLine = 0x0085, + + Space = 0x20, + NonBreakingSpace = 0xA0, + EnQuad = 0x2000, + EmQuad = 0x2001, + EnSpace = 0x2002, + EmSpace = 0x2003, + ThreePerEmSpace = 0x2004, + FourPerEmSpace = 0x2005, + SixPerEmSpace = 0x2006, + FigureSpace = 0x2007, + PunctuationSpace = 0x2008, + ThinSpace = 0x2009, + HairSpace = 0x200A, + ZeroWidthSpace = 0x200B, + NarrowNoBreakSpace = 0x202F, + IdeographicSpace = 0x3000, + MathematicalSpace = 0x205F, + Ogham = 0x1680, _ = 0x5F, @@ -99,52 +99,52 @@ export const enum CharCode { Y = 0x59, Z = 0x5a, - AMPERSAND = 0x26, - ASTERISK = 0x2A, - AT = 0x40, - BACKSLASH = 0x5C, - BACKTICK = 0x60, - BAR = 0x7C, - CARET = 0x5E, - CLOSEBRACE = 0x7D, - CLOSEBRACKET = 0x5D, - CLOSEPAREN = 0x29, - COLON = 0x3A, - COMMA = 0x2C, - DOLLAR = 0x24, - DOT = 0x2E, - DOUBLEQUOTE = 0x22, - EQUALS = 0x3D, - EXCLAMATION = 0x21, - GREATERTHAN = 0x3E, - HASH = 0x23, - LESSTHAN = 0x3C, - MINUS = 0x2D, - OPENBRACE = 0x7B, - OPENBRACKET = 0x5B, - OPENPAREN = 0x28, - PERCENT = 0x25, - PLUS = 0x2B, - QUESTION = 0x3F, - SEMICOLON = 0x3B, - SINGLEQUOTE = 0x27, - SLASH = 0x2F, - TILDE = 0x7E, - - BACKSPACE = 0x08, - FORMFEED = 0x0C, - BYTEORDERMARK = 0xFEFF, - TAB = 0x09, - VERTICALTAB = 0x0B + Ampersand = 0x26, + Asterisk = 0x2A, + At = 0x40, + Backslash = 0x5C, + Backtick = 0x60, + Bar = 0x7C, + Caret = 0x5E, + CloseBrace = 0x7D, + CloseBracket = 0x5D, + CloseParen = 0x29, + Colon = 0x3A, + Comma = 0x2C, + Dollar = 0x24, + Dot = 0x2E, + DoubleQuote = 0x22, + Equals = 0x3D, + Exclamation = 0x21, + GreaterThan = 0x3E, + Hash = 0x23, + LessThan = 0x3C, + Minus = 0x2D, + OpenBrace = 0x7B, + OpenBracket = 0x5B, + OpenParen = 0x28, + Percent = 0x25, + Plus = 0x2B, + Question = 0x3F, + Semicolon = 0x3B, + SingleQuote = 0x27, + Slash = 0x2F, + Tilde = 0x7E, + + Backspace = 0x08, + FormFeed = 0x0C, + ByteOrderMark = 0xFEFF, + Tab = 0x09, + VerticalTab = 0x0B } /** Tests if the specified character code is some sort of line break. */ export function isLineBreak(c: i32): bool { switch (c) { - case CharCode.LINEFEED: - case CharCode.CARRIAGERETURN: - case CharCode.LINESEPARATOR: - case CharCode.PARAGRAPHSEPARATOR: { + case CharCode.LineFeed: + case CharCode.CarriageReturn: + case CharCode.LineSeparator: + case CharCode.ParagraphSeparator: { return true; } default: { @@ -156,21 +156,21 @@ export function isLineBreak(c: i32): bool { /** Tests if the specified character code is some sort of white space. */ export function isWhiteSpace(c: i32): bool { switch (c) { - case CharCode.SPACE: - case CharCode.TAB: - case CharCode.VERTICALTAB: - case CharCode.FORMFEED: - case CharCode.NONBREAKINGSPACE: - case CharCode.NEXTLINE: - case CharCode.OGHAM: - case CharCode.NARROWNOBREAKSPACE: - case CharCode.MATHEMATICALSPACE: - case CharCode.IDEOGRAPHICSPACE: - case CharCode.BYTEORDERMARK: { + case CharCode.Space: + case CharCode.Tab: + case CharCode.VerticalTab: + case CharCode.FormFeed: + case CharCode.NonBreakingSpace: + case CharCode.NextLine: + case CharCode.Ogham: + case CharCode.NarrowNoBreakSpace: + case CharCode.MathematicalSpace: + case CharCode.IdeographicSpace: + case CharCode.ByteOrderMark: { return true; } default: { - return c >= CharCode.ENQUAD && c <= CharCode.ZEROWIDTHSPACE; + return c >= CharCode.EnQuad && c <= CharCode.ZeroWidthSpace; } } } @@ -254,7 +254,7 @@ export function isAlphaOrDecimal(c: i32): bool { export function isIdentifierStart(c: i32): bool { return isAlpha(c) || c == CharCode._ - || c == CharCode.DOLLAR + || c == CharCode.Dollar || c >= 170 && c <= 65500 && lookupInUnicodeMap(c as u16, unicodeIdentifierStart); } @@ -263,7 +263,7 @@ export function isIdentifierStart(c: i32): bool { export function isIdentifierPart(c: i32): bool { return isAlphaOrDecimal(c) || c == CharCode._ - || c == CharCode.DOLLAR + || c == CharCode.Dollar || c >= 170 && c <= 65500 && lookupInUnicodeMap(c as u16, unicodeIdentifierPart); } @@ -477,50 +477,50 @@ export function escapeString(str: string, quote: CharCode): string { var i = 0; for (let k = str.length; i < k;) { switch (str.charCodeAt(i)) { - case CharCode.NULL: { + case CharCode.Null: { if (i > off) sb.push(str.substring(off, off = i + 1)); sb.push("\\0"); off = ++i; break; } - case CharCode.BACKSPACE: { + case CharCode.Backspace: { if (i > off) sb.push(str.substring(off, i)); off = ++i; sb.push("\\b"); break; } - case CharCode.TAB: { + case CharCode.Tab: { if (i > off) sb.push(str.substring(off, i)); off = ++i; sb.push("\\t"); break; } - case CharCode.LINEFEED: { + case CharCode.LineFeed: { if (i > off) sb.push(str.substring(off, i)); off = ++i; sb.push("\\n"); break; } - case CharCode.VERTICALTAB: { + case CharCode.VerticalTab: { if (i > off) sb.push(str.substring(off, i)); off = ++i; sb.push("\\v"); break; } - case CharCode.FORMFEED: { + case CharCode.FormFeed: { if (i > off) sb.push(str.substring(off, i)); off = ++i; sb.push("\\f"); break; } - case CharCode.CARRIAGERETURN: { + case CharCode.CarriageReturn: { if (i > off) sb.push(str.substring(off, i)); sb.push("\\r"); off = ++i; break; } - case CharCode.DOUBLEQUOTE: { - if (quote == CharCode.DOUBLEQUOTE) { + case CharCode.DoubleQuote: { + if (quote == CharCode.DoubleQuote) { if (i > off) sb.push(str.substring(off, i)); sb.push("\\\""); off = ++i; @@ -529,8 +529,8 @@ export function escapeString(str: string, quote: CharCode): string { } break; } - case CharCode.SINGLEQUOTE: { - if (quote == CharCode.SINGLEQUOTE) { + case CharCode.SingleQuote: { + if (quote == CharCode.SingleQuote) { if (i > off) sb.push(str.substring(off, i)); sb.push("\\'"); off = ++i; @@ -539,14 +539,14 @@ export function escapeString(str: string, quote: CharCode): string { } break; } - case CharCode.BACKSLASH: { + case CharCode.Backslash: { if (i > off) sb.push(str.substring(off, i)); sb.push("\\\\"); off = ++i; break; } - case CharCode.BACKTICK: { - if (quote == CharCode.BACKTICK) { + case CharCode.Backtick: { + if (quote == CharCode.Backtick) { if (i > off) sb.push(str.substring(off, i)); sb.push("\\`"); off = ++i; From 20c06f5fa173b423c18c2a770ae8421708fff694 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 5 Sep 2022 12:53:34 +0300 Subject: [PATCH 11/22] final --- src/ast.ts | 16 ++-- src/bindings/util.ts | 2 +- src/compiler.ts | 70 +++++++------- src/parser.ts | 42 ++++----- src/program.ts | 212 +++++++++++++++++++++---------------------- src/resolver.ts | 24 ++--- src/tokenizer.ts | 26 +++--- 7 files changed, 196 insertions(+), 196 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index de1cb04dd4..6d39b7800b 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1092,11 +1092,11 @@ export class DecoratorNode extends Node { /** Comment kinds. */ export const enum CommentKind { /** Line comment. */ - LINE, + Line, /** Triple-slash line comment. */ - TRIPLE, + Triple, /** Block comment. */ - BLOCK + Block } /** Represents a comment. */ @@ -1611,13 +1611,13 @@ export abstract class Statement extends Node { } /** Indicates the specific kind of a source. */ export const enum SourceKind { /** User-provided file. */ - USER = 0, + User = 0, /** User-provided entry file. */ - USER_ENTRY = 1, + UserEntry = 1, /** Library-provided file. */ - LIBRARY = 2, + Library = 2, /** Library-provided entry file. */ - LIBRARY_ENTRY = 3 + LibraryEntry = 3 } /** A top-level source node. */ @@ -1657,7 +1657,7 @@ export class Source extends Node { /** Checks if this source is part of the (standard) library. */ get isLibrary(): bool { var kind = this.sourceKind; - return kind == SourceKind.LIBRARY || kind == SourceKind.LIBRARY_ENTRY; + return kind == SourceKind.Library || kind == SourceKind.LibraryEntry; } /** Cached line starts. */ diff --git a/src/bindings/util.ts b/src/bindings/util.ts index d40bfb0c2b..32282e5579 100644 --- a/src/bindings/util.ts +++ b/src/bindings/util.ts @@ -44,7 +44,7 @@ export abstract class ExportsWalker { // TODO: for (let file of this.program.filesByName.values()) { for (let _values = Map_values(this.program.filesByName), i = 0, k = _values.length; i < k; ++i) { let file = unchecked(_values[i]); - if (file.source.sourceKind == SourceKind.USER_ENTRY) this.visitFile(file); + if (file.source.sourceKind == SourceKind.UserEntry) this.visitFile(file); } } diff --git a/src/compiler.ts b/src/compiler.ts index 8dd02a76cc..549daeb49c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -518,7 +518,7 @@ export class Compiler extends DiagnosticEmitter { // TODO: for (let file of files.values()) { for (let _values = Map_values(files), i = 0, k = _values.length; i < k; ++i) { let file = unchecked(_values[i]); - if (file.source.sourceKind == SourceKind.USER_ENTRY) { + if (file.source.sourceKind == SourceKind.UserEntry) { this.compileFile(file); this.compileModuleExports(file); } @@ -3838,7 +3838,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.LT); + let overload = classReference.lookupOverload(OperatorKind.Lt); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -3873,7 +3873,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.GT); + let overload = classReference.lookupOverload(OperatorKind.Gt); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -3908,7 +3908,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.LE); + let overload = classReference.lookupOverload(OperatorKind.Le); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -3943,7 +3943,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.GE); + let overload = classReference.lookupOverload(OperatorKind.Ge); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -3980,7 +3980,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.EQ); + let overload = classReference.lookupOverload(OperatorKind.Eq); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4032,7 +4032,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClass(); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.NE); + let overload = classReference.lookupOverload(OperatorKind.Ne); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4087,7 +4087,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.ADD); + let overload = classReference.lookupOverload(OperatorKind.Add); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4131,7 +4131,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.SUB); + let overload = classReference.lookupOverload(OperatorKind.Sub); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4176,7 +4176,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.MUL); + let overload = classReference.lookupOverload(OperatorKind.Mul); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4221,7 +4221,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.POW); + let overload = classReference.lookupOverload(OperatorKind.Pow); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4266,7 +4266,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.DIV); + let overload = classReference.lookupOverload(OperatorKind.Div); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4311,7 +4311,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.REM); + let overload = classReference.lookupOverload(OperatorKind.Rem); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4356,7 +4356,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_SHL); + let overload = classReference.lookupOverload(OperatorKind.BitwiseShl); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4383,7 +4383,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_SHR); + let overload = classReference.lookupOverload(OperatorKind.BitwiseShr); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4411,7 +4411,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_SHR_U); + let overload = classReference.lookupOverload(OperatorKind.BitwiseShrU); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4438,7 +4438,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overloadd let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_AND); + let overload = classReference.lookupOverload(OperatorKind.BitwiseAnd); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4483,7 +4483,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_OR); + let overload = classReference.lookupOverload(OperatorKind.BitwiseOr); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -4528,7 +4528,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = leftType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_XOR); + let overload = classReference.lookupOverload(OperatorKind.BitwiseXor); if (overload) { expr = this.compileBinaryOverload(overload, left, leftExpr, leftType, right, expression); break; @@ -5619,9 +5619,9 @@ export class Compiler extends DiagnosticEmitter { assert(parent.kind == ElementKind.Class); let classInstance = parent; let isUnchecked = flow.is(FlowFlags.UncheckedContext); - let indexedSet = classInstance.lookupOverload(OperatorKind.INDEXED_SET, isUnchecked); + let indexedSet = classInstance.lookupOverload(OperatorKind.IndexedSet, isUnchecked); if (!indexedSet) { - let indexedGet = classInstance.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + let indexedGet = classInstance.lookupOverload(OperatorKind.IndexedGet, isUnchecked); if (!indexedGet) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, @@ -5806,7 +5806,7 @@ export class Compiler extends DiagnosticEmitter { let classInstance = parent; assert(classInstance.kind == ElementKind.Class); let isUnchecked = flow.is(FlowFlags.UncheckedContext); - let getterInstance = classInstance.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + let getterInstance = classInstance.lookupOverload(OperatorKind.IndexedGet, isUnchecked); if (!getterInstance) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, @@ -5814,7 +5814,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - let setterInstance = classInstance.lookupOverload(OperatorKind.INDEXED_SET, isUnchecked); + let setterInstance = classInstance.lookupOverload(OperatorKind.IndexedSet, isUnchecked); if (!setterInstance) { this.error( DiagnosticCode.Index_signature_in_type_0_only_permits_reading, @@ -7157,7 +7157,7 @@ export class Compiler extends DiagnosticEmitter { let classReference = targetType.getClassOrWrapper(this.program); if (classReference) { let isUnchecked = this.currentFlow.is(FlowFlags.UncheckedContext); - let indexedGet = classReference.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + let indexedGet = classReference.lookupOverload(OperatorKind.IndexedGet, isUnchecked); if (indexedGet) { let thisType = assert(indexedGet.signature.thisType); let thisArg = this.compileExpression(targetExpression, thisType, @@ -7978,7 +7978,7 @@ export class Compiler extends DiagnosticEmitter { this.program.OBJECTInstance.writeField("gcInfo", 3, segment.buffer, 0); // use transparent gcinfo let offset = i64_add(segment.offset, i64_new(this.program.totalOverhead)); let joinInstance = assert(arrayInstance.getMethod("join")); - let indexedSetInstance = assert(arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true)); + let indexedSetInstance = assert(arrayInstance.lookupOverload(OperatorKind.IndexedSet, true)); let stmts = new Array(2 * numExpressions + 1); // Use one local per toString'ed subexpression, since otherwise recursion on the same // static array would overwrite already prepared parts. Avoids a temporary array. @@ -8172,7 +8172,7 @@ export class Compiler extends DiagnosticEmitter { } // otherwise compile an explicit instantiation with indexed sets - var indexedSet = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true); + var indexedSet = arrayInstance.lookupOverload(OperatorKind.IndexedSet, true); if (!indexedSet) { flow.freeTempLocal(tempThis); flow.freeTempLocal(tempDataStart); @@ -8334,7 +8334,7 @@ export class Compiler extends DiagnosticEmitter { } // otherwise compile an explicit instantiation with indexed sets - var indexedSet = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true); + var indexedSet = arrayInstance.lookupOverload(OperatorKind.IndexedSet, true); if (!indexedSet) { flow.freeTempLocal(tempThis); this.error( @@ -9090,7 +9090,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.POSTFIX_INC); + let overload = classReference.lookupOverload(OperatorKind.PostfixInc); if (overload) { let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns @@ -9176,7 +9176,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.POSTFIX_DEC); + let overload = classReference.lookupOverload(OperatorKind.PostfixDec); if (overload) { let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns @@ -9324,7 +9324,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.PLUS); + let overload = classReference.lookupOverload(OperatorKind.Plus); if (overload) return this.compileUnaryOverload(overload, expression.operand, expr, expression); } if (!this.currentType.isValue) { @@ -9357,7 +9357,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.MINUS); + let overload = classReference.lookupOverload(OperatorKind.Minus); if (overload) return this.compileUnaryOverload(overload, expression.operand, expr, expression); } if (!this.currentType.isValue) { @@ -9422,7 +9422,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.PREFIX_INC); + let overload = classReference.lookupOverload(OperatorKind.PrefixInc); if (overload) { expr = this.compileUnaryOverload(overload, expression.operand, expr, expression); if (overload.is(CommonFlags.Instance)) break; // re-assign @@ -9491,7 +9491,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.PREFIX_DEC); + let overload = classReference.lookupOverload(OperatorKind.PrefixDec); if (overload) { expr = this.compileUnaryOverload(overload, expression.operand, expr, expression); if (overload.is(CommonFlags.Instance)) break; // re-assign @@ -9559,7 +9559,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.NOT); + let overload = classReference.lookupOverload(OperatorKind.Not); if (overload) return this.compileUnaryOverload(overload, expression.operand, expr, expression); // fall back to compare by value } @@ -9582,7 +9582,7 @@ export class Compiler extends DiagnosticEmitter { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_NOT); + let overload = classReference.lookupOverload(OperatorKind.BitwiseNot); if (overload) return this.compileUnaryOverload(overload, expression.operand, expr, expression); } if (!this.currentType.isValue) { diff --git a/src/parser.ts b/src/parser.ts index 70a23c7182..858634b05a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -164,12 +164,12 @@ export class Parser extends DiagnosticEmitter { // create the source element var source = new Source( isEntry - ? SourceKind.USER_ENTRY + ? SourceKind.UserEntry : path.startsWith(LIBRARY_PREFIX) ? path.indexOf(PATH_DELIMITER, LIBRARY_PREFIX.length) < 0 - ? SourceKind.LIBRARY_ENTRY - : SourceKind.LIBRARY - : SourceKind.USER, + ? SourceKind.LibraryEntry + : SourceKind.Library + : SourceKind.User, normalizedPath, text ); @@ -322,7 +322,7 @@ export class Parser extends DiagnosticEmitter { case Token.Namespace: { let state = tn.mark(); tn.next(); - if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { + if (tn.peek(false, IdentifierHandling.Prefer) == Token.Identifier) { tn.discard(state); statement = this.parseNamespace(tn, flags, decorators, startPos); decorators = null; @@ -345,7 +345,7 @@ export class Parser extends DiagnosticEmitter { case Token.Type: { // also identifier let state = tn.mark(); tn.next(); - if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { + if (tn.peek(false, IdentifierHandling.Prefer) == Token.Identifier) { tn.discard(state); statement = this.parseTypeDeclaration(tn, flags, decorators, startPos); decorators = null; @@ -371,7 +371,7 @@ export class Parser extends DiagnosticEmitter { // handle plain exports if (flags & CommonFlags.Export) { - if (defaultEnd && tn.skipIdentifier(IdentifierHandling.PREFER)) { + if (defaultEnd && tn.skipIdentifier(IdentifierHandling.Prefer)) { if (declareEnd) { this.error( DiagnosticCode.An_export_assignment_cannot_have_modifiers, @@ -886,7 +886,7 @@ export class Parser extends DiagnosticEmitter { let name = tn.readIdentifier(); let expression: Expression = Node.createIdentifierExpression(name, tn.range(startPos, tn.pos)); while (tn.skip(Token.Dot)) { - if (tn.skipIdentifier(IdentifierHandling.PREFER)) { + if (tn.skipIdentifier(IdentifierHandling.Prefer)) { name = tn.readIdentifier(); expression = Node.createPropertyAccessExpression( expression, @@ -2035,7 +2035,7 @@ export class Parser extends DiagnosticEmitter { var setEnd = 0; if (!isInterface) { if (tn.skip(Token.Get)) { - if (tn.peek(true, IdentifierHandling.PREFER) == Token.Identifier && !tn.nextTokenOnNewLine) { + if (tn.peek(true, IdentifierHandling.Prefer) == Token.Identifier && !tn.nextTokenOnNewLine) { flags |= CommonFlags.Get; isGetter = true; getStart = tn.tokenPos; @@ -2051,7 +2051,7 @@ export class Parser extends DiagnosticEmitter { tn.reset(state); } } else if (tn.skip(Token.Set)) { - if (tn.peek(true, IdentifierHandling.PREFER) == Token.Identifier && !tn.nextTokenOnNewLine) { + if (tn.peek(true, IdentifierHandling.Prefer) == Token.Identifier && !tn.nextTokenOnNewLine) { flags |= CommonFlags.Set; isSetter = true; setStart = tn.tokenPos; @@ -2146,7 +2146,7 @@ export class Parser extends DiagnosticEmitter { tn.skip(Token.Semicolon); return retIndex; } - if (!tn.skipIdentifier(IdentifierHandling.ALWAYS)) { + if (!tn.skipIdentifier(IdentifierHandling.Always)) { this.error( DiagnosticCode.Identifier_expected, tn.range() @@ -2638,11 +2638,11 @@ export class Parser extends DiagnosticEmitter { // before: Identifier ('as' Identifier)? - if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { + if (tn.skipIdentifier(IdentifierHandling.Always)) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let asIdentifier: IdentifierExpression | null = null; if (tn.skip(Token.As)) { - if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { + if (tn.skipIdentifier(IdentifierHandling.Always)) { asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { this.error( @@ -2743,7 +2743,7 @@ export class Parser extends DiagnosticEmitter { ); return null; } - } else if (tn.skip(Token.Identifier, IdentifierHandling.PREFER)) { // import Name from "file" + } else if (tn.skip(Token.Identifier, IdentifierHandling.Prefer)) { // import Name from "file" let name = tn.readIdentifier(); let range = tn.range(); members = [ @@ -2804,7 +2804,7 @@ export class Parser extends DiagnosticEmitter { // before: Identifier ('as' Identifier)? - if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { + if (tn.skipIdentifier(IdentifierHandling.Always)) { let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let asIdentifier: IdentifierExpression | null = null; if (tn.skip(Token.As)) { @@ -2956,7 +2956,7 @@ export class Parser extends DiagnosticEmitter { break; } case Token.Type: { // also identifier - if (tn.peek(false, IdentifierHandling.PREFER) == Token.Identifier) { + if (tn.peek(false, IdentifierHandling.Prefer) == Token.Identifier) { statement = this.parseTypeDeclaration(tn, CommonFlags.None, null, tn.tokenPos); break; } @@ -3011,7 +3011,7 @@ export class Parser extends DiagnosticEmitter { var identifier: IdentifierExpression | null = null; if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { - tn.next(IdentifierHandling.PREFER); + tn.next(IdentifierHandling.Prefer); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } var ret = Node.createBreakStatement(identifier, tn.range()); @@ -3027,7 +3027,7 @@ export class Parser extends DiagnosticEmitter { var identifier: IdentifierExpression | null = null; if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { - tn.next(IdentifierHandling.PREFER); + tn.next(IdentifierHandling.Prefer); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } var ret = Node.createContinueStatement(identifier, tn.range()); @@ -3671,7 +3671,7 @@ export class Parser extends DiagnosticEmitter { parseExpressionStart( tn: Tokenizer ): Expression | null { - var token = tn.next(IdentifierHandling.PREFER); + var token = tn.next(IdentifierHandling.Prefer); var startPos = tn.tokenPos; switch (token) { @@ -3762,7 +3762,7 @@ export class Parser extends DiagnosticEmitter { let state = tn.mark(); let again = true; do { - switch (tn.next(IdentifierHandling.PREFER)) { + switch (tn.next(IdentifierHandling.Prefer)) { // function expression case Token.DotDotDot: { @@ -4226,7 +4226,7 @@ export class Parser extends DiagnosticEmitter { } // PropertyAccessExpression case Token.Dot: { - if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { // expr '.' Identifier + if (tn.skipIdentifier(IdentifierHandling.Always)) { // expr '.' Identifier let next = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); expr = Node.createPropertyAccessExpression( expr, diff --git a/src/program.ts b/src/program.ts index 92ab72e198..3ff37c5a0f 100644 --- a/src/program.ts +++ b/src/program.ts @@ -197,49 +197,49 @@ class QueuedExportStar { /** Represents the kind of an operator overload. */ export enum OperatorKind { - INVALID, + Invalid, // indexed access - INDEXED_GET, // a[] - INDEXED_SET, // a[]=b - UNCHECKED_INDEXED_GET, // unchecked(a[]) - UNCHECKED_INDEXED_SET, // unchecked(a[]=b) + IndexedGet, // a[] + IndexedSet, // a[]=b + UncheckedIndexedGet, // unchecked(a[]) + UncheckedIndexedSet, // unchecked(a[]=b) // binary - ADD, // a + b - SUB, // a - b - MUL, // a * b - DIV, // a / b - REM, // a % b - POW, // a ** b - BITWISE_AND, // a & b - BITWISE_OR, // a | b - BITWISE_XOR, // a ^ b - BITWISE_SHL, // a << b - BITWISE_SHR, // a >> b - BITWISE_SHR_U, // a >>> b - EQ, // a == b, a === b - NE, // a != b, a !== b - GT, // a > b - GE, // a >= b - LT, // a < b - LE, // a <= b + Add, // a + b + Sub, // a - b + Mul, // a * b + Div, // a / b + Rem, // a % b + Pow, // a ** b + BitwiseAnd, // a & b + BitwiseOr, // a | b + BitwiseXor, // a ^ b + BitwiseShl, // a << b + BitwiseShr, // a >> b + BitwiseShrU, // a >>> b + Eq, // a == b, a === b + Ne, // a != b, a !== b + Gt, // a > b + Ge, // a >= b + Lt, // a < b + Le, // a <= b // unary prefix - PLUS, // +a - MINUS, // -a - NOT, // !a - BITWISE_NOT, // ~a - PREFIX_INC, // ++a - PREFIX_DEC, // --a + Plus, // +a + Minus, // -a + Not, // !a + BitwiseNot, // ~a + PrefixInc, // ++a + PrefixDec, // --a // unary postfix - POSTFIX_INC, // a++ - POSTFIX_DEC // a-- + PostfixInc, // a++ + PostfixDec // a-- // not overridable: - // LOGICAL_AND // a && b - // LOGICAL_OR // a || b + // LogicalAnd // a && b + // LogicalOr // a || b } export namespace OperatorKind { @@ -252,67 +252,67 @@ export namespace OperatorKind { case DecoratorKind.OperatorBinary: { switch (arg.charCodeAt(0)) { case CharCode.OpenBracket: { - if (arg == "[]") return OperatorKind.INDEXED_GET; - if (arg == "[]=") return OperatorKind.INDEXED_SET; + if (arg == "[]") return OperatorKind.IndexedGet; + if (arg == "[]=") return OperatorKind.IndexedSet; break; } case CharCode.OpenBrace: { - if (arg == "{}") return OperatorKind.UNCHECKED_INDEXED_GET; - if (arg == "{}=") return OperatorKind.UNCHECKED_INDEXED_SET; + if (arg == "{}") return OperatorKind.UncheckedIndexedGet; + if (arg == "{}=") return OperatorKind.UncheckedIndexedSet; break; } case CharCode.Plus: { - if (arg == "+") return OperatorKind.ADD; + if (arg == "+") return OperatorKind.Add; break; } case CharCode.Minus: { - if (arg == "-") return OperatorKind.SUB; + if (arg == "-") return OperatorKind.Sub; break; } case CharCode.Asterisk: { - if (arg == "*") return OperatorKind.MUL; - if (arg == "**") return OperatorKind.POW; + if (arg == "*") return OperatorKind.Mul; + if (arg == "**") return OperatorKind.Pow; break; } case CharCode.Slash: { - if (arg == "/") return OperatorKind.DIV; + if (arg == "/") return OperatorKind.Div; break; } case CharCode.Percent: { - if (arg == "%") return OperatorKind.REM; + if (arg == "%") return OperatorKind.Rem; break; } case CharCode.Ampersand: { - if (arg == "&") return OperatorKind.BITWISE_AND; + if (arg == "&") return OperatorKind.BitwiseAnd; break; } case CharCode.Bar: { - if (arg == "|") return OperatorKind.BITWISE_OR; + if (arg == "|") return OperatorKind.BitwiseOr; break; } case CharCode.Caret: { - if (arg == "^") return OperatorKind.BITWISE_XOR; + if (arg == "^") return OperatorKind.BitwiseXor; break; } case CharCode.Equals: { - if (arg == "==") return OperatorKind.EQ; + if (arg == "==") return OperatorKind.Eq; break; } case CharCode.Exclamation: { - if (arg == "!=") return OperatorKind.NE; + if (arg == "!=") return OperatorKind.Ne; break; } case CharCode.GreaterThan: { - if (arg == ">") return OperatorKind.GT; - if (arg == ">=") return OperatorKind.GE; - if (arg == ">>") return OperatorKind.BITWISE_SHR; - if (arg == ">>>") return OperatorKind.BITWISE_SHR_U; + if (arg == ">") return OperatorKind.Gt; + if (arg == ">=") return OperatorKind.Ge; + if (arg == ">>") return OperatorKind.BitwiseShr; + if (arg == ">>>") return OperatorKind.BitwiseShrU; break; } case CharCode.LessThan: { - if (arg == "<") return OperatorKind.LT; - if (arg == "<=") return OperatorKind.LE; - if (arg == "<<") return OperatorKind.BITWISE_SHL; + if (arg == "<") return OperatorKind.Lt; + if (arg == "<=") return OperatorKind.Le; + if (arg == "<<") return OperatorKind.BitwiseShl; break; } } @@ -321,21 +321,21 @@ export namespace OperatorKind { case DecoratorKind.OperatorPrefix: { switch (arg.charCodeAt(0)) { case CharCode.Plus: { - if (arg == "+") return OperatorKind.PLUS; - if (arg == "++") return OperatorKind.PREFIX_INC; + if (arg == "+") return OperatorKind.Plus; + if (arg == "++") return OperatorKind.PrefixInc; break; } case CharCode.Minus: { - if (arg == "-") return OperatorKind.MINUS; - if (arg == "--") return OperatorKind.PREFIX_DEC; + if (arg == "-") return OperatorKind.Minus; + if (arg == "--") return OperatorKind.PrefixDec; break; } case CharCode.Exclamation: { - if (arg == "!") return OperatorKind.NOT; + if (arg == "!") return OperatorKind.Not; break; } case CharCode.Tilde: { - if (arg == "~") return OperatorKind.BITWISE_NOT; + if (arg == "~") return OperatorKind.BitwiseNot; break; } } @@ -344,77 +344,77 @@ export namespace OperatorKind { case DecoratorKind.OperatorPostfix: { switch (arg.charCodeAt(0)) { case CharCode.Plus: { - if (arg == "++") return OperatorKind.POSTFIX_INC; + if (arg == "++") return OperatorKind.PostfixInc; break; } case CharCode.Minus: { - if (arg == "--") return OperatorKind.POSTFIX_DEC; + if (arg == "--") return OperatorKind.PostfixDec; break; } } break; } } - return OperatorKind.INVALID; + return OperatorKind.Invalid; } /** Converts a binary operator token to the respective operator kind. */ export function fromBinaryToken(token: Token): OperatorKind { switch (token) { case Token.Plus: - case Token.PlusEquals: return OperatorKind.ADD; + case Token.PlusEquals: return OperatorKind.Add; case Token.Minus: - case Token.MinusEquals: return OperatorKind.SUB; + case Token.MinusEquals: return OperatorKind.Sub; case Token.Asterisk: - case Token.AsteriskEquals: return OperatorKind.MUL; + case Token.AsteriskEquals: return OperatorKind.Mul; case Token.Slash: - case Token.SlashEquals: return OperatorKind.DIV; + case Token.SlashEquals: return OperatorKind.Div; case Token.Percent: - case Token.PercentEquals: return OperatorKind.REM; + case Token.PercentEquals: return OperatorKind.Rem; case Token.AsteriskAsterisk: - case Token.AsteriskAsteriskEquals: return OperatorKind.POW; + case Token.AsteriskAsteriskEquals: return OperatorKind.Pow; case Token.Ampersand: - case Token.AmpersandEquals: return OperatorKind.BITWISE_AND; + case Token.AmpersandEquals: return OperatorKind.BitwiseAnd; case Token.Bar: - case Token.BarEquals: return OperatorKind.BITWISE_OR; + case Token.BarEquals: return OperatorKind.BitwiseOr; case Token.Caret: - case Token.CaretEquals: return OperatorKind.BITWISE_XOR; + case Token.CaretEquals: return OperatorKind.BitwiseXor; case Token.LessThanLessThan: - case Token.LessThanLessThanEquals: return OperatorKind.BITWISE_SHL; + case Token.LessThanLessThanEquals: return OperatorKind.BitwiseShl; case Token.GreaterThanGreaterThan: - case Token.GreaterThanGreaterThanEquals: return OperatorKind.BITWISE_SHR; + case Token.GreaterThanGreaterThanEquals: return OperatorKind.BitwiseShr; case Token.GreaterThanGreaterThanGreaterThan: - case Token.GreaterThanGreaterThanGreaterThanEquals: return OperatorKind.BITWISE_SHR_U; - case Token.EqualsEquals: return OperatorKind.EQ; - case Token.ExclamationEquals: return OperatorKind.NE; - case Token.GreaterThan: return OperatorKind.GT; - case Token.GreaterThanEquals: return OperatorKind.GE; - case Token.LessThan: return OperatorKind.LT; - case Token.LessThanEquals: return OperatorKind.LE; + case Token.GreaterThanGreaterThanGreaterThanEquals: return OperatorKind.BitwiseShrU; + case Token.EqualsEquals: return OperatorKind.Eq; + case Token.ExclamationEquals: return OperatorKind.Ne; + case Token.GreaterThan: return OperatorKind.Gt; + case Token.GreaterThanEquals: return OperatorKind.Ge; + case Token.LessThan: return OperatorKind.Lt; + case Token.LessThanEquals: return OperatorKind.Le; } - return OperatorKind.INVALID; + return OperatorKind.Invalid; } /** Converts a unary prefix operator token to the respective operator kind. */ export function fromUnaryPrefixToken(token: Token): OperatorKind { switch (token) { - case Token.Plus: return OperatorKind.PLUS; - case Token.Minus: return OperatorKind.MINUS; - case Token.Exclamation: return OperatorKind.NOT; - case Token.Tilde: return OperatorKind.BITWISE_NOT; - case Token.PlusPlus: return OperatorKind.PREFIX_INC; - case Token.MinusMinus: return OperatorKind.PREFIX_DEC; + case Token.Plus: return OperatorKind.Plus; + case Token.Minus: return OperatorKind.Minus; + case Token.Exclamation: return OperatorKind.Not; + case Token.Tilde: return OperatorKind.BitwiseNot; + case Token.PlusPlus: return OperatorKind.PrefixInc; + case Token.MinusMinus: return OperatorKind.PrefixDec; } - return OperatorKind.INVALID; + return OperatorKind.Invalid; } /** Converts a unary postfix operator token to the respective operator kind. */ export function fromUnaryPostfixToken(token: Token): OperatorKind { switch (token) { - case Token.PlusPlus: return OperatorKind.POSTFIX_INC; - case Token.MinusMinus: return OperatorKind.POSTFIX_DEC; + case Token.PlusPlus: return OperatorKind.PostfixInc; + case Token.MinusMinus: return OperatorKind.PostfixDec; } - return OperatorKind.INVALID; + return OperatorKind.Invalid; } } @@ -429,7 +429,7 @@ export class Program extends DiagnosticEmitter { diagnostics: DiagnosticMessage[] | null = null ) { super(diagnostics); - var nativeSource = new Source(SourceKind.LIBRARY_ENTRY, LIBRARY_PREFIX + "native.ts", "[native code]"); + var nativeSource = new Source(SourceKind.LibraryEntry, LIBRARY_PREFIX + "native.ts", "[native code]"); this.nativeSource = nativeSource; this.parser = new Parser(this.diagnostics, this.sources); this.resolver = new Resolver(this); @@ -1438,7 +1438,7 @@ export class Program extends DiagnosticEmitter { // TODO: for (let file of this.filesByName.values()) { for (let _values = Map_values(this.filesByName), i = 0, k = _values.length; i < k; ++i) { let file = unchecked(_values[i]); - if (file.source.sourceKind == SourceKind.USER_ENTRY) { + if (file.source.sourceKind == SourceKind.UserEntry) { this.markModuleExports(file); } } @@ -2014,7 +2014,7 @@ export class Program extends DiagnosticEmitter { if (firstArg.isLiteralKind(LiteralKind.String)) { let text = (firstArg).value; let kind = OperatorKind.fromDecorator(decorator.decoratorKind, text); - if (kind == OperatorKind.INVALID) { + if (kind == OperatorKind.Invalid) { this.error( DiagnosticCode._0_is_not_a_valid_operator, firstArg.range, text @@ -3111,7 +3111,7 @@ export class File extends Element { var exports = this.exports; if (!exports) this.exports = exports = new Map(); exports.set(name, element); - if (this.source.sourceKind == SourceKind.LIBRARY_ENTRY) this.program.ensureGlobal(name, element); + if (this.source.sourceKind == SourceKind.LibraryEntry) this.program.ensureGlobal(name, element); // Also, add to the namespaces that capture our exports for(let i = 0; i < this.aliasNamespaces.length; i++) { @@ -3473,7 +3473,7 @@ export class Local extends VariableLikeElement { export class FunctionPrototype extends DeclaredElement { /** Operator kind, if an overload. */ - operatorKind: OperatorKind = OperatorKind.INVALID; + operatorKind: OperatorKind = OperatorKind.Invalid; /** Already resolved instances. */ instances: Map | null = null; /** Methods overloading this one, if any. These are unbound. */ @@ -4046,12 +4046,12 @@ export class IndexSignature extends TypedElement { /** Obtains the getter instance. */ getGetterInstance(isUnchecked: bool): Function | null { - return (this.parent).lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + return (this.parent).lookupOverload(OperatorKind.IndexedGet, isUnchecked); } /** Obtains the setter instance. */ getSetterInstance(isUnchecked: bool): Function | null { - return (this.parent).lookupOverload(OperatorKind.INDEXED_SET, isUnchecked); + return (this.parent).lookupOverload(OperatorKind.IndexedSet, isUnchecked); } } @@ -4236,8 +4236,8 @@ export class Class extends TypedElement { (lengthField).getterPrototype != null // TODO: resolve & check type? ) ) && ( - this.lookupOverload(OperatorKind.INDEXED_GET) != null || - this.lookupOverload(OperatorKind.UNCHECKED_INDEXED_GET) != null + this.lookupOverload(OperatorKind.IndexedGet) != null || + this.lookupOverload(OperatorKind.UncheckedIndexedGet) != null ); } @@ -4354,13 +4354,13 @@ export class Class extends TypedElement { lookupOverload(kind: OperatorKind, unchecked: bool = false): Function | null { if (unchecked) { switch (kind) { - case OperatorKind.INDEXED_GET: { - let uncheckedOverload = this.lookupOverload(OperatorKind.UNCHECKED_INDEXED_GET); + case OperatorKind.IndexedGet: { + let uncheckedOverload = this.lookupOverload(OperatorKind.UncheckedIndexedGet); if (uncheckedOverload) return uncheckedOverload; break; } - case OperatorKind.INDEXED_SET: { - let uncheckedOverload = this.lookupOverload(OperatorKind.UNCHECKED_INDEXED_SET); + case OperatorKind.IndexedSet: { + let uncheckedOverload = this.lookupOverload(OperatorKind.UncheckedIndexedSet); if (uncheckedOverload) return uncheckedOverload; break; } diff --git a/src/resolver.ts b/src/resolver.ts index 37d394b1de..3e230e4853 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -489,7 +489,7 @@ export class Resolver extends DiagnosticEmitter { } return null; } - var overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + var overload = classReference.lookupOverload(OperatorKind.IndexedGet); if (overload) { let parameterTypes = overload.signature.parameterTypes; if (overload.is(CommonFlags.Static)) { @@ -525,7 +525,7 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; var classReference = typeArgument.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + let overload = classReference.lookupOverload(OperatorKind.IndexedGet); if (overload) return overload.signature.returnType; } if (reportMode == ReportMode.Report) { @@ -1376,7 +1376,7 @@ export class Resolver extends DiagnosticEmitter { assert(parent.kind == ElementKind.Class); let classInstance = parent; let elementExpression = assert(this.currentElementExpression); - let indexedGet = classInstance.lookupOverload(OperatorKind.INDEXED_GET); + let indexedGet = classInstance.lookupOverload(OperatorKind.IndexedGet); if (!indexedGet) { if (reportMode == ReportMode.Report) { this.error( @@ -1849,7 +1849,7 @@ export class Resolver extends DiagnosticEmitter { if (!type) return null; let classReference = type.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.NOT); + let overload = classReference.lookupOverload(OperatorKind.Not); if (overload) return overload.signature.returnType; } return Type.bool; // incl. references @@ -1859,7 +1859,7 @@ export class Resolver extends DiagnosticEmitter { if (!type) return null; let classReference = type.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.BITWISE_NOT); + let overload = classReference.lookupOverload(OperatorKind.BitwiseNot); if (overload) return overload.signature.returnType; } if (!type.isNumericValue) { @@ -3431,7 +3431,7 @@ export class Resolver extends DiagnosticEmitter { for (let _keys = Map_keys(overloadPrototypes), i = 0, k = _keys.length; i < k; ++i) { let overloadKind = unchecked(_keys[i]); let overloadPrototype = assert(overloadPrototypes.get(overloadKind)); - assert(overloadKind != OperatorKind.INVALID); + assert(overloadKind != OperatorKind.Invalid); if (overloadPrototype.is(CommonFlags.Generic)) { // Already errored during initialization: AS212: Decorator '@operator' is not valid here continue; @@ -3461,10 +3461,10 @@ export class Resolver extends DiagnosticEmitter { // static overload works like any other overload. if (operatorInstance.is(CommonFlags.Instance)) { switch (overloadKind) { - case OperatorKind.PREFIX_INC: - case OperatorKind.PREFIX_DEC: - case OperatorKind.POSTFIX_INC: - case OperatorKind.POSTFIX_DEC: { + case OperatorKind.PrefixInc: + case OperatorKind.PrefixDec: + case OperatorKind.PostfixInc: + case OperatorKind.PostfixDec: { let returnType = operatorInstance.signature.returnType; if (!returnType.isAssignableTo(instance.type)) { if (reportMode == ReportMode.Report) { @@ -3479,10 +3479,10 @@ export class Resolver extends DiagnosticEmitter { } if (!overloads.has(overloadKind)) { overloads.set(overloadKind, operatorInstance); - if (overloadKind == OperatorKind.INDEXED_GET || overloadKind == OperatorKind.INDEXED_SET) { + if (overloadKind == OperatorKind.IndexedGet || overloadKind == OperatorKind.IndexedSet) { let index = instance.indexSignature; if (!index) instance.indexSignature = index = new IndexSignature(instance); - if (overloadKind == OperatorKind.INDEXED_GET) { + if (overloadKind == OperatorKind.IndexedGet) { index.setType(operatorInstance.signature.returnType); } } diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 729b918d84..3dd83a924d 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -176,9 +176,9 @@ export const enum Token { } export const enum IdentifierHandling { - DEFAULT, - PREFER, - ALWAYS + Default, + Prefer, + Always } export function tokenFromKeyword(text: string): Token { @@ -502,7 +502,7 @@ export class Tokenizer extends DiagnosticEmitter { this.end = end; } - next(identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT): Token { + next(identifierHandling: IdentifierHandling = IdentifierHandling.Default): Token { this.nextToken = -1; var token: Token; do token = this.unsafeNext(identifierHandling); @@ -512,7 +512,7 @@ export class Tokenizer extends DiagnosticEmitter { } private unsafeNext( - identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT, + identifierHandling: IdentifierHandling = IdentifierHandling.Default, maxTokenLength: i32 = i32.MAX_VALUE ): Token { var text = this.source.text; @@ -688,13 +688,13 @@ export class Tokenizer extends DiagnosticEmitter { if (maxTokenLength > 1 && pos < end) { let chr = text.charCodeAt(pos); if (chr == CharCode.Slash) { // single-line - let commentKind = CommentKind.LINE; + let commentKind = CommentKind.Line; if ( pos + 1 < end && text.charCodeAt(pos + 1) == CharCode.Slash ) { ++pos; - commentKind = CommentKind.TRIPLE; + commentKind = CommentKind.Triple; } while (++pos < end) { if (text.charCodeAt(pos) == CharCode.LineFeed) { @@ -732,7 +732,7 @@ export class Tokenizer extends DiagnosticEmitter { ); } else if (this.onComment) { this.onComment( - CommentKind.BLOCK, + CommentKind.Block, text.substring(commentStartPos, pos), this.range(commentStartPos, pos) ); @@ -919,12 +919,12 @@ export class Tokenizer extends DiagnosticEmitter { ++pos < end && isIdentifierPart(c = text.charCodeAt(pos)) ) { /* nop */ } - if (identifierHandling != IdentifierHandling.ALWAYS) { + if (identifierHandling != IdentifierHandling.Always) { let maybeKeywordToken = tokenFromKeyword(text.substring(posBefore, pos)); if ( maybeKeywordToken != Token.Invalid && !( - identifierHandling == IdentifierHandling.PREFER && + identifierHandling == IdentifierHandling.Prefer && tokenIsAlsoIdentifier(maybeKeywordToken) ) ) { @@ -958,7 +958,7 @@ export class Tokenizer extends DiagnosticEmitter { peek( checkOnNewLine: bool = false, - identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT, + identifierHandling: IdentifierHandling = IdentifierHandling.Default, maxCompoundLength: i32 = i32.MAX_VALUE ): Token { var text = this.source.text; @@ -987,11 +987,11 @@ export class Tokenizer extends DiagnosticEmitter { return this.nextToken; } - skipIdentifier(identifierHandling: IdentifierHandling = IdentifierHandling.PREFER): bool { + skipIdentifier(identifierHandling: IdentifierHandling = IdentifierHandling.Prefer): bool { return this.skip(Token.Identifier, identifierHandling); } - skip(token: Token, identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT): bool { + skip(token: Token, identifierHandling: IdentifierHandling = IdentifierHandling.Default): bool { var posBefore = this.pos; var tokenBefore = this.token; var tokenPosBefore = this.tokenPos; From d0572d4234e533cf72d7d740c5609933c9596130 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 24 Sep 2022 16:30:25 +0300 Subject: [PATCH 12/22] update --- package-lock.json | 1 + src/builtins.ts | 21 ++++++------ src/compiler.ts | 50 ++++++++++++++--------------- src/index-wasm.ts | 4 +-- src/module.ts | 3 +- src/program.ts | 4 +-- src/types.ts | 58 +++++++++++++++++----------------- std/assembly/shared/feature.ts | 12 +++---- 8 files changed, 76 insertions(+), 77 deletions(-) diff --git a/package-lock.json b/package-lock.json index f5d48f1b7b..3af326762c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "assemblyscript", "version": "0.0.0", "license": "Apache-2.0", "dependencies": { diff --git a/src/builtins.ts b/src/builtins.ts index 70c6621315..b0c02e976d 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -3492,12 +3492,11 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Anyref: case TypeKind.Eqref: case TypeKind.Dataref: - case TypeKind.I31REF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.I31ref: return module.if(module.ref_is(RefIsOp.Null, arg0), abort); - + case TypeKind.I31ref: + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: return module.if(module.ref_is(RefIsOp.Null, arg0), abort); } } else { compiler.currentType = type.nonNullableType; @@ -3578,11 +3577,11 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Anyref: case TypeKind.Eqref: case TypeKind.Dataref: - case TypeKind.I31REF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.I31ref: + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: { let temp = flow.getTempLocal(type); let ret = module.if( module.ref_is(RefIsOp.Null, diff --git a/src/compiler.ts b/src/compiler.ts index 6e7cd1e444..56c3610e92 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -474,7 +474,7 @@ export class Compiler extends DiagnosticEmitter { if (options.hasFeature(Feature.Memory64)) featureFlags |= FeatureFlags.Memory64; if (options.hasFeature(Feature.RelaxedSimd)) featureFlags |= FeatureFlags.RelaxedSimd; if (options.hasFeature(Feature.ExtendedConst)) featureFlags |= FeatureFlags.ExtendedConst; - if (options.hasFeature(Feature.STRINGREF)) featureFlags |= FeatureFlags.Stringref; + if (options.hasFeature(Feature.Stringref)) featureFlags |= FeatureFlags.Stringref; module.setFeatures(featureFlags); // set up the main start function @@ -4875,10 +4875,10 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Eqref: case TypeKind.I31ref: case TypeKind.Dataref: return module.ref_eq(leftExpr, rightExpr); - case TypeKind.STRINGREF: return module.string_eq(leftExpr, rightExpr); - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: + case TypeKind.Stringref: return module.string_eq(leftExpr, rightExpr); + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: case TypeKind.Funcref: case TypeKind.Externref: case TypeKind.Anyref: { @@ -4928,14 +4928,14 @@ export class Compiler extends DiagnosticEmitter { module.ref_eq(leftExpr, rightExpr) ); } - case TypeKind.STRINGREF: { + case TypeKind.Stringref: { return module.unary(UnaryOp.EqzI32, module.string_eq(leftExpr, rightExpr) ); } - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: case TypeKind.Funcref: case TypeKind.Externref: case TypeKind.Anyref: { @@ -9856,12 +9856,12 @@ export class Compiler extends DiagnosticEmitter { return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode) && this.checkFeatureEnabled(Feature.GC, reportNode); } - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { - return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode) - && this.checkFeatureEnabled(Feature.STRINGREF, reportNode); + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: { + return this.checkFeatureEnabled(Feature.ReferenceTypes, reportNode) + && this.checkFeatureEnabled(Feature.Stringref, reportNode); } } let classReference = type.getClass(); @@ -9968,11 +9968,11 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Externref: case TypeKind.Anyref: case TypeKind.Eqref: - case TypeKind.DATAREF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: return module.ref_null(type.toRef()); + case TypeKind.Dataref: + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: return module.ref_null(type.toRef()); case TypeKind.I31ref: return module.i31_new(module.i32(0)); } } @@ -10121,11 +10121,11 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Anyref: case TypeKind.Eqref: case TypeKind.I31ref: - case TypeKind.DATAREF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.Dataref: + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: { // Needs to be true (i.e. not zero) when the ref is _not_ null, // which means `ref.is_null` returns false (i.e. zero). return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr)); diff --git a/src/index-wasm.ts b/src/index-wasm.ts index 005556b95a..1dd14a229a 100644 --- a/src/index-wasm.ts +++ b/src/index-wasm.ts @@ -192,9 +192,9 @@ export const FEATURE_MEMORY64 = Feature.Memory64; /** Relaxed SIMD. */ export const FEATURE_RELAXED_SIMD = Feature.RelaxedSimd; /** Extended const expressions. */ -export const FEATURE_EXTENDED_CONST = Feature.EXTENDED_CONST; +export const FEATURE_EXTENDED_CONST = Feature.ExtendedConst; /** String references. */ -export const FEATURE_STRINGREF = Feature.STRINGREF; +export const FEATURE_STRINGREF = Feature.Stringref; /** Enables a specific feature. */ export function enableFeature(options: Options, feature: Feature): void { diff --git a/src/module.ts b/src/module.ts index 1d3d7deee7..ad84dcd2f4 100644 --- a/src/module.ts +++ b/src/module.ts @@ -148,8 +148,7 @@ export const enum FeatureFlags { MultiValue = 512 /* _BinaryenFeatureMultivalue */, GC = 1024 /* _BinaryenFeatureGC */, Memory64 = 2048 /* _BinaryenFeatureMemory64 */, - // GCNNLocals is for off-spec experimentation - RelaxedSIMD = 8192 /* _BinaryenFeatureRelaxedSIMD */, + RelaxedSimd = 8192 /* _BinaryenFeatureRelaxedSIMD */, ExtendedConst = 16384 /* _BinaryenFeatureExtendedConst */, Stringref = 32768 /* _BinaryenFeatureStrings */, MultiMemory = 65536 /* _BinaryenFeatureMultiMemories */, diff --git a/src/program.ts b/src/program.ts index 2e9912af83..1c77eb12ac 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1074,9 +1074,9 @@ export class Program extends DiagnosticEmitter { this.registerConstantInteger(CommonNames.ASC_FEATURE_RELAXED_SIMD, Type.bool, i64_new(options.hasFeature(Feature.RelaxedSimd) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_EXTENDED_CONST, Type.bool, - i64_new(options.hasFeature(Feature.EXTENDED_CONST) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.ExtendedConst) ? 1 : 0, 0)); this.registerConstantInteger(CommonNames.ASC_FEATURE_STRINGREF, Type.bool, - i64_new(options.hasFeature(Feature.STRINGREF) ? 1 : 0, 0)); + i64_new(options.hasFeature(Feature.Stringref) ? 1 : 0, 0)); // remember deferred elements var queuedImports = new Array(); diff --git a/src/types.ts b/src/types.ts index adf67dd46d..257ef6e9a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -70,15 +70,15 @@ export const enum TypeKind { /** 31-bit integer reference. */ I31ref, /** Data reference. */ - DATAREF, + Dataref, /** String reference. */ - STRINGREF, + Stringref, /** WTF8 string view. */ - STRINGVIEW_WTF8, + StringviewWTF8, /** WTF16 string view. */ - STRINGVIEW_WTF16, + StringviewWTF16, /** String iterator. */ - STRINGVIEW_ITER, + StringviewIter, // other @@ -548,10 +548,10 @@ export class Type { case TypeKind.Eqref: return "eqref"; case TypeKind.I31ref: return "i31ref"; case TypeKind.Dataref: return "dataref"; - case TypeKind.STRINGREF: return "stringref"; - case TypeKind.STRINGVIEW_WTF8: return "stringview_wtf8"; - case TypeKind.STRINGVIEW_WTF16: return "stringview_wtf16"; - case TypeKind.STRINGVIEW_ITER: return "stringview_iter"; + case TypeKind.Stringref: return "stringref"; + case TypeKind.StringviewWTF8: return "stringview_wtf8"; + case TypeKind.StringviewWTF16: return "stringview_wtf16"; + case TypeKind.StringviewIter: return "stringview_iter"; default: assert(false); case TypeKind.Void: return "void"; } @@ -584,10 +584,10 @@ export class Type { case TypeKind.Eqref: return TypeRef.Eqref; case TypeKind.I31ref: return TypeRef.I31ref; case TypeKind.Dataref: return TypeRef.Dataref; - case TypeKind.STRINGREF: return TypeRef.Stringref; - case TypeKind.STRINGVIEW_WTF8: return TypeRef.StringviewWTF8; - case TypeKind.STRINGVIEW_WTF16: return TypeRef.StringviewWTF16; - case TypeKind.STRINGVIEW_ITER: return TypeRef.StringviewIter; + case TypeKind.Stringref: return TypeRef.Stringref; + case TypeKind.StringviewWTF8: return TypeRef.StringviewWTF8; + case TypeKind.StringviewWTF16: return TypeRef.StringviewWTF16; + case TypeKind.StringviewIter: return TypeRef.StringviewIter; case TypeKind.Void: return TypeRef.None; } } @@ -762,31 +762,31 @@ export class Type { ); /** String reference. */ - static readonly stringref: Type = new Type(TypeKind.STRINGREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly stringref: Type = new Type(TypeKind.Stringref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** WTF8 string view. */ - static readonly stringview_wtf8: Type = new Type(TypeKind.STRINGVIEW_WTF8, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly stringview_wtf8: Type = new Type(TypeKind.StringviewWTF8, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** WTF16 string view. */ - static readonly stringview_wtf16: Type = new Type(TypeKind.STRINGVIEW_WTF16, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly stringview_wtf16: Type = new Type(TypeKind.StringviewWTF16, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** String iterator. */ - static readonly stringview_iter: Type = new Type(TypeKind.STRINGVIEW_ITER, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly stringview_iter: Type = new Type(TypeKind.StringviewIter, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** No return type. */ diff --git a/std/assembly/shared/feature.ts b/std/assembly/shared/feature.ts index 26751a935d..19027742ed 100644 --- a/std/assembly/shared/feature.ts +++ b/std/assembly/shared/feature.ts @@ -29,11 +29,11 @@ export const enum Feature { /** Memory64. */ Memory64 = 1 << 11, // see: https://github.com/WebAssembly/memory64 /** Relaxed SIMD. */ - RELAXED_SIMD = 1 << 12, // see: https://github.com/WebAssembly/relaxed-simd + RelaxedSimd = 1 << 12, // see: https://github.com/WebAssembly/relaxed-simd /** Extended const expressions. */ - EXTENDED_CONST = 1 << 13, // see: https://github.com/WebAssembly/extended-const + ExtendedConst = 1 << 13, // see: https://github.com/WebAssembly/extended-const /** Reference typed strings. */ - STRINGREF = 1 << 14, // see: https://github.com/WebAssembly/stringref + Stringref = 1 << 14, // see: https://github.com/WebAssembly/stringref } /** Gets the name of the specified feature one would specify on the command line. */ @@ -51,9 +51,9 @@ export function featureToString(feature: Feature): string { case Feature.MultiValue: return "multi-value"; case Feature.GC: return "gc"; case Feature.Memory64: return "memory64"; - case Feature.RELAXED_SIMD: return "relaxed-simd"; - case Feature.EXTENDED_CONST: return "extended-const"; - case Feature.STRINGREF: return "stringref"; + case Feature.RelaxedSimd: return "relaxed-simd"; + case Feature.ExtendedConst: return "extended-const"; + case Feature.Stringref: return "stringref"; } assert(false); return ""; From 30d81d0b2bc885d91d9f6664f740abb668170fcf Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 25 Sep 2022 21:29:07 +0300 Subject: [PATCH 13/22] update --- src/program.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/program.ts b/src/program.ts index efecdeee9d..72d4473253 100644 --- a/src/program.ts +++ b/src/program.ts @@ -819,7 +819,7 @@ export class Program extends DiagnosticEmitter { const instancesByName = this.instancesByName; if (instancesByName.has(modifiedFunctionName)) { const element = assert(instancesByName.get(modifiedFunctionName)); - if (element.kind == ElementKind.FUNCTION) { + if (element.kind == ElementKind.Function) { return element; } } @@ -1376,7 +1376,7 @@ export class Program extends DiagnosticEmitter { for (let j = 0, k = members.length; j < k; j++) { let member = members[j]; let declaration = member.declaration; - if (declaration.is(CommonFlags.OVERRIDE)) { + if (declaration.is(CommonFlags.Override)) { let basePrototype = prototype.basePrototype; let hasOverride = false; while (basePrototype) { From a48992dfe1bdc8fda31460abdd33d2bdd34c4379 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 21 Oct 2022 16:59:24 +0300 Subject: [PATCH 14/22] update --- src/compiler.ts | 8 ++++---- src/types.ts | 42 +++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 85c0e539c4..16bb58c4b1 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6120,7 +6120,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - if (local.is(CommonFlags.INLINED)) { + if (local.is(CommonFlags.Inlined)) { let inlinedValue = local.constantIntegerValue; if (this.options.isWasm64) { functionArg = module.i64(i64_low(inlinedValue), i64_high(inlinedValue)); @@ -9982,12 +9982,12 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.Stringref: case TypeKind.StringviewWTF8: case TypeKind.StringviewWTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.StringviewIter: { // TODO: what if not nullable? return module.ref_null(type.toRef()); } - case TypeKind.I31REF: { - if (type.is(TypeFlags.NULLABLE)) return module.ref_null(type.toRef()); + case TypeKind.I31ref: { + if (type.is(TypeFlags.Nullable)) return module.ref_null(type.toRef()); return module.i31_new(module.i32(0)); } } diff --git a/src/types.ts b/src/types.ts index 0556063dcd..b77dd9ad0b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -601,37 +601,37 @@ export class Type { case TypeKind.F32: return TypeRef.F32; case TypeKind.F64: return TypeRef.F64; case TypeKind.V128: return TypeRef.V128; - case TypeKind.FUNCREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, this.is(TypeFlags.NULLABLE)); + case TypeKind.Funcref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, this.is(TypeFlags.Nullable)); } - case TypeKind.EXTERNREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Ext, this.is(TypeFlags.NULLABLE)); + case TypeKind.Externref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Ext, this.is(TypeFlags.Nullable)); } - case TypeKind.ANYREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, this.is(TypeFlags.NULLABLE)); + case TypeKind.Anyref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, this.is(TypeFlags.Nullable)); } - case TypeKind.EQREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Eq, this.is(TypeFlags.NULLABLE)); + case TypeKind.Eqref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Eq, this.is(TypeFlags.Nullable)); } - case TypeKind.I31REF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, this.is(TypeFlags.NULLABLE)); + case TypeKind.I31ref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, this.is(TypeFlags.Nullable)); } - case TypeKind.DATAREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, this.is(TypeFlags.NULLABLE)); + case TypeKind.Dataref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, this.is(TypeFlags.Nullable)); } - case TypeKind.STRINGREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.String, this.is(TypeFlags.NULLABLE)); + case TypeKind.Stringref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.String, this.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_WTF8: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF8, this.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewWTF8: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF8, this.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_WTF16: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF16, this.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewWTF16: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF16, this.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_ITER: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewIter, this.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewIter: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewIter, this.is(TypeFlags.Nullable)); } - case TypeKind.VOID: return TypeRef.None; + case TypeKind.Void: return TypeRef.None; } } From 6e5d07f2e27d106f460b814411892d47b74a619a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 21 Oct 2022 21:46:00 +0300 Subject: [PATCH 15/22] fixes --- src/builtins.ts | 4 +-- src/module.ts | 70 ++++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index e755dcc247..d56e9fbdcb 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -3492,7 +3492,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Anyref: case TypeKind.Eqref: case TypeKind.Dataref: - case TypeKind.ARRAYREF: + case TypeKind.Arrayref: case TypeKind.I31ref: case TypeKind.Stringref: case TypeKind.StringviewWTF8: @@ -3578,7 +3578,7 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { case TypeKind.Anyref: case TypeKind.Eqref: case TypeKind.Dataref: - case TypeKind.ARRAYREF: + case TypeKind.Arrayref: case TypeKind.I31ref: case TypeKind.Stringref: case TypeKind.StringviewWTF8: diff --git a/src/module.ts b/src/module.ts index 8e614796d0..c86857a8d2 100644 --- a/src/module.ts +++ b/src/module.ts @@ -3659,7 +3659,7 @@ export function ensureType(type: Type): TypeRef { if (typeRef = type.ref) { return binaryen._BinaryenTypeFromHeapType( binaryen._BinaryenTypeGetHeapType(typeRef), - originalType.is(TypeFlags.NULLABLE) // apply nullability + originalType.is(TypeFlags.Nullable) // apply nullability ); } @@ -3684,7 +3684,7 @@ export function ensureType(type: Type): TypeRef { // Assign all the built types to their respective non-nullable type for (let _keys = Map_keys(seen), i = 0, k = _keys.length; i < k; ++i) { let seenType = _keys[i]; - assert(!seenType.is(TypeFlags.NULLABLE)); // non-nullable only + assert(!seenType.is(TypeFlags.Nullable)); // non-nullable only let heapType = binaryen.__i32_load(out + 4 * i); let fullType = binaryen._BinaryenTypeFromHeapType(heapType, false); assert(!seenType.ref); @@ -3702,14 +3702,14 @@ export function ensureType(type: Type): TypeRef { typeRef = assert(type.ref); return binaryen._BinaryenTypeFromHeapType( binaryen._BinaryenTypeGetHeapType(typeRef), - originalType.is(TypeFlags.NULLABLE) // apply nullability + originalType.is(TypeFlags.Nullable) // apply nullability ); } /** Obtains the basic type of the given type, if any. */ function tryEnsureBasicType(type: Type): TypeRef { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.U8: case TypeKind.I16: @@ -3718,48 +3718,48 @@ function tryEnsureBasicType(type: Type): TypeRef { case TypeKind.U32: return TypeRef.I32; case TypeKind.I64: case TypeKind.U64: return TypeRef.I64; - case TypeKind.ISIZE: - case TypeKind.USIZE: { + case TypeKind.Isize: + case TypeKind.Usize: { if (type.isInternalReference) break; // non-basic return type.size == 64 ? TypeRef.I64 : TypeRef.I32; } case TypeKind.F32: return TypeRef.F32; case TypeKind.F64: return TypeRef.F64; case TypeKind.V128: return TypeRef.V128; - case TypeKind.FUNCREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, type.is(TypeFlags.NULLABLE)); + case TypeKind.Funcref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, type.is(TypeFlags.Nullable)); } - case TypeKind.EXTERNREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Extern, type.is(TypeFlags.NULLABLE)); + case TypeKind.Externref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Extern, type.is(TypeFlags.Nullable)); } - case TypeKind.ANYREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, type.is(TypeFlags.NULLABLE)); + case TypeKind.Anyref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, type.is(TypeFlags.Nullable)); } - case TypeKind.EQREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Eq, type.is(TypeFlags.NULLABLE)); + case TypeKind.Eqref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Eq, type.is(TypeFlags.Nullable)); } - case TypeKind.I31REF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, type.is(TypeFlags.NULLABLE)); + case TypeKind.I31ref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.I31, type.is(TypeFlags.Nullable)); } - case TypeKind.DATAREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, type.is(TypeFlags.NULLABLE)); + case TypeKind.Dataref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Data, type.is(TypeFlags.Nullable)); } - case TypeKind.ARRAYREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Array, type.is(TypeFlags.NULLABLE)); + case TypeKind.Arrayref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Array, type.is(TypeFlags.Nullable)); } - case TypeKind.STRINGREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.String, type.is(TypeFlags.NULLABLE)); + case TypeKind.Stringref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.String, type.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_WTF8: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF8, type.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewWTF8: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF8, type.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_WTF16: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF16, type.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewWTF16: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewWTF16, type.is(TypeFlags.Nullable)); } - case TypeKind.STRINGVIEW_ITER: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewIter, type.is(TypeFlags.NULLABLE)); + case TypeKind.StringviewIter: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.StringviewIter, type.is(TypeFlags.Nullable)); } - case TypeKind.VOID: assert(false); // invalid here + case TypeKind.Void: assert(false); // invalid here } return 0; // non-basic } @@ -3767,7 +3767,7 @@ function tryEnsureBasicType(type: Type): TypeRef { /** Determines the packed GC type of the given type, if applicable. */ function determinePackedType(type: Type): PackedType { switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.U8: return PackedType.I8; case TypeKind.I16: @@ -3783,7 +3783,7 @@ function prepareType(builder: binaryen.TypeBuilderRef, seen: Mapmember; let fieldType = field.type; if (DEBUG_TYPEBUILDER) { console.log(` field ${fieldType.toString()}`); } - if (fieldType.is(TypeFlags.NULLABLE)) { + if (fieldType.is(TypeFlags.Nullable)) { fieldTypes.push( binaryen._TypeBuilderGetTempRefType( builder, @@ -3889,7 +3889,7 @@ function prepareType(builder: binaryen.TypeBuilderRef, seen: Map Date: Sun, 23 Oct 2022 16:49:43 +0300 Subject: [PATCH 16/22] postfix --- src/tokenizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 23f2588683..da439fc146 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -993,7 +993,7 @@ export class Tokenizer extends DiagnosticEmitter { return this.skip(Token.Identifier, identifierHandling); } - skip(token: Token, identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT): bool { + skip(token: Token, identifierHandling: IdentifierHandling = IdentifierHandling.Default): bool { let posBefore = this.pos; let tokenBefore = this.token; let tokenPosBefore = this.tokenPos; From b0cc5a4010953c3f2a4474d2ebdcfe7aebdb5a06 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 17:28:21 +0300 Subject: [PATCH 17/22] use insanceof and uppercase SIMD ppstfix --- src/compiler.ts | 4 ++-- src/module.ts | 4 ++-- src/parser.ts | 4 ++-- src/tokenizer.ts | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 75c5b65e8c..0489c68106 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -463,7 +463,7 @@ export class Compiler extends DiagnosticEmitter { if (options.hasFeature(Feature.MutableGlobals)) featureFlags |= FeatureFlags.MutableGlobals; if (options.hasFeature(Feature.NontrappingF2I)) featureFlags |= FeatureFlags.TruncSat; if (options.hasFeature(Feature.BulkMemory)) featureFlags |= FeatureFlags.BulkMemory; - if (options.hasFeature(Feature.Simd)) featureFlags |= FeatureFlags.Simd; + if (options.hasFeature(Feature.Simd)) featureFlags |= FeatureFlags.SIMD; if (options.hasFeature(Feature.Threads)) featureFlags |= FeatureFlags.Atomics; if (options.hasFeature(Feature.ExceptionHandling)) featureFlags |= FeatureFlags.ExceptionHandling; if (options.hasFeature(Feature.TailCalls)) featureFlags |= FeatureFlags.TailCall; @@ -471,7 +471,7 @@ export class Compiler extends DiagnosticEmitter { if (options.hasFeature(Feature.MultiValue)) featureFlags |= FeatureFlags.MultiValue; if (options.hasFeature(Feature.GC)) featureFlags |= FeatureFlags.GC; if (options.hasFeature(Feature.Memory64)) featureFlags |= FeatureFlags.Memory64; - if (options.hasFeature(Feature.RelaxedSimd)) featureFlags |= FeatureFlags.RelaxedSimd; + if (options.hasFeature(Feature.RelaxedSimd)) featureFlags |= FeatureFlags.RelaxedSIMD; if (options.hasFeature(Feature.ExtendedConst)) featureFlags |= FeatureFlags.ExtendedConst; if (options.hasFeature(Feature.Stringref)) featureFlags |= FeatureFlags.Stringref; module.setFeatures(featureFlags); diff --git a/src/module.ts b/src/module.ts index e464f85b10..a7c88871b6 100644 --- a/src/module.ts +++ b/src/module.ts @@ -172,7 +172,7 @@ export const enum FeatureFlags { Atomics = 1 /* _BinaryenFeatureAtomics */, MutableGlobals = 2 /* _BinaryenFeatureMutableGlobals */, TruncSat = 4 /* _BinaryenFeatureNontrappingFPToInt */, - Simd = 8 /* _BinaryenFeatureSIMD128 */, + SIMD = 8 /* _BinaryenFeatureSIMD128 */, BulkMemory = 16 /* _BinaryenFeatureBulkMemory */, SignExt = 32 /* _BinaryenFeatureSignExt */, ExceptionHandling = 64 /* _BinaryenFeatureExceptionHandling */, @@ -181,7 +181,7 @@ export const enum FeatureFlags { MultiValue = 512 /* _BinaryenFeatureMultivalue */, GC = 1024 /* _BinaryenFeatureGC */, Memory64 = 2048 /* _BinaryenFeatureMemory64 */, - RelaxedSimd = 8192 /* _BinaryenFeatureRelaxedSIMD */, + RelaxedSIMD = 8192 /* _BinaryenFeatureRelaxedSIMD */, ExtendedConst = 16384 /* _BinaryenFeatureExtendedConst */, Stringref = 32768 /* _BinaryenFeatureStrings */, MultiMemory = 65536 /* _BinaryenFeatureMultiMemories */, diff --git a/src/parser.ts b/src/parser.ts index 3584a2f620..a016d7dae8 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4140,7 +4140,7 @@ export class Parser extends DiagnosticEmitter { break; } // InstanceOfExpression - case Token.InstanceOf: { + case Token.Instanceof: { let isType = this.parseType(tn); // reports if (!isType) return null; expr = Node.createInstanceOfExpression( @@ -4544,7 +4544,7 @@ function determinePrecedence(kind: Token): Precedence { case Token.ExclamationEqualsEquals: return Precedence.Equality; case Token.As: case Token.In: - case Token.InstanceOf: + case Token.Instanceof: case Token.LessThan: case Token.GreaterThan: case Token.LessThanEquals: diff --git a/src/tokenizer.ts b/src/tokenizer.ts index da439fc146..533c6ced40 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -73,7 +73,7 @@ export const enum Token { Implements, // ES2017 non-lexical Import, // ES2017 In, // ES2017 - InstanceOf, // ES2017 + Instanceof, // ES2017 Interface, // ES2017 non-lexical Is, KeyOf, @@ -265,7 +265,7 @@ export function tokenFromKeyword(text: string): Token { break; } case CharCode.t: { - if (text == "instanceof") return Token.InstanceOf; + if (text == "instanceof") return Token.Instanceof; break; } case CharCode.e: { @@ -363,7 +363,7 @@ export function tokenIsAlsoIdentifier(token: Token): bool { case Token.From: case Token.For: case Token.Get: - case Token.InstanceOf: + case Token.Instanceof: case Token.Is: case Token.KeyOf: case Token.Module: @@ -393,7 +393,7 @@ export function operatorTokenToString(token: Token): string { switch (token) { case Token.Delete: return "delete"; case Token.In: return "in"; - case Token.InstanceOf: return "instanceof"; + case Token.Instanceof: return "instanceof"; case Token.New: return "new"; case Token.TypeOf: return "typeof"; case Token.Void: return "void"; From a10ef78a827051c7bdfe784dfedb9856eae1f399 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 17:47:14 +0300 Subject: [PATCH 18/22] revert instnaceOf token and use Underscores for compaund token names --- src/compiler.ts | 16 +++++++------- src/parser.ts | 36 +++++++++++++++---------------- src/program.ts | 16 +++++++------- src/resolver.ts | 16 +++++++------- src/tokenizer.ts | 56 ++++++++++++++++++++++++------------------------ 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 0489c68106..65cb0d2db4 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3866,7 +3866,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.LessThanEquals: { + case Token.LessThan_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3901,7 +3901,7 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.GreaterThanEquals: { + case Token.GreaterThan_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4313,8 +4313,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeRem(leftExpr, rightExpr, commonType, expression); break; } - case Token.LessThanLessThanEquals: compound = true; - case Token.LessThanLessThan: { + case Token.LessThan_LessThan_Equals: compound = true; + case Token.LessThan_LessThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4340,8 +4340,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShl(leftExpr, rightExpr, rightType); break; } - case Token.GreaterThanGreaterThanEquals: compound = true; - case Token.GreaterThanGreaterThan: { + case Token.GreaterThan_GreaterThan_Equals: compound = true; + case Token.GreaterThan_GreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4368,8 +4368,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShr(leftExpr, rightExpr, rightType); break; } - case Token.GreaterThanGreaterThanGreaterThanEquals: compound = true; - case Token.GreaterThanGreaterThanGreaterThan: { + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: compound = true; + case Token.GreaterThan_GreaterThan_GreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; diff --git a/src/parser.ts b/src/parser.ts index a016d7dae8..ab9e7a4e86 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4140,7 +4140,7 @@ export class Parser extends DiagnosticEmitter { break; } // InstanceOfExpression - case Token.Instanceof: { + case Token.InstanceOf: { let isType = this.parseType(tn); // reports if (!isType) return null; expr = Node.createInstanceOfExpression( @@ -4263,9 +4263,9 @@ export class Parser extends DiagnosticEmitter { case Token.AsteriskEquals: case Token.SlashEquals: case Token.PercentEquals: - case Token.LessThanLessThanEquals: - case Token.GreaterThanGreaterThanEquals: - case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.LessThan_LessThan_Equals: + case Token.GreaterThan_GreaterThan_Equals: + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: case Token.AmpersandEquals: case Token.CaretEquals: case Token.BarEquals: @@ -4278,8 +4278,8 @@ export class Parser extends DiagnosticEmitter { // BinaryExpression case Token.LessThan: case Token.GreaterThan: - case Token.LessThanEquals: - case Token.GreaterThanEquals: + case Token.LessThan_Equals: + case Token.GreaterThan_Equals: case Token.EqualsEquals: case Token.EqualsEqualsEquals: case Token.ExclamationEqualsEquals: @@ -4289,9 +4289,9 @@ export class Parser extends DiagnosticEmitter { case Token.Asterisk: case Token.Slash: case Token.Percent: - case Token.LessThanLessThan: - case Token.GreaterThanGreaterThan: - case Token.GreaterThanGreaterThanGreaterThan: + case Token.LessThan_LessThan: + case Token.GreaterThan_GreaterThan: + case Token.GreaterThan_GreaterThan_GreaterThan: case Token.Ampersand: case Token.Bar: case Token.Caret: @@ -4526,9 +4526,9 @@ function determinePrecedence(kind: Token): Precedence { case Token.AsteriskEquals: case Token.SlashEquals: case Token.PercentEquals: - case Token.LessThanLessThanEquals: - case Token.GreaterThanGreaterThanEquals: - case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.LessThan_LessThan_Equals: + case Token.GreaterThan_GreaterThan_Equals: + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: case Token.AmpersandEquals: case Token.CaretEquals: case Token.BarEquals: return Precedence.Assignment; @@ -4544,14 +4544,14 @@ function determinePrecedence(kind: Token): Precedence { case Token.ExclamationEqualsEquals: return Precedence.Equality; case Token.As: case Token.In: - case Token.Instanceof: + case Token.InstanceOf: case Token.LessThan: case Token.GreaterThan: - case Token.LessThanEquals: - case Token.GreaterThanEquals: return Precedence.Relational; - case Token.LessThanLessThan: - case Token.GreaterThanGreaterThan: - case Token.GreaterThanGreaterThanGreaterThan: return Precedence.Shift; + case Token.LessThan_Equals: + case Token.GreaterThan_Equals: return Precedence.Relational; + case Token.LessThan_LessThan: + case Token.GreaterThan_GreaterThan: + case Token.GreaterThan_GreaterThan_GreaterThan: return Precedence.Shift; case Token.Plus: case Token.Minus: return Precedence.Additive; case Token.Asterisk: diff --git a/src/program.ts b/src/program.ts index 351bee35fa..a1e782dee4 100644 --- a/src/program.ts +++ b/src/program.ts @@ -380,18 +380,18 @@ export namespace OperatorKind { case Token.BarEquals: return OperatorKind.BitwiseOr; case Token.Caret: case Token.CaretEquals: return OperatorKind.BitwiseXor; - case Token.LessThanLessThan: - case Token.LessThanLessThanEquals: return OperatorKind.BitwiseShl; - case Token.GreaterThanGreaterThan: - case Token.GreaterThanGreaterThanEquals: return OperatorKind.BitwiseShr; - case Token.GreaterThanGreaterThanGreaterThan: - case Token.GreaterThanGreaterThanGreaterThanEquals: return OperatorKind.BitwiseShrU; + case Token.LessThan_LessThan: + case Token.LessThan_LessThan_Equals: return OperatorKind.BitwiseShl; + case Token.GreaterThan_GreaterThan: + case Token.GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShr; + case Token.GreaterThan_GreaterThan_GreaterThan: + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShrU; case Token.EqualsEquals: return OperatorKind.Eq; case Token.ExclamationEquals: return OperatorKind.Ne; case Token.GreaterThan: return OperatorKind.Gt; - case Token.GreaterThanEquals: return OperatorKind.Ge; + case Token.GreaterThan_Equals: return OperatorKind.Ge; case Token.LessThan: return OperatorKind.Lt; - case Token.LessThanEquals: return OperatorKind.Le; + case Token.LessThan_Equals: return OperatorKind.Le; } return OperatorKind.Invalid; } diff --git a/src/resolver.ts b/src/resolver.ts index 5c21baf66c..99b8387049 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2003,9 +2003,9 @@ export class Resolver extends DiagnosticEmitter { case Token.AsteriskAsteriskEquals: case Token.SlashEquals: case Token.PercentEquals: - case Token.LessThanLessThanEquals: - case Token.GreaterThanGreaterThanEquals: - case Token.GreaterThanGreaterThanGreaterThanEquals: + case Token.LessThan_LessThan_Equals: + case Token.GreaterThan_GreaterThan_Equals: + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: case Token.AmpersandEquals: case Token.BarEquals: case Token.CaretEquals: { @@ -2016,8 +2016,8 @@ export class Resolver extends DiagnosticEmitter { case Token.LessThan: case Token.GreaterThan: - case Token.LessThanEquals: - case Token.GreaterThanEquals: { + case Token.LessThan_Equals: + case Token.GreaterThan_Equals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2089,9 +2089,9 @@ export class Resolver extends DiagnosticEmitter { // shift: result is LHS (RHS is converted to LHS), preferring overloads - case Token.LessThanLessThan: - case Token.GreaterThanGreaterThan: - case Token.GreaterThanGreaterThanGreaterThan: { + case Token.LessThan_LessThan: + case Token.GreaterThan_GreaterThan: + case Token.GreaterThan_GreaterThan_GreaterThan: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 533c6ced40..17e0d57ea0 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -73,7 +73,7 @@ export const enum Token { Implements, // ES2017 non-lexical Import, // ES2017 In, // ES2017 - Instanceof, // ES2017 + InstanceOf, // ES2017 Interface, // ES2017 non-lexical Is, KeyOf, @@ -120,8 +120,8 @@ export const enum Token { Comma, LessThan, GreaterThan, - LessThanEquals, - GreaterThanEquals, + LessThan_Equals, + GreaterThan_Equals, EqualsEquals, ExclamationEquals, EqualsEqualsEquals, @@ -135,9 +135,9 @@ export const enum Token { Percent, PlusPlus, MinusMinus, - LessThanLessThan, - GreaterThanGreaterThan, - GreaterThanGreaterThanGreaterThan, + LessThan_LessThan, + GreaterThan_GreaterThan, + GreaterThan_GreaterThan_GreaterThan, Ampersand, Bar, Caret, @@ -154,9 +154,9 @@ export const enum Token { AsteriskAsteriskEquals, SlashEquals, PercentEquals, - LessThanLessThanEquals, - GreaterThanGreaterThanEquals, - GreaterThanGreaterThanGreaterThanEquals, + LessThan_LessThan_Equals, + GreaterThan_GreaterThan_Equals, + GreaterThan_GreaterThan_GreaterThan_Equals, AmpersandEquals, BarEquals, CaretEquals, @@ -265,7 +265,7 @@ export function tokenFromKeyword(text: string): Token { break; } case CharCode.t: { - if (text == "instanceof") return Token.Instanceof; + if (text == "instanceof") return Token.InstanceOf; break; } case CharCode.e: { @@ -363,7 +363,7 @@ export function tokenIsAlsoIdentifier(token: Token): bool { case Token.From: case Token.For: case Token.Get: - case Token.Instanceof: + case Token.InstanceOf: case Token.Is: case Token.KeyOf: case Token.Module: @@ -393,7 +393,7 @@ export function operatorTokenToString(token: Token): string { switch (token) { case Token.Delete: return "delete"; case Token.In: return "in"; - case Token.Instanceof: return "instanceof"; + case Token.InstanceOf: return "instanceof"; case Token.New: return "new"; case Token.TypeOf: return "typeof"; case Token.Void: return "void"; @@ -402,8 +402,8 @@ export function operatorTokenToString(token: Token): string { case Token.Comma: return ","; case Token.LessThan: return "<"; case Token.GreaterThan: return ">"; - case Token.LessThanEquals: return "<="; - case Token.GreaterThanEquals: return ">="; + case Token.LessThan_Equals: return "<="; + case Token.GreaterThan_Equals: return ">="; case Token.EqualsEquals: return "=="; case Token.ExclamationEquals: return "!="; case Token.EqualsEqualsEquals: return "==="; @@ -416,9 +416,9 @@ export function operatorTokenToString(token: Token): string { case Token.Percent: return "%"; case Token.PlusPlus: return "++"; case Token.MinusMinus: return "--"; - case Token.LessThanLessThan: return "<<"; - case Token.GreaterThanGreaterThan: return ">>"; - case Token.GreaterThanGreaterThanGreaterThan: return ">>>"; + case Token.LessThan_LessThan: return "<<"; + case Token.GreaterThan_GreaterThan: return ">>"; + case Token.GreaterThan_GreaterThan_GreaterThan: return ">>>"; case Token.Ampersand: return "&"; case Token.Bar: return "|"; case Token.Caret: return "^"; @@ -433,9 +433,9 @@ export function operatorTokenToString(token: Token): string { case Token.AsteriskAsteriskEquals: return "**="; case Token.SlashEquals: return "/="; case Token.PercentEquals: return "%="; - case Token.LessThanLessThanEquals: return "<<="; - case Token.GreaterThanGreaterThanEquals: return ">>="; - case Token.GreaterThanGreaterThanGreaterThanEquals: return ">>>="; + case Token.LessThan_LessThan_Equals: return "<<="; + case Token.GreaterThan_GreaterThan_Equals: return ">>="; + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return ">>>="; case Token.AmpersandEquals: return "&="; case Token.BarEquals: return "|="; case Token.CaretEquals: return "^="; @@ -783,14 +783,14 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.LessThanLessThanEquals; + return Token.LessThan_LessThan_Equals; } this.pos = pos; - return Token.LessThanLessThan; + return Token.LessThan_LessThan; } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.LessThanEquals; + return Token.LessThan_Equals; } } this.pos = pos; @@ -836,22 +836,22 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.GreaterThanGreaterThanGreaterThanEquals; + return Token.GreaterThan_GreaterThan_GreaterThan_Equals; } this.pos = pos; - return Token.GreaterThanGreaterThanGreaterThan; + return Token.GreaterThan_GreaterThan_GreaterThan; } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.GreaterThanGreaterThanEquals; + return Token.GreaterThan_GreaterThan_Equals; } } this.pos = pos; - return Token.GreaterThanGreaterThan; + return Token.GreaterThan_GreaterThan; } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.GreaterThanEquals; + return Token.GreaterThan_Equals; } } this.pos = pos; From 85aa694af3b2206addf434cbf8f589c2c9af1642 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 21:00:39 +0300 Subject: [PATCH 19/22] more underscores --- src/compiler.ts | 24 +++++++++--------- src/parser.ts | 56 +++++++++++++++++++++--------------------- src/program.ts | 16 ++++++------ src/resolver.ts | 24 +++++++++--------- src/tokenizer.ts | 64 ++++++++++++++++++++++++------------------------ 5 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 65cb0d2db4..3f71778a95 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3937,8 +3937,8 @@ export class Compiler extends DiagnosticEmitter { break; } - case Token.EqualsEqualsEquals: - case Token.EqualsEquals: { + case Token.Equals_Equals_Equals: + case Token.Equals_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -3989,8 +3989,8 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.ExclamationEqualsEquals: - case Token.ExclamationEquals: { + case Token.Exclamation_Equals_Equals: + case Token.Exclamation_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4178,8 +4178,8 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeMul(leftExpr, rightExpr, commonType); break; } - case Token.AsteriskAsteriskEquals: compound = true; - case Token.AsteriskAsterisk: { + case Token.Asterisk_Asterisk_Equals: compound = true; + case Token.Asterisk_Asterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4533,7 +4533,7 @@ export class Compiler extends DiagnosticEmitter { // logical (no overloading) - case Token.AmpersandAmpersand: { // left && right -> (t = left) ? right : t + case Token.Ampersand_Ampersand: { // left && right -> (t = left) ? right : t let flow = this.currentFlow; let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); @@ -9037,7 +9037,7 @@ export class Compiler extends DiagnosticEmitter { let expr: ExpressionRef; switch (expression.operator) { - case Token.PlusPlus: { + case Token.Plus_Plus: { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); @@ -9121,7 +9121,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MinusMinus: { + case Token.Minus_Minus: { // check operator overload let classReference = this.currentType.getClassOrWrapper(this.program); @@ -9357,7 +9357,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.PlusPlus: { + case Token.Plus_Plus: { compound = true; expr = this.compileExpression( expression.operand, @@ -9426,7 +9426,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MinusMinus: { + case Token.Minus_Minus: { compound = true; expr = this.compileExpression( expression.operand, @@ -9579,7 +9579,7 @@ export class Compiler extends DiagnosticEmitter { case Token.TypeOf: { return this.compileTypeof(expression, contextualType, constraints); } - case Token.DotDotDot: { + case Token.Dot_Dot_Dot: { this.error( DiagnosticCode.Not_implemented_0, expression.range, "Spread operator" diff --git a/src/parser.ts b/src/parser.ts index ab9e7a4e86..d2fec577ae 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -719,7 +719,7 @@ export class Parser extends DiagnosticEmitter { do { let paramStart = -1; let kind = ParameterKind.Default; - if (tn.skip(Token.DotDotDot)) { + if (tn.skip(Token.Dot_Dot_Dot)) { paramStart = tn.tokenPos; isSignature = true; tn.discard(state); @@ -823,7 +823,7 @@ export class Parser extends DiagnosticEmitter { } let returnType: TypeNode | null; - if (tn.skip(Token.EqualsGreaterThan)) { + if (tn.skip(Token.Equals_GreaterThan)) { if (!isSignature) { isSignature = true; tn.discard(state); @@ -1342,7 +1342,7 @@ export class Parser extends DiagnosticEmitter { } } } - if (tn.skip(Token.DotDotDot)) { + if (tn.skip(Token.Dot_Dot_Dot)) { if (accessFlags) { this.error( DiagnosticCode.A_parameter_property_cannot_be_declared_using_a_rest_parameter, @@ -1609,7 +1609,7 @@ export class Parser extends DiagnosticEmitter { } if (arrowKind) { - if (!tn.skip(Token.EqualsGreaterThan)) { + if (!tn.skip(Token.Equals_GreaterThan)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "=>" @@ -3676,7 +3676,7 @@ export class Parser extends DiagnosticEmitter { switch (token) { // TODO: SpreadExpression, YieldExpression - case Token.DotDotDot: + case Token.Dot_Dot_Dot: case Token.Yield: // fallthrough to unsupported UnaryPrefixExpression // UnaryPrefixExpression @@ -3691,8 +3691,8 @@ export class Parser extends DiagnosticEmitter { if (!operand) return null; return Node.createUnaryPrefixExpression(token, operand, tn.range(startPos, tn.pos)); } - case Token.PlusPlus: - case Token.MinusMinus: { + case Token.Plus_Plus: + case Token.Minus_Minus: { let operand = this.parseExpression(tn, Precedence.UnaryPrefix); if (!operand) return null; switch (operand.kind) { @@ -3765,7 +3765,7 @@ export class Parser extends DiagnosticEmitter { switch (tn.next(IdentifierHandling.Prefer)) { // function expression - case Token.DotDotDot: { + case Token.Dot_Dot_Dot: { tn.reset(state); return this.parseFunctionExpression(tn); } @@ -3778,7 +3778,7 @@ export class Parser extends DiagnosticEmitter { case Token.CloseParen: { if ( !tn.skip(Token.Colon) && - !tn.skip(Token.EqualsGreaterThan) + !tn.skip(Token.Equals_GreaterThan) ) { again = false; break; @@ -3938,7 +3938,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.TemplateLiteral)) { return this.parseTemplateLiteral(tn, identifier); } - if (tn.peek(true) == Token.EqualsGreaterThan && !tn.nextTokenOnNewLine) { + if (tn.peek(true) == Token.Equals_GreaterThan && !tn.nextTokenOnNewLine) { return this.parseFunctionExpressionCommon( tn, Node.createEmptyIdentifierExpression(tn.range(startPos)), @@ -4170,8 +4170,8 @@ export class Parser extends DiagnosticEmitter { break; } // UnaryPostfixExpression - case Token.PlusPlus: - case Token.MinusMinus: { + case Token.Plus_Plus: + case Token.Minus_Minus: { if ( expr.kind != NodeKind.Identifier && expr.kind != NodeKind.ElementAccess && @@ -4259,7 +4259,7 @@ export class Parser extends DiagnosticEmitter { case Token.Equals: case Token.PlusEquals: case Token.MinusEquals: - case Token.AsteriskAsteriskEquals: + case Token.Asterisk_Asterisk_Equals: case Token.AsteriskEquals: case Token.SlashEquals: case Token.PercentEquals: @@ -4269,7 +4269,7 @@ export class Parser extends DiagnosticEmitter { case Token.AmpersandEquals: case Token.CaretEquals: case Token.BarEquals: - case Token.AsteriskAsterisk: { + case Token.Asterisk_Asterisk: { let next = this.parseExpression(tn, nextPrecedence); if (!next) return null; expr = Node.createBinaryExpression(token, expr, next, tn.range(startPos, tn.pos)); @@ -4280,10 +4280,10 @@ export class Parser extends DiagnosticEmitter { case Token.GreaterThan: case Token.LessThan_Equals: case Token.GreaterThan_Equals: - case Token.EqualsEquals: - case Token.EqualsEqualsEquals: - case Token.ExclamationEqualsEquals: - case Token.ExclamationEquals: + case Token.Equals_Equals: + case Token.Equals_Equals_Equals: + case Token.Exclamation_Equals_Equals: + case Token.Exclamation_Equals: case Token.Plus: case Token.Minus: case Token.Asterisk: @@ -4295,7 +4295,7 @@ export class Parser extends DiagnosticEmitter { case Token.Ampersand: case Token.Bar: case Token.Caret: - case Token.AmpersandAmpersand: + case Token.Ampersand_Ampersand: case Token.BarBar: { let next = this.parseExpression(tn, nextPrecedence + 1); if (!next) return null; @@ -4522,7 +4522,7 @@ function determinePrecedence(kind: Token): Precedence { case Token.Equals: case Token.PlusEquals: case Token.MinusEquals: - case Token.AsteriskAsteriskEquals: + case Token.Asterisk_Asterisk_Equals: case Token.AsteriskEquals: case Token.SlashEquals: case Token.PercentEquals: @@ -4534,14 +4534,14 @@ function determinePrecedence(kind: Token): Precedence { case Token.BarEquals: return Precedence.Assignment; case Token.Question: return Precedence.Conditional; case Token.BarBar: return Precedence.LogicalOr; - case Token.AmpersandAmpersand: return Precedence.LogicalAnd; + case Token.Ampersand_Ampersand: return Precedence.LogicalAnd; case Token.Bar: return Precedence.BitwiseOr; case Token.Caret: return Precedence.BitwiseXor; case Token.Ampersand: return Precedence.BitwiseAnd; - case Token.EqualsEquals: - case Token.ExclamationEquals: - case Token.EqualsEqualsEquals: - case Token.ExclamationEqualsEquals: return Precedence.Equality; + case Token.Equals_Equals: + case Token.Exclamation_Equals: + case Token.Equals_Equals_Equals: + case Token.Exclamation_Equals_Equals: return Precedence.Equality; case Token.As: case Token.In: case Token.InstanceOf: @@ -4557,9 +4557,9 @@ function determinePrecedence(kind: Token): Precedence { case Token.Asterisk: case Token.Slash: case Token.Percent: return Precedence.Multiplicative; - case Token.AsteriskAsterisk: return Precedence.Exponentiated; - case Token.PlusPlus: - case Token.MinusMinus: return Precedence.UnaryPostfix; + case Token.Asterisk_Asterisk: return Precedence.Exponentiated; + case Token.Plus_Plus: + case Token.Minus_Minus: return Precedence.UnaryPostfix; case Token.Dot: case Token.OpenBracket: case Token.Exclamation: return Precedence.MemberAccess; diff --git a/src/program.ts b/src/program.ts index a1e782dee4..58c8316a21 100644 --- a/src/program.ts +++ b/src/program.ts @@ -372,8 +372,8 @@ export namespace OperatorKind { case Token.SlashEquals: return OperatorKind.Div; case Token.Percent: case Token.PercentEquals: return OperatorKind.Rem; - case Token.AsteriskAsterisk: - case Token.AsteriskAsteriskEquals: return OperatorKind.Pow; + case Token.Asterisk_Asterisk: + case Token.Asterisk_Asterisk_Equals: return OperatorKind.Pow; case Token.Ampersand: case Token.AmpersandEquals: return OperatorKind.BitwiseAnd; case Token.Bar: @@ -386,8 +386,8 @@ export namespace OperatorKind { case Token.GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShr; case Token.GreaterThan_GreaterThan_GreaterThan: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShrU; - case Token.EqualsEquals: return OperatorKind.Eq; - case Token.ExclamationEquals: return OperatorKind.Ne; + case Token.Equals_Equals: return OperatorKind.Eq; + case Token.Exclamation_Equals: return OperatorKind.Ne; case Token.GreaterThan: return OperatorKind.Gt; case Token.GreaterThan_Equals: return OperatorKind.Ge; case Token.LessThan: return OperatorKind.Lt; @@ -403,8 +403,8 @@ export namespace OperatorKind { case Token.Minus: return OperatorKind.Minus; case Token.Exclamation: return OperatorKind.Not; case Token.Tilde: return OperatorKind.BitwiseNot; - case Token.PlusPlus: return OperatorKind.PrefixInc; - case Token.MinusMinus: return OperatorKind.PrefixDec; + case Token.Plus_Plus: return OperatorKind.PrefixInc; + case Token.Minus_Minus: return OperatorKind.PrefixDec; } return OperatorKind.Invalid; } @@ -412,8 +412,8 @@ export namespace OperatorKind { /** Converts a unary postfix operator token to the respective operator kind. */ export function fromUnaryPostfixToken(token: Token): OperatorKind { switch (token) { - case Token.PlusPlus: return OperatorKind.PostfixInc; - case Token.MinusMinus: return OperatorKind.PostfixDec; + case Token.Plus_Plus: return OperatorKind.PostfixInc; + case Token.Minus_Minus: return OperatorKind.PostfixDec; } return OperatorKind.Invalid; } diff --git a/src/resolver.ts b/src/resolver.ts index 99b8387049..10b6b61f90 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -1824,8 +1824,8 @@ export class Resolver extends DiagnosticEmitter { // fall-through } case Token.Plus: - case Token.PlusPlus: - case Token.MinusMinus: { + case Token.Plus_Plus: + case Token.Minus_Minus: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -1873,7 +1873,7 @@ export class Resolver extends DiagnosticEmitter { } return type.intType; } - case Token.DotDotDot: { + case Token.Dot_Dot_Dot: { if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Not_implemented_0, @@ -1928,8 +1928,8 @@ export class Resolver extends DiagnosticEmitter { ): Type | null { let operator = node.operator; switch (operator) { - case Token.PlusPlus: - case Token.MinusMinus: { + case Token.Plus_Plus: + case Token.Minus_Minus: { let type = this.resolveExpression(node.operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -2000,7 +2000,7 @@ export class Resolver extends DiagnosticEmitter { case Token.PlusEquals: case Token.MinusEquals: case Token.AsteriskEquals: - case Token.AsteriskAsteriskEquals: + case Token.Asterisk_Asterisk_Equals: case Token.SlashEquals: case Token.PercentEquals: case Token.LessThan_LessThan_Equals: @@ -2039,8 +2039,8 @@ export class Resolver extends DiagnosticEmitter { // equality: result is Bool, preferring overloads, incl. references - case Token.EqualsEquals: - case Token.ExclamationEquals: { + case Token.Equals_Equals: + case Token.Exclamation_Equals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2053,8 +2053,8 @@ export class Resolver extends DiagnosticEmitter { // identity: result is Bool, not supporting overloads - case Token.EqualsEqualsEquals: - case Token.ExclamationEqualsEquals: { + case Token.Equals_Equals_Equals: + case Token.Exclamation_Equals_Equals: { return Type.bool; } @@ -2065,7 +2065,7 @@ export class Resolver extends DiagnosticEmitter { case Token.Asterisk: case Token.Slash: case Token.Percent: // mod has special logic, but also behaves like this - case Token.AsteriskAsterisk: { + case Token.Asterisk_Asterisk: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -2139,7 +2139,7 @@ export class Resolver extends DiagnosticEmitter { // logical: result is LHS (RHS is converted to LHS), not supporting overloads - case Token.AmpersandAmpersand: + case Token.Ampersand_Ampersand: case Token.BarBar: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 17e0d57ea0..027fc2c17e 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -115,26 +115,26 @@ export const enum Token { OpenBracket, CloseBracket, Dot, - DotDotDot, + Dot_Dot_Dot, Semicolon, Comma, LessThan, GreaterThan, LessThan_Equals, GreaterThan_Equals, - EqualsEquals, - ExclamationEquals, - EqualsEqualsEquals, - ExclamationEqualsEquals, - EqualsGreaterThan, + Equals_Equals, + Exclamation_Equals, + Equals_Equals_Equals, + Exclamation_Equals_Equals, + Equals_GreaterThan, Plus, Minus, - AsteriskAsterisk, + Asterisk_Asterisk, Asterisk, Slash, Percent, - PlusPlus, - MinusMinus, + Plus_Plus, + Minus_Minus, LessThan_LessThan, GreaterThan_GreaterThan, GreaterThan_GreaterThan_GreaterThan, @@ -143,7 +143,7 @@ export const enum Token { Caret, Exclamation, Tilde, - AmpersandAmpersand, + Ampersand_Ampersand, BarBar, Question, Colon, @@ -151,7 +151,7 @@ export const enum Token { PlusEquals, MinusEquals, AsteriskEquals, - AsteriskAsteriskEquals, + Asterisk_Asterisk_Equals, SlashEquals, PercentEquals, LessThan_LessThan_Equals, @@ -398,24 +398,24 @@ export function operatorTokenToString(token: Token): string { case Token.TypeOf: return "typeof"; case Token.Void: return "void"; case Token.Yield: return "yield"; - case Token.DotDotDot: return "..."; + case Token.Dot_Dot_Dot: return "..."; case Token.Comma: return ","; case Token.LessThan: return "<"; case Token.GreaterThan: return ">"; case Token.LessThan_Equals: return "<="; case Token.GreaterThan_Equals: return ">="; - case Token.EqualsEquals: return "=="; - case Token.ExclamationEquals: return "!="; - case Token.EqualsEqualsEquals: return "==="; - case Token.ExclamationEqualsEquals: return "!=="; + case Token.Equals_Equals: return "=="; + case Token.Exclamation_Equals: return "!="; + case Token.Equals_Equals_Equals: return "==="; + case Token.Exclamation_Equals_Equals: return "!=="; case Token.Plus: return "+"; case Token.Minus: return "-"; - case Token.AsteriskAsterisk: return "**"; + case Token.Asterisk_Asterisk: return "**"; case Token.Asterisk: return "*"; case Token.Slash: return "/"; case Token.Percent: return "%"; - case Token.PlusPlus: return "++"; - case Token.MinusMinus: return "--"; + case Token.Plus_Plus: return "++"; + case Token.Minus_Minus: return "--"; case Token.LessThan_LessThan: return "<<"; case Token.GreaterThan_GreaterThan: return ">>"; case Token.GreaterThan_GreaterThan_GreaterThan: return ">>>"; @@ -424,13 +424,13 @@ export function operatorTokenToString(token: Token): string { case Token.Caret: return "^"; case Token.Exclamation: return "!"; case Token.Tilde: return "~"; - case Token.AmpersandAmpersand: return "&&"; + case Token.Ampersand_Ampersand: return "&&"; case Token.BarBar: return "||"; case Token.Equals: return "="; case Token.PlusEquals: return "+="; case Token.MinusEquals: return "-="; case Token.AsteriskEquals: return "*="; - case Token.AsteriskAsteriskEquals: return "**="; + case Token.Asterisk_Asterisk_Equals: return "**="; case Token.SlashEquals: return "/="; case Token.PercentEquals: return "%="; case Token.LessThan_LessThan_Equals: return "<<="; @@ -550,10 +550,10 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.ExclamationEqualsEquals; + return Token.Exclamation_Equals_Equals; } this.pos = pos; - return Token.ExclamationEquals; + return Token.Exclamation_Equals; } this.pos = pos; return Token.Exclamation; @@ -585,7 +585,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.Ampersand) { this.pos = pos + 1; - return Token.AmpersandAmpersand; + return Token.Ampersand_Ampersand; } if (chr == CharCode.Equals) { this.pos = pos + 1; @@ -618,10 +618,10 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.AsteriskAsteriskEquals; + return Token.Asterisk_Asterisk_Equals; } this.pos = pos; - return Token.AsteriskAsterisk; + return Token.Asterisk_Asterisk; } } this.pos = pos; @@ -633,7 +633,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.Plus) { this.pos = pos + 1; - return Token.PlusPlus; + return Token.Plus_Plus; } if (chr == CharCode.Equals) { this.pos = pos + 1; @@ -653,7 +653,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.Minus) { this.pos = pos + 1; - return Token.MinusMinus; + return Token.Minus_Minus; } if (chr == CharCode.Equals) { this.pos = pos + 1; @@ -677,7 +677,7 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos + 1) == CharCode.Dot ) { this.pos = pos + 2; - return Token.DotDotDot; + return Token.Dot_Dot_Dot; } } this.pos = pos; @@ -808,14 +808,14 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.EqualsEqualsEquals; + return Token.Equals_Equals_Equals; } this.pos = pos; - return Token.EqualsEquals; + return Token.Equals_Equals; } if (chr == CharCode.GreaterThan) { this.pos = pos + 1; - return Token.EqualsGreaterThan; + return Token.Equals_GreaterThan; } } this.pos = pos; From fd2e9a103dec3d6ad4e7ade285a16d20655af46e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 21:02:05 +0300 Subject: [PATCH 20/22] Revert ExclamationEquals --- src/compiler.ts | 2 +- src/parser.ts | 4 ++-- src/program.ts | 2 +- src/resolver.ts | 2 +- src/tokenizer.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 3f71778a95..3cb5b99b6a 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3990,7 +3990,7 @@ export class Compiler extends DiagnosticEmitter { break; } case Token.Exclamation_Equals_Equals: - case Token.Exclamation_Equals: { + case Token.ExclamationEquals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; diff --git a/src/parser.ts b/src/parser.ts index d2fec577ae..4ee7f2f7aa 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4283,7 +4283,7 @@ export class Parser extends DiagnosticEmitter { case Token.Equals_Equals: case Token.Equals_Equals_Equals: case Token.Exclamation_Equals_Equals: - case Token.Exclamation_Equals: + case Token.ExclamationEquals: case Token.Plus: case Token.Minus: case Token.Asterisk: @@ -4539,7 +4539,7 @@ function determinePrecedence(kind: Token): Precedence { case Token.Caret: return Precedence.BitwiseXor; case Token.Ampersand: return Precedence.BitwiseAnd; case Token.Equals_Equals: - case Token.Exclamation_Equals: + case Token.ExclamationEquals: case Token.Equals_Equals_Equals: case Token.Exclamation_Equals_Equals: return Precedence.Equality; case Token.As: diff --git a/src/program.ts b/src/program.ts index 58c8316a21..5ed2cb5c95 100644 --- a/src/program.ts +++ b/src/program.ts @@ -387,7 +387,7 @@ export namespace OperatorKind { case Token.GreaterThan_GreaterThan_GreaterThan: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShrU; case Token.Equals_Equals: return OperatorKind.Eq; - case Token.Exclamation_Equals: return OperatorKind.Ne; + case Token.ExclamationEquals: return OperatorKind.Ne; case Token.GreaterThan: return OperatorKind.Gt; case Token.GreaterThan_Equals: return OperatorKind.Ge; case Token.LessThan: return OperatorKind.Lt; diff --git a/src/resolver.ts b/src/resolver.ts index 10b6b61f90..9c45be8128 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2040,7 +2040,7 @@ export class Resolver extends DiagnosticEmitter { // equality: result is Bool, preferring overloads, incl. references case Token.Equals_Equals: - case Token.Exclamation_Equals: { + case Token.ExclamationEquals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 027fc2c17e..673dadd261 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -123,7 +123,7 @@ export const enum Token { LessThan_Equals, GreaterThan_Equals, Equals_Equals, - Exclamation_Equals, + ExclamationEquals, Equals_Equals_Equals, Exclamation_Equals_Equals, Equals_GreaterThan, @@ -405,7 +405,7 @@ export function operatorTokenToString(token: Token): string { case Token.LessThan_Equals: return "<="; case Token.GreaterThan_Equals: return ">="; case Token.Equals_Equals: return "=="; - case Token.Exclamation_Equals: return "!="; + case Token.ExclamationEquals: return "!="; case Token.Equals_Equals_Equals: return "==="; case Token.Exclamation_Equals_Equals: return "!=="; case Token.Plus: return "+"; @@ -553,7 +553,7 @@ export class Tokenizer extends DiagnosticEmitter { return Token.Exclamation_Equals_Equals; } this.pos = pos; - return Token.Exclamation_Equals; + return Token.ExclamationEquals; } this.pos = pos; return Token.Exclamation; From 28d30170c4c0e8e64a6f13dcc84e363055c70ad8 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 21:14:45 +0300 Subject: [PATCH 21/22] more --- src/compiler.ts | 18 ++++++++-------- src/parser.ts | 36 ++++++++++++++++---------------- src/program.ts | 16 +++++++------- src/resolver.ts | 18 ++++++++-------- src/tokenizer.ts | 54 ++++++++++++++++++++++++------------------------ 5 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 3cb5b99b6a..d0fd3d6a99 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -4044,7 +4044,7 @@ export class Compiler extends DiagnosticEmitter { case Token.Equals: { return this.compileAssignment(left, right, contextualType); } - case Token.PlusEquals: compound = true; + case Token.Plus_Equals: compound = true; case Token.Plus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4088,7 +4088,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAdd(leftExpr, rightExpr, commonType); break; } - case Token.MinusEquals: compound = true; + case Token.Minus_Equals: compound = true; case Token.Minus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4133,7 +4133,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeSub(leftExpr, rightExpr, commonType); break; } - case Token.AsteriskEquals: compound = true; + case Token.Asterisk_Equals: compound = true; case Token.Asterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4223,7 +4223,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makePow(leftExpr, rightExpr, commonType, expression); break; } - case Token.SlashEquals: compound = true; + case Token.Slash_Equals: compound = true; case Token.Slash: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4268,7 +4268,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeDiv(leftExpr, rightExpr, commonType); break; } - case Token.PercentEquals: compound = true; + case Token.Percent_Equals: compound = true; case Token.Percent: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; @@ -4395,7 +4395,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeShru(leftExpr, rightExpr, rightType); break; } - case Token.AmpersandEquals: compound = true; + case Token.Ampersand_Equals: compound = true; case Token.Ampersand: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4440,7 +4440,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAnd(leftExpr, rightExpr, commonType); break; } - case Token.BarEquals: compound = true; + case Token.Bar_Equals: compound = true; case Token.Bar: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4485,7 +4485,7 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeOr(leftExpr, rightExpr, commonType); break; } - case Token.CaretEquals: compound = true; + case Token.Caret_Equals: compound = true; case Token.Caret: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; @@ -4594,7 +4594,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.BarBar: { // left || right -> ((t = left) ? t : right) + case Token.Bar_Bar: { // left || right -> ((t = left) ? t : right) let flow = this.currentFlow; let inheritedConstraints = constraints & Constraints.MustWrap; leftExpr = this.compileExpression(left, contextualType.exceptVoid, inheritedConstraints); diff --git a/src/parser.ts b/src/parser.ts index 4ee7f2f7aa..9f62da6182 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4257,18 +4257,18 @@ export class Parser extends DiagnosticEmitter { } // BinaryExpression (right associative) case Token.Equals: - case Token.PlusEquals: - case Token.MinusEquals: + case Token.Plus_Equals: + case Token.Minus_Equals: case Token.Asterisk_Asterisk_Equals: - case Token.AsteriskEquals: - case Token.SlashEquals: - case Token.PercentEquals: + case Token.Asterisk_Equals: + case Token.Slash_Equals: + case Token.Percent_Equals: case Token.LessThan_LessThan_Equals: case Token.GreaterThan_GreaterThan_Equals: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: - case Token.AmpersandEquals: - case Token.CaretEquals: - case Token.BarEquals: + case Token.Ampersand_Equals: + case Token.Caret_Equals: + case Token.Bar_Equals: case Token.Asterisk_Asterisk: { let next = this.parseExpression(tn, nextPrecedence); if (!next) return null; @@ -4296,7 +4296,7 @@ export class Parser extends DiagnosticEmitter { case Token.Bar: case Token.Caret: case Token.Ampersand_Ampersand: - case Token.BarBar: { + case Token.Bar_Bar: { let next = this.parseExpression(tn, nextPrecedence + 1); if (!next) return null; expr = Node.createBinaryExpression(token, expr, next, tn.range(startPos, tn.pos)); @@ -4520,20 +4520,20 @@ function determinePrecedence(kind: Token): Precedence { switch (kind) { case Token.Comma: return Precedence.Comma; case Token.Equals: - case Token.PlusEquals: - case Token.MinusEquals: + case Token.Plus_Equals: + case Token.Minus_Equals: case Token.Asterisk_Asterisk_Equals: - case Token.AsteriskEquals: - case Token.SlashEquals: - case Token.PercentEquals: + case Token.Asterisk_Equals: + case Token.Slash_Equals: + case Token.Percent_Equals: case Token.LessThan_LessThan_Equals: case Token.GreaterThan_GreaterThan_Equals: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: - case Token.AmpersandEquals: - case Token.CaretEquals: - case Token.BarEquals: return Precedence.Assignment; + case Token.Ampersand_Equals: + case Token.Caret_Equals: + case Token.Bar_Equals: return Precedence.Assignment; case Token.Question: return Precedence.Conditional; - case Token.BarBar: return Precedence.LogicalOr; + case Token.Bar_Bar: return Precedence.LogicalOr; case Token.Ampersand_Ampersand: return Precedence.LogicalAnd; case Token.Bar: return Precedence.BitwiseOr; case Token.Caret: return Precedence.BitwiseXor; diff --git a/src/program.ts b/src/program.ts index 5ed2cb5c95..c9d3ca5960 100644 --- a/src/program.ts +++ b/src/program.ts @@ -363,23 +363,23 @@ export namespace OperatorKind { export function fromBinaryToken(token: Token): OperatorKind { switch (token) { case Token.Plus: - case Token.PlusEquals: return OperatorKind.Add; + case Token.Plus_Equals: return OperatorKind.Add; case Token.Minus: - case Token.MinusEquals: return OperatorKind.Sub; + case Token.Minus_Equals: return OperatorKind.Sub; case Token.Asterisk: - case Token.AsteriskEquals: return OperatorKind.Mul; + case Token.Asterisk_Equals: return OperatorKind.Mul; case Token.Slash: - case Token.SlashEquals: return OperatorKind.Div; + case Token.Slash_Equals: return OperatorKind.Div; case Token.Percent: - case Token.PercentEquals: return OperatorKind.Rem; + case Token.Percent_Equals: return OperatorKind.Rem; case Token.Asterisk_Asterisk: case Token.Asterisk_Asterisk_Equals: return OperatorKind.Pow; case Token.Ampersand: - case Token.AmpersandEquals: return OperatorKind.BitwiseAnd; + case Token.Ampersand_Equals: return OperatorKind.BitwiseAnd; case Token.Bar: - case Token.BarEquals: return OperatorKind.BitwiseOr; + case Token.Bar_Equals: return OperatorKind.BitwiseOr; case Token.Caret: - case Token.CaretEquals: return OperatorKind.BitwiseXor; + case Token.Caret_Equals: return OperatorKind.BitwiseXor; case Token.LessThan_LessThan: case Token.LessThan_LessThan_Equals: return OperatorKind.BitwiseShl; case Token.GreaterThan_GreaterThan: diff --git a/src/resolver.ts b/src/resolver.ts index 9c45be8128..d515279d43 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -1997,18 +1997,18 @@ export class Resolver extends DiagnosticEmitter { // assignment: result is the target's type case Token.Equals: - case Token.PlusEquals: - case Token.MinusEquals: - case Token.AsteriskEquals: + case Token.Plus_Equals: + case Token.Minus_Equals: + case Token.Asterisk_Equals: case Token.Asterisk_Asterisk_Equals: - case Token.SlashEquals: - case Token.PercentEquals: + case Token.Slash_Equals: + case Token.Percent_Equals: case Token.LessThan_LessThan_Equals: case Token.GreaterThan_GreaterThan_Equals: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: - case Token.AmpersandEquals: - case Token.BarEquals: - case Token.CaretEquals: { + case Token.Ampersand_Equals: + case Token.Bar_Equals: + case Token.Caret_Equals: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } @@ -2140,7 +2140,7 @@ export class Resolver extends DiagnosticEmitter { // logical: result is LHS (RHS is converted to LHS), not supporting overloads case Token.Ampersand_Ampersand: - case Token.BarBar: { + case Token.Bar_Bar: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } } diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 673dadd261..c6e10b4fab 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -144,22 +144,22 @@ export const enum Token { Exclamation, Tilde, Ampersand_Ampersand, - BarBar, + Bar_Bar, Question, Colon, Equals, - PlusEquals, - MinusEquals, - AsteriskEquals, + Plus_Equals, + Minus_Equals, + Asterisk_Equals, Asterisk_Asterisk_Equals, - SlashEquals, - PercentEquals, + Slash_Equals, + Percent_Equals, LessThan_LessThan_Equals, GreaterThan_GreaterThan_Equals, GreaterThan_GreaterThan_GreaterThan_Equals, - AmpersandEquals, - BarEquals, - CaretEquals, + Ampersand_Equals, + Bar_Equals, + Caret_Equals, At, // literals @@ -425,20 +425,20 @@ export function operatorTokenToString(token: Token): string { case Token.Exclamation: return "!"; case Token.Tilde: return "~"; case Token.Ampersand_Ampersand: return "&&"; - case Token.BarBar: return "||"; + case Token.Bar_Bar: return "||"; case Token.Equals: return "="; - case Token.PlusEquals: return "+="; - case Token.MinusEquals: return "-="; - case Token.AsteriskEquals: return "*="; + case Token.Plus_Equals: return "+="; + case Token.Minus_Equals: return "-="; + case Token.Asterisk_Equals: return "*="; case Token.Asterisk_Asterisk_Equals: return "**="; - case Token.SlashEquals: return "/="; - case Token.PercentEquals: return "%="; + case Token.Slash_Equals: return "/="; + case Token.Percent_Equals: return "%="; case Token.LessThan_LessThan_Equals: return "<<="; case Token.GreaterThan_GreaterThan_Equals: return ">>="; case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return ">>>="; - case Token.AmpersandEquals: return "&="; - case Token.BarEquals: return "|="; - case Token.CaretEquals: return "^="; + case Token.Ampersand_Equals: return "&="; + case Token.Bar_Equals: return "|="; + case Token.Caret_Equals: return "^="; default: { assert(false); return ""; @@ -574,7 +574,7 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.PercentEquals; + return Token.Percent_Equals; } this.pos = pos; return Token.Percent; @@ -589,7 +589,7 @@ export class Tokenizer extends DiagnosticEmitter { } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.AmpersandEquals; + return Token.Ampersand_Equals; } } this.pos = pos; @@ -609,7 +609,7 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.AsteriskEquals; + return Token.Asterisk_Equals; } if (chr == CharCode.Asterisk) { ++pos; @@ -637,7 +637,7 @@ export class Tokenizer extends DiagnosticEmitter { } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.PlusEquals; + return Token.Plus_Equals; } } this.pos = pos; @@ -657,7 +657,7 @@ export class Tokenizer extends DiagnosticEmitter { } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.MinusEquals; + return Token.Minus_Equals; } } this.pos = pos; @@ -742,7 +742,7 @@ export class Tokenizer extends DiagnosticEmitter { } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.SlashEquals; + return Token.Slash_Equals; } } this.pos = pos; @@ -876,7 +876,7 @@ export class Tokenizer extends DiagnosticEmitter { text.charCodeAt(pos) == CharCode.Equals ) { this.pos = pos + 1; - return Token.CaretEquals; + return Token.Caret_Equals; } this.pos = pos; return Token.Caret; @@ -891,11 +891,11 @@ export class Tokenizer extends DiagnosticEmitter { let chr = text.charCodeAt(pos); if (chr == CharCode.Bar) { this.pos = pos + 1; - return Token.BarBar; + return Token.Bar_Bar; } if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.BarEquals; + return Token.Bar_Equals; } } this.pos = pos; From 9f9d80ec178e32d92c609e4291e154c6199a9df8 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 23 Oct 2022 23:01:59 +0300 Subject: [PATCH 22/22] Exclamation_Equals --- src/compiler.ts | 2 +- src/parser.ts | 4 ++-- src/program.ts | 2 +- src/resolver.ts | 2 +- src/tokenizer.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index d0fd3d6a99..fd0ac005bc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3990,7 +3990,7 @@ export class Compiler extends DiagnosticEmitter { break; } case Token.Exclamation_Equals_Equals: - case Token.ExclamationEquals: { + case Token.Exclamation_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; diff --git a/src/parser.ts b/src/parser.ts index 9f62da6182..1ab2d3e915 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4283,7 +4283,7 @@ export class Parser extends DiagnosticEmitter { case Token.Equals_Equals: case Token.Equals_Equals_Equals: case Token.Exclamation_Equals_Equals: - case Token.ExclamationEquals: + case Token.Exclamation_Equals: case Token.Plus: case Token.Minus: case Token.Asterisk: @@ -4539,7 +4539,7 @@ function determinePrecedence(kind: Token): Precedence { case Token.Caret: return Precedence.BitwiseXor; case Token.Ampersand: return Precedence.BitwiseAnd; case Token.Equals_Equals: - case Token.ExclamationEquals: + case Token.Exclamation_Equals: case Token.Equals_Equals_Equals: case Token.Exclamation_Equals_Equals: return Precedence.Equality; case Token.As: diff --git a/src/program.ts b/src/program.ts index c9d3ca5960..421a76618b 100644 --- a/src/program.ts +++ b/src/program.ts @@ -387,7 +387,7 @@ export namespace OperatorKind { case Token.GreaterThan_GreaterThan_GreaterThan: case Token.GreaterThan_GreaterThan_GreaterThan_Equals: return OperatorKind.BitwiseShrU; case Token.Equals_Equals: return OperatorKind.Eq; - case Token.ExclamationEquals: return OperatorKind.Ne; + case Token.Exclamation_Equals: return OperatorKind.Ne; case Token.GreaterThan: return OperatorKind.Gt; case Token.GreaterThan_Equals: return OperatorKind.Ge; case Token.LessThan: return OperatorKind.Lt; diff --git a/src/resolver.ts b/src/resolver.ts index d515279d43..6b862ceb17 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2040,7 +2040,7 @@ export class Resolver extends DiagnosticEmitter { // equality: result is Bool, preferring overloads, incl. references case Token.Equals_Equals: - case Token.ExclamationEquals: { + case Token.Exclamation_Equals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); diff --git a/src/tokenizer.ts b/src/tokenizer.ts index c6e10b4fab..767ee03489 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -123,7 +123,7 @@ export const enum Token { LessThan_Equals, GreaterThan_Equals, Equals_Equals, - ExclamationEquals, + Exclamation_Equals, Equals_Equals_Equals, Exclamation_Equals_Equals, Equals_GreaterThan, @@ -405,7 +405,7 @@ export function operatorTokenToString(token: Token): string { case Token.LessThan_Equals: return "<="; case Token.GreaterThan_Equals: return ">="; case Token.Equals_Equals: return "=="; - case Token.ExclamationEquals: return "!="; + case Token.Exclamation_Equals: return "!="; case Token.Equals_Equals_Equals: return "==="; case Token.Exclamation_Equals_Equals: return "!=="; case Token.Plus: return "+"; @@ -553,7 +553,7 @@ export class Tokenizer extends DiagnosticEmitter { return Token.Exclamation_Equals_Equals; } this.pos = pos; - return Token.ExclamationEquals; + return Token.Exclamation_Equals; } this.pos = pos; return Token.Exclamation;