diff --git a/src/ast.ts b/src/ast.ts index 497d3dc1ab..66c8969264 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. */ @@ -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( @@ -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,12 +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; } } @@ -832,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; @@ -847,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) { @@ -873,7 +877,7 @@ export class TypeName extends Node { /** Source range. */ range: Range ) { - super(NodeKind.TYPENAME, range); + super(NodeKind.TypeName, range); } } @@ -889,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. */ @@ -913,7 +917,7 @@ export class FunctionTypeNode extends TypeNode { /** Source range. */ range: Range ) { - super(NodeKind.FUNCTIONTYPE, isNullable, range); + super(NodeKind.FunctionType, isNullable, range); } } @@ -929,18 +933,18 @@ export class TypeParameterNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.TYPEPARAMETER, range); + super(NodeKind.TypeParameter, range); } } /** 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. */ @@ -957,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; } @@ -977,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; @@ -1046,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; } } @@ -1081,18 +1085,18 @@ export class DecoratorNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.DECORATOR, range); + super(NodeKind.Decorator, range); } } /** Comment kinds. */ export const enum CommentKind { /** Line comment. */ - LINE, + Line, /** Triple-slash line comment. */ - TRIPLE, + Triple, /** Block comment. */ - BLOCK + Block } /** Represents a comment. */ @@ -1105,7 +1109,7 @@ export class CommentNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.COMMENT, range); + super(NodeKind.Comment, range); } } @@ -1124,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. */ @@ -1147,7 +1151,7 @@ export abstract class LiteralExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.LITERAL, range); + super(NodeKind.Literal, range); } } @@ -1159,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. */ @@ -1187,7 +1191,7 @@ export class AssertionExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.ASSERTION, range); + super(NodeKind.Assertion, range); } } @@ -1203,7 +1207,7 @@ export class BinaryExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.BINARY, range); + super(NodeKind.Binary, range); } } @@ -1219,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. */ @@ -1251,7 +1255,7 @@ export class ClassExpression extends Expression { /** Inline class declaration. */ public declaration: ClassDeclaration ) { - super(NodeKind.CLASS, declaration.range); + super(NodeKind.Class, declaration.range); } } @@ -1263,7 +1267,7 @@ export class CommaExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.COMMA, range); + super(NodeKind.Comma, range); } } @@ -1274,7 +1278,7 @@ export class ConstructorExpression extends IdentifierExpression { range: Range ) { super("constructor", false, range); - this.kind = NodeKind.CONSTRUCTOR; + this.kind = NodeKind.Constructor; } } @@ -1288,7 +1292,7 @@ export class ElementAccessExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.ELEMENTACCESS, range); + super(NodeKind.ElementAccess, range); } } @@ -1300,7 +1304,7 @@ export class FloatLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.FLOAT, range); + super(LiteralKind.Float, range); } } @@ -1310,7 +1314,7 @@ export class FunctionExpression extends Expression { /** Inline function declaration. */ public declaration: FunctionDeclaration ) { - super(NodeKind.FUNCTION, declaration.range); + super(NodeKind.Function, declaration.range); } } @@ -1324,7 +1328,7 @@ export class InstanceOfExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.INSTANCEOF, range); + super(NodeKind.InstanceOf, range); } } @@ -1336,7 +1340,7 @@ export class IntegerLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.INTEGER, range); + super(LiteralKind.Integer, range); } } @@ -1352,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. */ @@ -1383,7 +1387,7 @@ export class NullExpression extends IdentifierExpression { range: Range ) { super("null", false, range); - this.kind = NodeKind.NULL; + this.kind = NodeKind.Null; } } @@ -1397,7 +1401,7 @@ export class ObjectLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.OBJECT, range); + super(LiteralKind.Object, range); } } @@ -1407,7 +1411,7 @@ export class OmittedExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.OMITTED, range); + super(NodeKind.Omitted, range); } } @@ -1419,7 +1423,7 @@ export class ParenthesizedExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.PARENTHESIZED, range); + super(NodeKind.Parenthesized, range); } } @@ -1433,7 +1437,7 @@ export class PropertyAccessExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.PROPERTYACCESS, range); + super(NodeKind.PropertyAccess, range); } } @@ -1447,7 +1451,7 @@ export class RegexpLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.REGEXP, range); + super(LiteralKind.RegExp, range); } } @@ -1463,7 +1467,7 @@ export class TernaryExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.TERNARY, range); + super(NodeKind.Ternary, range); } } @@ -1475,7 +1479,7 @@ export class StringLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.STRING, range); + super(LiteralKind.String, range); } } @@ -1486,7 +1490,7 @@ export class SuperExpression extends IdentifierExpression { range: Range ) { super("super", false, range); - this.kind = NodeKind.SUPER; + this.kind = NodeKind.Super; } } @@ -1504,7 +1508,7 @@ export class TemplateLiteralExpression extends LiteralExpression { /** Source range. */ range: Range ) { - super(LiteralKind.TEMPLATE, range); + super(LiteralKind.Template, range); } } @@ -1515,7 +1519,7 @@ export class ThisExpression extends IdentifierExpression { range: Range ) { super("this", false, range); - this.kind = NodeKind.THIS; + this.kind = NodeKind.This; } } @@ -1526,7 +1530,7 @@ export class TrueExpression extends IdentifierExpression { range: Range ) { super("true", false, range); - this.kind = NodeKind.TRUE; + this.kind = NodeKind.True; } } @@ -1537,7 +1541,7 @@ export class FalseExpression extends IdentifierExpression { range: Range ) { super("false", false, range); - this.kind = NodeKind.FALSE; + this.kind = NodeKind.False; } } @@ -1567,7 +1571,7 @@ export class UnaryPostfixExpression extends UnaryExpression { /** Source range. */ range: Range ) { - super(NodeKind.UNARYPOSTFIX, operator, operand, range); + super(NodeKind.UnaryPostfix, operator, operand, range); } } @@ -1581,7 +1585,7 @@ export class UnaryPrefixExpression extends UnaryExpression { /** Source range. */ range: Range ) { - super(NodeKind.UNARYPREFIX, operator, operand, range); + super(NodeKind.UnaryPrefix, operator, operand, range); } } @@ -1595,7 +1599,7 @@ export class CompiledExpression extends Expression { /** Source range. */ range: Range ) { - super(NodeKind.COMPILED, range); + super(NodeKind.Compiled, range); } } @@ -1607,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. */ @@ -1626,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)); let internalPath = mangleInternalPath(normalizedPath); this.internalPath = internalPath; let pos = internalPath.lastIndexOf(PATH_DELIMITER); @@ -1653,7 +1657,7 @@ export class Source extends Node { /** Checks if this source is part of the (standard) library. */ get isLibrary(): bool { let kind = this.sourceKind; - return kind == SourceKind.LIBRARY || kind == SourceKind.LIBRARY_ENTRY; + return kind == SourceKind.Library || kind == SourceKind.LibraryEntry; } /** Cached line starts. */ @@ -1672,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); } @@ -1736,7 +1740,7 @@ export class IndexSignatureNode extends Node { /** Source range. */ range: Range ) { - super(NodeKind.INDEXSIGNATURE, range); + super(NodeKind.IndexSignature, range); } } @@ -1770,7 +1774,7 @@ export class BlockStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.BLOCK, range); + super(NodeKind.Block, range); } } @@ -1782,7 +1786,7 @@ export class BreakStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.BREAK, range); + super(NodeKind.Break, range); } } @@ -1806,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. */ @@ -1826,21 +1830,21 @@ export class ContinueStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.CONTINUE, range); + super(NodeKind.Continue, range); } } /** 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. */ range: Range ) { - super(NodeKind.DO, range); + super(NodeKind.Do, range); } } @@ -1850,7 +1854,7 @@ export class EmptyStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EMPTY, range); + super(NodeKind.Empty, range); } } @@ -1868,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); } } @@ -1884,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); } } @@ -1898,7 +1902,7 @@ export class ExportImportStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTIMPORT, range); + super(NodeKind.ExportImport, range); } } @@ -1912,7 +1916,7 @@ export class ExportMember extends Node { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTMEMBER, range); + super(NodeKind.ExportMember, range); } } @@ -1928,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 @@ -1954,7 +1958,7 @@ export class ExportDefaultStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.EXPORTDEFAULT, range); + super(NodeKind.ExportDefault, range); } } @@ -1964,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); } } @@ -1986,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); } } @@ -1999,12 +2003,12 @@ 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 statement being looped over. */ + public body: Statement, /** Source range. */ range: Range ) { - super(NodeKind.FOR, range); + super(NodeKind.For, range); } } @@ -2015,23 +2019,23 @@ export class ForOfStatement extends Statement { public variable: Statement, /** Iterable expression being iterated. */ public iterable: Expression, - /** Statement being looped over. */ - public statement: Statement, + /** Body statement being looped over. */ + public body: 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. */ @@ -2054,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. */ @@ -2090,7 +2094,7 @@ export class IfStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.IF, range); + super(NodeKind.If, range); } } @@ -2104,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); } } @@ -2120,7 +2124,7 @@ export class ImportStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.IMPORT, range); + super(NodeKind.Import, range); let normalizedPath = normalizePath(path.value); if (path.value.startsWith(".")) { // relative in project normalizedPath = resolvePath(normalizedPath, range.source.internalPath); @@ -2155,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; } } @@ -2177,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; } } @@ -2196,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); } } @@ -2208,7 +2212,7 @@ export class ReturnStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.RETURN, range); + super(NodeKind.Return, range); } } @@ -2222,7 +2226,11 @@ export class SwitchCase extends Node { /** Source range. */ range: Range ) { - super(NodeKind.SWITCHCASE, range); + super(NodeKind.SwitchCase, range); + } + + get isDefault(): bool { + return this.label == null; } } @@ -2236,7 +2244,7 @@ export class SwitchStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.SWITCH, range); + super(NodeKind.Switch, range); } } @@ -2248,7 +2256,7 @@ export class ThrowStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.THROW, range); + super(NodeKind.Throw, range); } } @@ -2256,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. */ @@ -2266,7 +2274,7 @@ export class TryStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.TRY, range); + super(NodeKind.Try, range); } } @@ -2280,7 +2288,7 @@ export class ModuleDeclaration extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.MODULE, range); + super(NodeKind.Module, range); } } @@ -2300,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); } } @@ -2320,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); } } @@ -2334,7 +2342,7 @@ export class VariableStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.VARIABLE, range); + super(NodeKind.Variable, range); } } @@ -2346,7 +2354,7 @@ export class VoidStatement extends Statement { /** Source range. */ range: Range ) { - super(NodeKind.VOID, range); + super(NodeKind.Void, range); } } @@ -2355,12 +2363,12 @@ 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 ) { - super(NodeKind.WHILE, range); + super(NodeKind.While, range); } } @@ -2387,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 5d211c22c3..2eae3b3e3e 100644 --- a/src/bindings/js.ts +++ b/src/bindings/js.ts @@ -136,7 +136,7 @@ export class JSBuilder extends ExportsWalker { let sb = this.sb; let 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,20 +190,20 @@ 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 { 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,11 +222,11 @@ 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); - if (isPlainValue(type, Mode.IMPORT)) { + if (isPlainValue(type, Mode.Import)) { sb.push("(\n"); indent(sb, this.indentLevel + 1); sb.push("// "); @@ -268,10 +268,10 @@ 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) { + 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; let sb = this.sb; let 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]; @@ -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; @@ -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; } @@ -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) { @@ -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 { let parameterTypes = signature.parameterTypes; - let inverseMode = mode == Mode.IMPORT ? Mode.EXPORT : Mode.IMPORT; + let 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; } @@ -1355,7 +1355,7 @@ function indentText(text: string, indentLevel: i32, sb: string[], butFirst: bool let length = text.length; let 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 a7e4ffc51b..2969d2e5dc 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); @@ -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"); @@ -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 920d6344d3..212214c81e 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); } } @@ -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; let 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 88e40fae95..802724b7c4 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -924,7 +924,7 @@ function builtin_isDefined(ctx: BuiltinContext): ExpressionRef { ctx.operands[0], compiler.currentFlow, Type.auto, - ReportMode.SWALLOW + ReportMode.Swallow ); return module.i32(element ? 1 : 0); } @@ -969,7 +969,7 @@ function builtin_isVoid(ctx: BuiltinContext): ExpressionRef { let 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); @@ -1067,7 +1067,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 @@ -1078,7 +1078,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); } } @@ -1129,7 +1129,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( @@ -1154,18 +1154,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 ); let 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: @@ -1173,7 +1173,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, @@ -1196,13 +1196,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, @@ -1243,9 +1243,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( @@ -1327,20 +1327,20 @@ function builtin_clz(ctx: BuiltinContext): ExpressionRef { ) return module.unreachable(); let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -1364,20 +1364,20 @@ function builtin_ctz(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -1401,12 +1401,12 @@ function builtin_popcnt(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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: @@ -1415,8 +1415,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( @@ -1438,13 +1438,13 @@ function builtin_rotl(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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: @@ -1452,9 +1452,9 @@ function builtin_rotl(ctx: BuiltinContext): ExpressionRef { // (value << (shift & mask)) | (value >>> ((0 - shift) & mask)) 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); let ret = module.binary(BinaryOp.OrI32, module.binary( @@ -1487,8 +1487,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( @@ -1510,13 +1510,13 @@ function builtin_rotr(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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: @@ -1524,9 +1524,9 @@ function builtin_rotr(ctx: BuiltinContext): ExpressionRef { // (value >>> (shift & mask)) | (value << ((0 - shift) & mask)) 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); let ret = module.binary(BinaryOp.OrI32, module.binary( @@ -1559,8 +1559,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( @@ -1582,17 +1582,17 @@ function builtin_abs(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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: { @@ -1618,7 +1618,7 @@ function builtin_abs(ctx: BuiltinContext): ExpressionRef { ); return ret; } - case TypeKind.ISIZE: { + case TypeKind.Isize: { let options = compiler.options; let flow = compiler.currentFlow; @@ -1688,32 +1688,32 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef { let typeArguments = ctx.typeArguments; let left = operands[0]; let 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); let 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); } @@ -1721,9 +1721,9 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef { let flow = compiler.currentFlow; let typeRef = type.toRef(); 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); let ret = module.select( module.local_tee(temp1.index, arg0, false), // numeric module.local_tee(temp2.index, arg1, false), // numeric @@ -1756,32 +1756,32 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef { let typeArguments = ctx.typeArguments; let left = operands[0]; let 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); let 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); } @@ -1789,9 +1789,9 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef { let flow = compiler.currentFlow; let typeRef = type.toRef(); 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); let ret = module.select( module.local_tee(temp1.index, arg0, false), // numeric module.local_tee(temp2.index, arg1, false), // numeric @@ -1823,22 +1823,22 @@ function builtin_ceil(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -1862,22 +1862,22 @@ function builtin_floor(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -1901,11 +1901,11 @@ function builtin_copysign(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); @@ -1931,22 +1931,22 @@ function builtin_nearest(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -1974,22 +1974,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( @@ -2000,12 +2000,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); } @@ -2030,8 +2030,8 @@ function builtin_sqrt(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let type = compiler.currentType; if (type.isValue) { switch (type.kind) { @@ -2059,22 +2059,22 @@ function builtin_trunc(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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); } @@ -2101,7 +2101,7 @@ function builtin_isNaN(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let type = compiler.currentType; compiler.currentType = Type.bool; @@ -2112,12 +2112,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 @@ -2175,7 +2175,7 @@ function builtin_isFinite(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let type = compiler.currentType; compiler.currentType = Type.bool; @@ -2186,12 +2186,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 @@ -2278,7 +2278,7 @@ function builtin_load(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let numOperands = operands.length; let immOffset = 0; let immAlign = type.byteSize; @@ -2322,18 +2322,18 @@ function builtin_store(ctx: BuiltinContext): ExpressionRef { let typeArguments = ctx.typeArguments; let contextualType = ctx.contextualType; let type = typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let 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 ); let inType = compiler.currentType; if (!inType.isMemory) { @@ -2390,7 +2390,7 @@ function builtin_rem(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2406,14 +2406,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) { @@ -2444,7 +2444,7 @@ function builtin_add(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2460,14 +2460,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) { @@ -2498,7 +2498,7 @@ function builtin_sub(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2514,14 +2514,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) { @@ -2552,7 +2552,7 @@ function builtin_mul(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2568,14 +2568,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) { @@ -2606,7 +2606,7 @@ function builtin_div(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2622,14 +2622,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) { @@ -2660,7 +2660,7 @@ function builtin_eq(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2676,14 +2676,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) { @@ -2715,7 +2715,7 @@ function builtin_ne(ctx: BuiltinContext): ExpressionRef { ? compiler.compileExpression( left, typeArguments[0], - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ) : compiler.compileExpression(operands[0], Type.auto); let type = compiler.currentType; @@ -2731,14 +2731,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) { @@ -2763,7 +2763,7 @@ function builtin_atomic_load(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 2) ) return module.unreachable(); @@ -2784,7 +2784,7 @@ function builtin_atomic_load(ctx: BuiltinContext): ExpressionRef { compiler.currentType = outType; return module.unreachable(); } - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let immOffset = operands.length == 2 ? evaluateImmediateOffset(operands[1], compiler) : 0; // reports if (immOffset < 0) { compiler.currentType = outType; @@ -2805,7 +2805,7 @@ function builtin_atomic_store(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx) | checkArgsOptional(ctx, 2, 3) ) return module.unreachable(); @@ -2821,19 +2821,19 @@ function builtin_atomic_store(ctx: BuiltinContext): ExpressionRef { compiler.currentType = Type.void; return module.unreachable(); } - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let 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 ); let inType = compiler.currentType; if ( @@ -2862,7 +2862,7 @@ function builtin_atomic_binary(ctx: BuiltinContext, op: AtomicRMWOp, opName: str let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 2, 3) ) return module.unreachable(); @@ -2879,19 +2879,19 @@ function builtin_atomic_binary(ctx: BuiltinContext, op: AtomicRMWOp, opName: str } let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); let 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 ); let inType = compiler.currentType; if ( @@ -2955,7 +2955,7 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 4) ) return module.unreachable(); @@ -2972,24 +2972,24 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef { } let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); let 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 ); let inType = compiler.currentType; let arg2 = compiler.compileExpression(operands[2], inType, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); if ( type.isIntegerValue && @@ -3018,7 +3018,7 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeRequired(ctx) | checkArgsOptional(ctx, 2, 3) ) { @@ -3028,19 +3028,19 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let type = typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); let 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, @@ -3055,7 +3055,7 @@ function builtin_atomic_notify(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeAbsent(ctx) | checkArgsOptional(ctx, 1, 2) ) { @@ -3063,9 +3063,9 @@ function builtin_atomic_notify(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let 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); @@ -3078,7 +3078,7 @@ function builtin_atomic_fence(ctx: BuiltinContext): ExpressionRef { let module = compiler.module; compiler.currentType = Type.void; if ( - checkFeatureEnabled(ctx, Feature.THREADS) | + checkFeatureEnabled(ctx, Feature.Threads) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 0) ) return module.unreachable(); @@ -3099,17 +3099,17 @@ function builtin_select(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let 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); let 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(); } - let arg1 = compiler.compileExpression(operands[1], type, Constraints.CONV_IMPLICIT); + let arg1 = compiler.compileExpression(operands[1], type, Constraints.ConvImplicit); let arg2 = compiler.makeIsTrueish( compiler.compileExpression(operands[2], Type.bool), compiler.currentType, // ^ @@ -3152,7 +3152,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); @@ -3166,7 +3166,7 @@ function builtin_memory_copy(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 3) ) return module.unreachable(); let 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; @@ -3174,9 +3174,9 @@ function builtin_memory_copy(ctx: BuiltinContext): ExpressionRef { return compiler.compileCallDirect(instance, operands, ctx.reportNode); } let usizeType = compiler.options.usizeType; - let arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], usizeType, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], usizeType, Constraints.ConvImplicit); + let arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.ConvImplicit); compiler.currentType = Type.void; return module.memory_copy(arg0, arg1, arg2); } @@ -3192,7 +3192,7 @@ function builtin_memory_fill(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 3) ) return module.unreachable(); let 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; @@ -3200,9 +3200,9 @@ function builtin_memory_fill(ctx: BuiltinContext): ExpressionRef { return compiler.compileCallDirect(instance, operands, ctx.reportNode); } let usizeType = compiler.options.usizeType; - let arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], usizeType, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); + let arg2 = compiler.compileExpression(operands[2], usizeType, Constraints.ConvImplicit); compiler.currentType = Type.void; return module.memory_fill(arg0, arg1, arg2); } @@ -3234,7 +3234,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 @@ -3248,8 +3248,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; @@ -3281,7 +3281,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( @@ -3331,7 +3331,7 @@ function builtin_i31_new(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.i31ref; return module.i31_new(arg0); } @@ -3345,8 +3345,8 @@ function builtin_i31_get(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.i31ref, Constraints.CONV_IMPLICIT); - if (ctx.contextualType.is(TypeFlags.UNSIGNED)) { + let 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 { @@ -3401,8 +3401,8 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let contextualType = ctx.contextualType; let 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); let type = compiler.currentType; compiler.currentType = type.nonNullableType; @@ -3448,7 +3448,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: @@ -3457,29 +3457,28 @@ 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.ARRAYREF: - case TypeKind.I31REF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: 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.Arrayref: + 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; let flow = compiler.currentFlow; switch (compiler.currentType.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -3487,7 +3486,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), @@ -3507,8 +3506,8 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { ); 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( @@ -3544,17 +3543,17 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef { ); return ret; } - case TypeKind.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: - case TypeKind.EQREF: - case TypeKind.DATAREF: - case TypeKind.ARRAYREF: - case TypeKind.I31REF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.Dataref: + case TypeKind.Arrayref: + 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, @@ -3585,11 +3584,11 @@ function builtin_unchecked(ctx: BuiltinContext): ExpressionRef { checkArgsRequired(ctx, 1) ) return module.unreachable(); let flow = compiler.currentFlow; - let alreadyUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT); - flow.set(FlowFlags.UNCHECKED_CONTEXT); + let alreadyUnchecked = flow.is(FlowFlags.UncheckedContext); + flow.set(FlowFlags.UncheckedContext); // eliminate unnecessary tees by preferring contextualType(=void) let 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); @@ -3611,7 +3610,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { } else { returnType = ctx.contextualType; } - let indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + let indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.ConvImplicit); let numOperands = operands.length - 1; let operandExprs = new Array(numOperands); let paramTypeRefs = new Array(numOperands); @@ -3645,7 +3644,7 @@ function builtin_instantiate(ctx: BuiltinContext): ExpressionRef { compiler.currentType = classInstance.type; let 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); @@ -3666,26 +3665,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); @@ -3695,7 +3694,7 @@ builtins.set(BuiltinNames.INFO, builtin_info); function builtin_function_call(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let parent = ctx.prototype.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; assert(classInstance.prototype == compiler.program.functionPrototype); let typeArguments = assert(classInstance.typeArguments); @@ -3710,13 +3709,13 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { compiler.currentType = returnType; return compiler.module.unreachable(); } - let functionArg = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); + let functionArg = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.ConvImplicit); let thisOperand = assert(ctx.operands.shift()); let thisType = signature.thisType; let 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 @@ -3751,7 +3750,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 @@ -3845,7 +3844,7 @@ function builtin_i8x16(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 16) ) { @@ -3858,7 +3857,7 @@ function builtin_i8x16(ctx: BuiltinContext): ExpressionRef { let 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); @@ -3895,7 +3894,7 @@ function builtin_i16x8(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 8) ) { @@ -3908,7 +3907,7 @@ function builtin_i16x8(ctx: BuiltinContext): ExpressionRef { let 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); @@ -3945,7 +3944,7 @@ function builtin_i32x4(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 4) ) { @@ -3958,7 +3957,7 @@ function builtin_i32x4(ctx: BuiltinContext): ExpressionRef { let 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); @@ -3995,7 +3994,7 @@ function builtin_i64x2(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4008,7 +4007,7 @@ function builtin_i64x2(ctx: BuiltinContext): ExpressionRef { let 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; @@ -4047,7 +4046,7 @@ function builtin_f32x4(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 4) ) { @@ -4060,7 +4059,7 @@ function builtin_f32x4(ctx: BuiltinContext): ExpressionRef { let 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); @@ -4097,7 +4096,7 @@ function builtin_f64x2(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4110,7 +4109,7 @@ function builtin_f64x2(ctx: BuiltinContext): ExpressionRef { let 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); @@ -4147,7 +4146,7 @@ function builtin_v128_splat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -4157,7 +4156,7 @@ function builtin_v128_splat(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], type, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], type, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -4169,8 +4168,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 @@ -4195,15 +4194,15 @@ function builtin_v128_extract_lane(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsRequired(ctx, 2) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); compiler.currentType = type; let idx = 0; let precomp = module.runExpression(arg1, ExpressionRunnerFlags.PreserveSideeffects); @@ -4233,8 +4232,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 @@ -4259,7 +4258,7 @@ function builtin_v128_replace_lane(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 3) ) { @@ -4269,9 +4268,9 @@ function builtin_v128_replace_lane(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], type, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.u8, Constraints.ConvImplicit); + let arg2 = compiler.compileExpression(operands[2], type, Constraints.ConvImplicit); compiler.currentType = Type.v128; let idx = 0; let precomp = module.runExpression(arg1, ExpressionRunnerFlags.PreserveSideeffects); @@ -4301,8 +4300,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 @@ -4327,7 +4326,7 @@ function builtin_v128_shuffle(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) ) { compiler.currentType = Type.v128; @@ -4346,26 +4345,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) { @@ -4439,7 +4438,7 @@ function builtin_v128_swizzle(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4447,8 +4446,8 @@ function builtin_v128_swizzle(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let operands = ctx.operands; - 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); return module.binary(BinaryOp.SwizzleI8x16, arg0, arg1); } builtins.set(BuiltinNames.v128_swizzle, builtin_v128_swizzle); @@ -4458,14 +4457,14 @@ function builtin_v128_load_splat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let numOperands = operands.length; let immOffset = 0; let immAlign = type.byteSize; @@ -4499,8 +4498,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); } @@ -4526,14 +4525,14 @@ function builtin_v128_load_ext(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let numOperands = operands.length; let immOffset = 0; let immAlign = type.byteSize; @@ -4558,12 +4557,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 } @@ -4583,14 +4582,14 @@ function builtin_v128_load_zero(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 1, 3) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); let numOperands = operands.length; let immOffset = 0; let immAlign = type.byteSize; @@ -4617,8 +4616,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 @@ -4643,16 +4642,16 @@ function builtin_v128_load_lane(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 5) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); + let arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.ConvImplicit); let idx = 0; let precomp = module.runExpression(arg2, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { @@ -4701,8 +4700,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 @@ -4729,16 +4728,16 @@ function builtin_v128_store_lane(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx, true) | checkArgsOptional(ctx, 3, 5) ) return module.unreachable(); let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.ConvImplicit); + let arg2 = compiler.compileExpression(operands[2], Type.u8, Constraints.ConvImplicit); let idx = 0; let precomp = module.runExpression(arg2, ExpressionRunnerFlags.PreserveSideeffects); if (precomp) { @@ -4787,8 +4786,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 @@ -4815,7 +4814,7 @@ function builtin_v128_add(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4825,8 +4824,8 @@ function builtin_v128_add(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -4837,8 +4836,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 @@ -4863,7 +4862,7 @@ function builtin_v128_sub(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4873,8 +4872,8 @@ function builtin_v128_sub(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -4885,8 +4884,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 @@ -4911,7 +4910,7 @@ function builtin_v128_mul(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4921,8 +4920,8 @@ function builtin_v128_mul(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I16: @@ -4931,8 +4930,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); } @@ -4950,7 +4949,7 @@ function builtin_v128_div(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4960,8 +4959,8 @@ function builtin_v128_div(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.DivF32x4, arg0, arg1); @@ -4981,7 +4980,7 @@ function builtin_v128_add_sat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -4991,8 +4990,8 @@ function builtin_v128_add_sat(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.AddSatI8x16, arg0, arg1); @@ -5014,7 +5013,7 @@ function builtin_v128_sub_sat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5024,8 +5023,8 @@ function builtin_v128_sub_sat(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.SubSatI8x16, arg0, arg1); @@ -5047,7 +5046,7 @@ function builtin_v128_min(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5057,20 +5056,20 @@ function builtin_v128_min(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); 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 } @@ -5092,7 +5091,7 @@ function builtin_v128_max(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5102,20 +5101,20 @@ function builtin_v128_max(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); 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 } @@ -5137,7 +5136,7 @@ function builtin_v128_pmin(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5147,8 +5146,8 @@ function builtin_v128_pmin(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.PminF32x4, arg0, arg1); @@ -5168,7 +5167,7 @@ function builtin_v128_pmax(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5178,8 +5177,8 @@ function builtin_v128_pmax(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.binary(BinaryOp.PmaxF32x4, arg0, arg1); @@ -5199,7 +5198,7 @@ function builtin_v128_dot(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5209,8 +5208,8 @@ function builtin_v128_dot(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.DotI16x8, arg0, arg1); @@ -5229,7 +5228,7 @@ function builtin_v128_avgr(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5239,8 +5238,8 @@ function builtin_v128_avgr(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.U8: return module.binary(BinaryOp.AvgrU8x16, arg0, arg1); @@ -5260,7 +5259,7 @@ function builtin_v128_eq(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5270,8 +5269,8 @@ function builtin_v128_eq(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5282,8 +5281,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); } @@ -5301,7 +5300,7 @@ function builtin_v128_ne(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5311,8 +5310,8 @@ function builtin_v128_ne(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5323,8 +5322,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); } @@ -5342,7 +5341,7 @@ function builtin_v128_lt(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5352,8 +5351,8 @@ function builtin_v128_lt(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.LtI8x16, arg0, arg1); @@ -5364,8 +5363,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); } @@ -5386,7 +5385,7 @@ function builtin_v128_le(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5396,8 +5395,8 @@ function builtin_v128_le(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.LeI8x16, arg0, arg1); @@ -5408,8 +5407,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); } @@ -5430,7 +5429,7 @@ function builtin_v128_gt(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5440,8 +5439,8 @@ function builtin_v128_gt(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.GtI8x16, arg0, arg1); @@ -5452,8 +5451,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); } @@ -5474,7 +5473,7 @@ function builtin_v128_ge(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5484,8 +5483,8 @@ function builtin_v128_ge(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.GeI8x16, arg0, arg1); @@ -5496,8 +5495,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); } @@ -5518,7 +5517,7 @@ function builtin_v128_narrow(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -5528,8 +5527,8 @@ function builtin_v128_narrow(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.NarrowI16x8ToI8x16, arg0, arg1); @@ -5551,7 +5550,7 @@ function builtin_v128_neg(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5561,7 +5560,7 @@ function builtin_v128_neg(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.I8: @@ -5572,8 +5571,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 @@ -5598,7 +5597,7 @@ function builtin_v128_abs(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5608,19 +5607,19 @@ function builtin_v128_abs(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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); } @@ -5638,7 +5637,7 @@ function builtin_v128_sqrt(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5648,7 +5647,7 @@ function builtin_v128_sqrt(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.SqrtF32x4, arg0); @@ -5668,7 +5667,7 @@ function builtin_v128_ceil(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5678,7 +5677,7 @@ function builtin_v128_ceil(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.CeilF32x4, arg0); @@ -5698,7 +5697,7 @@ function builtin_v128_floor(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5708,7 +5707,7 @@ function builtin_v128_floor(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.FloorF32x4, arg0); @@ -5728,7 +5727,7 @@ function builtin_v128_trunc(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5738,7 +5737,7 @@ function builtin_v128_trunc(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.TruncF32x4, arg0); @@ -5758,7 +5757,7 @@ function builtin_v128_nearest(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5768,7 +5767,7 @@ function builtin_v128_nearest(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); if (type.isValue) { switch (type.kind) { case TypeKind.F32: return module.unary(UnaryOp.NearestF32x4, arg0); @@ -5788,7 +5787,7 @@ function builtin_v128_convert(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5798,15 +5797,15 @@ function builtin_v128_convert(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -5826,7 +5825,7 @@ function builtin_v128_convert_low(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5836,15 +5835,15 @@ function builtin_v128_convert_low(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -5864,7 +5863,7 @@ function builtin_v128_trunc_sat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5874,15 +5873,15 @@ function builtin_v128_trunc_sat(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -5902,7 +5901,7 @@ function builtin_v128_trunc_sat_zero(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5912,15 +5911,15 @@ function builtin_v128_trunc_sat_zero(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -5940,7 +5939,7 @@ function builtin_v128_extend_low(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5950,19 +5949,19 @@ function builtin_v128_extend_low(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -5982,7 +5981,7 @@ function builtin_v128_extend_high(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -5992,19 +5991,19 @@ function builtin_v128_extend_high(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let 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 } @@ -6024,7 +6023,7 @@ function builtin_v128_shl(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6033,8 +6032,8 @@ function builtin_v128_shl(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6046,8 +6045,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 @@ -6070,7 +6069,7 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6079,8 +6078,8 @@ function builtin_v128_shr(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); + let arg1 = compiler.compileExpression(operands[1], Type.i32, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6092,7 +6091,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 @@ -6100,7 +6099,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 @@ -6122,7 +6121,7 @@ function builtin_v128_bitwise_binary(ctx: BuiltinContext, op: BinaryOp): Express let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6130,8 +6129,8 @@ function builtin_v128_bitwise_binary(ctx: BuiltinContext, op: BinaryOp): Express return module.unreachable(); } let operands = ctx.operands; - 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); return module.binary(op, arg0, arg1); } @@ -6163,7 +6162,7 @@ function builtin_v128_bitwise_unary(ctx: BuiltinContext, op: UnaryOp): Expressio let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6171,7 +6170,7 @@ function builtin_v128_bitwise_unary(ctx: BuiltinContext, op: UnaryOp): Expressio return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); return module.unary(op, arg0); } @@ -6185,7 +6184,7 @@ function builtin_v128_bitwise_ternary(ctx: BuiltinContext, op: SIMDTernaryOp): E let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 3) ) { @@ -6193,9 +6192,9 @@ function builtin_v128_bitwise_ternary(ctx: BuiltinContext, op: SIMDTernaryOp): E return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT); - let arg2 = compiler.compileExpression(operands[2], 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); + let arg2 = compiler.compileExpression(operands[2], Type.v128, Constraints.ConvImplicit); return module.simd_ternary(op, arg0, arg1, arg2); } @@ -6210,7 +6209,7 @@ function builtin_v128_any_true(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeAbsent(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6218,7 +6217,7 @@ function builtin_v128_any_true(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.bool; return module.unary(UnaryOp.AnyTrueV128, arg0); } @@ -6229,7 +6228,7 @@ function builtin_v128_all_true(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6238,7 +6237,7 @@ function builtin_v128_all_true(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.bool; if (type.isValue) { switch (type.kind) { @@ -6250,8 +6249,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 @@ -6274,7 +6273,7 @@ function builtin_v128_bitmask(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6283,7 +6282,7 @@ function builtin_v128_bitmask(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.i32; if (type.isValue) { switch (type.kind) { @@ -6295,8 +6294,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 @@ -6319,7 +6318,7 @@ function builtin_v128_popcnt(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6328,7 +6327,7 @@ function builtin_v128_popcnt(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6349,7 +6348,7 @@ function builtin_v128_extadd_pairwise(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6358,7 +6357,7 @@ function builtin_v128_extadd_pairwise(ctx: BuiltinContext): ExpressionRef { } let operands = ctx.operands; let type = ctx.typeArguments![0]; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6381,7 +6380,7 @@ function builtin_v128_demote_zero(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeOptional(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6391,7 +6390,7 @@ function builtin_v128_demote_zero(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let type = typeArguments ? typeArguments[0] : Type.f64; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6411,7 +6410,7 @@ function builtin_v128_promote_low(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeOptional(ctx) | checkArgsRequired(ctx, 1) ) { @@ -6421,7 +6420,7 @@ function builtin_v128_promote_low(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments; let type = typeArguments ? typeArguments[0] : Type.f32; - let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.ConvImplicit); compiler.currentType = Type.v128; if (type.isValue) { switch (type.kind) { @@ -6441,7 +6440,7 @@ function builtin_v128_q15mulr_sat(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6451,8 +6450,8 @@ function builtin_v128_q15mulr_sat(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I16: return module.binary(BinaryOp.Q15mulrSatI16x8, arg0, arg1); @@ -6471,7 +6470,7 @@ function builtin_v128_extmul_low(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6481,8 +6480,8 @@ function builtin_v128_extmul_low(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.ExtmulLowI16x8, arg0, arg1); @@ -6506,7 +6505,7 @@ function builtin_v128_extmul_high(ctx: BuiltinContext): ExpressionRef { let compiler = ctx.compiler; let module = compiler.module; if ( - checkFeatureEnabled(ctx, Feature.SIMD) | + checkFeatureEnabled(ctx, Feature.Simd) | checkTypeRequired(ctx) | checkArgsRequired(ctx, 2) ) { @@ -6516,8 +6515,8 @@ function builtin_v128_extmul_high(ctx: BuiltinContext): ExpressionRef { let operands = ctx.operands; let typeArguments = ctx.typeArguments!; let type = typeArguments[0]; - 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); if (type.isValue) { switch (type.kind) { case TypeKind.I8: return module.binary(BinaryOp.ExtmulHighI16x8, arg0, arg1); @@ -6550,7 +6549,7 @@ function builtin_visit_globals(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + let 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); @@ -6569,8 +6568,8 @@ function builtin_visit_members(ctx: BuiltinContext): ExpressionRef { return module.unreachable(); } let operands = ctx.operands; - let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.CONV_IMPLICIT); - let arg1 = compiler.compileExpression(operands[1], Type.u32, Constraints.CONV_IMPLICIT); + let arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType, Constraints.ConvImplicit); + let 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); @@ -10150,16 +10149,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( @@ -10227,7 +10226,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( @@ -10262,7 +10261,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) { @@ -10388,10 +10387,10 @@ export function compileVisitMembers(compiler: Compiler): void { function typeToRuntimeFlags(type: Type): TypeinfoFlags { let 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; } @@ -10436,7 +10435,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(); @@ -10548,7 +10547,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); } @@ -10584,7 +10583,7 @@ function evaluateImmediateOffset(expression: Expression, compiler: Compiler): i3 let module = compiler.module; let 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 @@ -10597,7 +10596,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 72eb68fb2d..6206dad9f0 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 a3673f17de..fd0ac005bc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -222,8 +222,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. */ @@ -257,10 +257,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. */ @@ -289,22 +289,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. */ @@ -320,34 +320,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. */ @@ -414,7 +414,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. */ @@ -459,21 +459,21 @@ export class Compiler extends DiagnosticEmitter { } } let 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.RELAXED_SIMD)) featureFlags |= FeatureFlags.RelaxedSIMD; - if (options.hasFeature(Feature.EXTENDED_CONST)) featureFlags |= FeatureFlags.ExtendedConst; - if (options.hasFeature(Feature.STRINGREF)) featureFlags |= FeatureFlags.Stringref; + 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; module.setFeatures(featureFlags); // set up the main start function @@ -517,7 +517,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); } @@ -568,8 +568,8 @@ export class Compiler extends DiagnosticEmitter { let 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); @@ -598,7 +598,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); @@ -606,7 +606,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)) @@ -620,7 +620,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 @@ -638,7 +638,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)) @@ -761,7 +761,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 @@ -887,10 +887,10 @@ export class Compiler extends DiagnosticEmitter { private compileModuleExport(name: string, element: DeclaredElement, prefix: string = ""): void { let 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); @@ -899,9 +899,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 @@ -909,7 +909,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); @@ -941,10 +941,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" @@ -952,7 +952,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); @@ -960,7 +960,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; } @@ -979,7 +979,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - case ElementKind.ENUM: { + case ElementKind.Enum: { this.compileEnum(element); let members = element.members; if (members) { @@ -987,23 +987,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); @@ -1042,8 +1042,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 let startFunction = file.startFunction; @@ -1088,8 +1088,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); let pendingElements = this.pendingElements; pendingElements.add(global); @@ -1099,13 +1099,13 @@ export class Compiler extends DiagnosticEmitter { let typeNode = global.typeNode; let 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; } @@ -1114,7 +1114,7 @@ export class Compiler extends DiagnosticEmitter { DiagnosticCode.Type_expected, typeNode.range ); - global.set(CommonFlags.ERRORED); + global.set(CommonFlags.Errored); pendingElements.delete(global); return false; } @@ -1124,11 +1124,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) { @@ -1136,7 +1136,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; } @@ -1148,33 +1148,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; } let type = global.type; let typeRef = type.toRef(); - let isDeclaredConstant = global.is(CommonFlags.CONST) || global.is(CommonFlags.STATIC | CommonFlags.READONLY); - let isDeclaredInline = global.hasDecorator(DecoratorFlags.INLINE); + let isDeclaredConstant = global.is(CommonFlags.Const) || global.is(CommonFlags.Static | CommonFlags.Readonly); + let 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( @@ -1196,7 +1196,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; } @@ -1209,11 +1209,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; } @@ -1239,7 +1239,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; } } } @@ -1256,12 +1256,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) @@ -1269,30 +1269,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); } @@ -1304,7 +1304,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)); @@ -1322,8 +1322,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); let pendingElements = this.pendingElements; pendingElements.add(element); @@ -1333,33 +1333,33 @@ export class Compiler extends DiagnosticEmitter { this.currentParent = element; let previousValue: EnumValue | null = null; let previousValueIsMut = false; - let isInline = element.is(CommonFlags.CONST) || element.hasDecorator(DecoratorFlags.INLINE); + let isInline = element.is(CommonFlags.Const) || element.hasDecorator(DecoratorFlags.Inline); let 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 @@ -1390,7 +1390,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 @@ -1410,7 +1410,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 { @@ -1436,11 +1436,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; } @@ -1466,7 +1466,7 @@ export class Compiler extends DiagnosticEmitter { } } - instance.set(CommonFlags.COMPILED); + instance.set(CommonFlags.Compiled); let pendingElements = this.pendingElements; pendingElements.add(instance); @@ -1475,7 +1475,7 @@ export class Compiler extends DiagnosticEmitter { let signature = instance.signature; let bodyNode = instance.prototype.bodyNode; let 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); let funcRef: FunctionRef; @@ -1484,7 +1484,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 @@ -1492,16 +1492,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" @@ -1531,7 +1531,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( @@ -1561,7 +1561,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, @@ -1575,10 +1575,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) { @@ -1620,42 +1620,42 @@ export class Compiler extends DiagnosticEmitter { let 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(); @@ -1671,7 +1671,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, @@ -1682,7 +1682,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 @@ -1690,15 +1690,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 @@ -1706,7 +1706,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 @@ -1721,7 +1721,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. */ @@ -1739,7 +1739,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); @@ -1762,7 +1762,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); @@ -1776,11 +1776,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); @@ -1964,7 +1968,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)); let program = this.program; let memorySegment = instance.memorySegment; if (!memorySegment) { @@ -1991,22 +1995,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) { @@ -2021,28 +2025,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) { @@ -2050,20 +2054,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); @@ -2082,72 +2086,72 @@ export class Compiler extends DiagnosticEmitter { let module = this.module; let 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, @@ -2157,7 +2161,7 @@ export class Compiler extends DiagnosticEmitter { stmt = module.unreachable(); break; } - case NodeKind.MODULE: { + case NodeKind.Module: { stmt = module.nop(); break; } @@ -2199,7 +2203,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; } @@ -2243,7 +2247,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - flow.set(FlowFlags.BREAKS); + flow.set(FlowFlags.Breaks); return module.br(breakLabel); } @@ -2270,7 +2274,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - flow.set(FlowFlags.CONTINUES | FlowFlags.TERMINATES); + flow.set(FlowFlags.Continues | FlowFlags.Terminates); return module.br(continueLabel); } @@ -2316,16 +2320,16 @@ export class Compiler extends DiagnosticEmitter { let bodyFlow = flow.fork(); this.currentFlow = bodyFlow; let bodyStmts = new Array(); - let body = statement.statement; - if (body.kind == NodeKind.BLOCK) { + let body = statement.body; + if (body.kind == NodeKind.Block) { this.compileStatements((body).statements, false, bodyStmts); } else { bodyStmts.push(this.compileStatement(body)); } // Shortcut if body never falls through - let possiblyContinues = bodyFlow.isAny(FlowFlags.CONTINUES | FlowFlags.CONDITIONALLY_CONTINUES); - if (bodyFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS) && !possiblyContinues) { + let possiblyContinues = bodyFlow.isAny(FlowFlags.Continues | FlowFlags.ConditionallyContinues); + if (bodyFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks) && !possiblyContinues) { bodyStmts.push( module.unreachable() ); @@ -2349,21 +2353,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( @@ -2393,7 +2397,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; @@ -2408,7 +2412,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( @@ -2460,8 +2464,8 @@ export class Compiler extends DiagnosticEmitter { let 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)); } @@ -2481,7 +2485,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) ); @@ -2493,7 +2497,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 @@ -2513,18 +2517,18 @@ export class Compiler extends DiagnosticEmitter { bodyFlow.inheritNonnullIfTrue(condExpr); this.currentFlow = bodyFlow; let bodyStmts = new Array(); - let body = statement.statement; - if (body.kind == NodeKind.BLOCK) { + let body = statement.body; + 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); let ifStmts = new Array(); @@ -2534,13 +2538,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) ); flow.inherit(incrFlow); // mostly local flags, also covers late termination by throwing this.currentFlow = flow; @@ -2577,7 +2581,7 @@ export class Compiler extends DiagnosticEmitter { // Finalize outerFlow.inherit(flow); outerFlow.popBreakLabel(); - if (outerFlow.is(FlowFlags.TERMINATES)) { + if (outerFlow.is(FlowFlags.Terminates)) { stmts.push(module.unreachable()); } this.currentFlow = outerFlow; @@ -2625,13 +2629,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), @@ -2650,12 +2654,12 @@ export class Compiler extends DiagnosticEmitter { let 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)); } - let thenTerminates = thenFlow.isAny(FlowFlags.TERMINATES | FlowFlags.BREAKS); + let thenTerminates = thenFlow.isAny(FlowFlags.Terminates | FlowFlags.Breaks); if (thenTerminates) { thenStmts.push(module.unreachable()); } @@ -2667,12 +2671,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()); } @@ -2685,7 +2689,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 ); @@ -2706,14 +2710,14 @@ export class Compiler extends DiagnosticEmitter { let valueExpression = statement.value; if (valueExpression) { - let constraints = Constraints.CONV_IMPLICIT; - if (flow.sourceFunction.is(CommonFlags.MODULE_EXPORT)) constraints |= Constraints.MUST_WRAP; + let constraints = Constraints.ConvImplicit; + if (flow.sourceFunction.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.sourceFunction.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.sourceFunction.is(CommonFlags.Constructor) && valueExpression.kind != NodeKind.This) { + flow.set(FlowFlags.MayReturnNonThis); } } else if (returnType != Type.void) { this.error( @@ -2725,7 +2729,7 @@ export class Compiler extends DiagnosticEmitter { } // Remember that this flow returns - flow.set(FlowFlags.RETURNS | FlowFlags.TERMINATES); + flow.set(FlowFlags.Returns | FlowFlags.Terminates); // Handle inline return if (flow.isInline) { @@ -2761,7 +2765,7 @@ export class Compiler extends DiagnosticEmitter { let numCases = cases.length; if (!numCases) { return this.compileExpression(statement.condition, Type.void, - Constraints.CONV_IMPLICIT + Constraints.ConvImplicit ); } @@ -2778,7 +2782,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 ); @@ -2794,7 +2798,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 ) ) ); @@ -2811,7 +2815,7 @@ export class Compiler extends DiagnosticEmitter { // nest blocks in order let currentBlock = module.block(`case0|${context}`, breaks, TypeRef.None); - let commonCategorical = FlowFlags.ANY_CATEGORICAL; + let commonCategorical = FlowFlags.AnyCategorical; let commonConditional = 0; for (let i = 0; i < numCases; ++i) { let case_ = cases[i]; @@ -2835,13 +2839,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; } @@ -2849,8 +2853,8 @@ export class Compiler extends DiagnosticEmitter { // Switch back to the parent flow innerFlow.unset( - FlowFlags.BREAKS | - FlowFlags.CONDITIONALLY_BREAKS + FlowFlags.Breaks | + FlowFlags.ConditionallyBreaks ); this.currentFlow = outerFlow; currentBlock = module.block(nextLabel, stmts, TypeRef.None); // must be a labeled block @@ -2858,8 +2862,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; } @@ -2871,12 +2875,12 @@ export class Compiler extends DiagnosticEmitter { let flow = this.currentFlow; // Remember that this branch throws - flow.set(FlowFlags.THROWS | FlowFlags.TERMINATES); + flow.set(FlowFlags.Throws | FlowFlags.Terminates); let stmts = new Array(); let value = statement.value; let 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 } @@ -2933,7 +2937,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); @@ -2967,7 +2971,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) { @@ -3039,7 +3043,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); @@ -3061,7 +3065,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) { @@ -3075,7 +3079,7 @@ export class Compiler extends DiagnosticEmitter { } local = flow.targetFunction.addLocal(type, name, declaration); flow.unsetLocalFlag(local.index, ~0); - if (isConst) flow.setLocalFlag(local.index, LocalFlags.CONSTANT); + if (isConst) flow.setLocalFlag(local.index, LocalFlags.Constant); } if (initExpr) { initializers.push( @@ -3084,7 +3088,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); } } } @@ -3099,7 +3103,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 ); } @@ -3152,7 +3156,7 @@ export class Compiler extends DiagnosticEmitter { let 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) ); @@ -3177,30 +3181,30 @@ export class Compiler extends DiagnosticEmitter { bodyFlow.inheritNonnullIfTrue(condExpr); this.currentFlow = bodyFlow; let bodyStmts = new Array(); - let body = statement.statement; - if (body.kind == NodeKind.BLOCK) { + let body = statement.body; + 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() @@ -3210,7 +3214,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 @@ -3239,7 +3243,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; @@ -3253,13 +3257,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)); let 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 @@ -3269,7 +3273,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 @@ -3278,7 +3282,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 @@ -3286,16 +3290,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 ); @@ -3304,7 +3308,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) @@ -3313,7 +3317,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 @@ -3332,83 +3336,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; let 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, @@ -3425,12 +3429,12 @@ export class Compiler extends DiagnosticEmitter { } // ensure conversion and wrapping in case the respective function doesn't on its own let currentType = this.currentType; - let wrap = (constraints & Constraints.MUST_WRAP) != 0; + let 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; } @@ -3456,8 +3460,8 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { let 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; @@ -3471,7 +3475,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) { @@ -3578,14 +3582,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 { @@ -3598,14 +3602,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 { @@ -3616,7 +3620,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); } @@ -3712,10 +3716,10 @@ export class Compiler extends DiagnosticEmitter { contextualType: Type, constraints: Constraints ): ExpressionRef { - let inheritedConstraints = constraints & ~(Constraints.CONV_IMPLICIT | Constraints.CONV_EXPLICIT); + let 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), @@ -3723,9 +3727,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; @@ -3740,13 +3744,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); @@ -3792,14 +3796,14 @@ export class Compiler extends DiagnosticEmitter { let operator = expression.operator; switch (operator) { - case Token.LESSTHAN: { + case Token.LessThan: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -3827,14 +3831,14 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.GREATERTHAN: { + case Token.GreaterThan: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -3862,14 +3866,14 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.LESSTHAN_EQUALS: { + case Token.LessThan_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -3897,14 +3901,14 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.GREATERTHAN_EQUALS: { + case Token.GreaterThan_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -3933,15 +3937,15 @@ export class Compiler extends DiagnosticEmitter { break; } - case Token.EQUALS_EQUALS_EQUALS: - case Token.EQUALS_EQUALS: { + case Token.Equals_Equals_Equals: + case Token.Equals_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -3985,15 +3989,15 @@ export class Compiler extends DiagnosticEmitter { this.currentType = Type.bool; break; } - case Token.EXCLAMATION_EQUALS_EQUALS: - case Token.EXCLAMATION_EQUALS: { + case Token.Exclamation_Equals_Equals: + case Token.Exclamation_Equals: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4037,18 +4041,18 @@ 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.Plus_Equals: compound = true; + case Token.Plus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4062,7 +4066,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); @@ -4084,15 +4088,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAdd(leftExpr, rightExpr, commonType); break; } - case Token.MINUS_EQUALS: compound = true; - case Token.MINUS: { + case Token.Minus_Equals: compound = true; + case Token.Minus: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4107,7 +4111,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); @@ -4129,15 +4133,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeSub(leftExpr, rightExpr, commonType); break; } - case Token.ASTERISK_EQUALS: compound = true; - case Token.ASTERISK: { + case Token.Asterisk_Equals: compound = true; + case Token.Asterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4152,7 +4156,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); @@ -4174,15 +4178,15 @@ 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.Asterisk_Asterisk_Equals: compound = true; + case Token.Asterisk_Asterisk: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4197,7 +4201,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); @@ -4219,15 +4223,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makePow(leftExpr, rightExpr, commonType, expression); break; } - case Token.SLASH_EQUALS: compound = true; - case Token.SLASH: { + case Token.Slash_Equals: compound = true; + case Token.Slash: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4242,7 +4246,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); @@ -4264,15 +4268,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeDiv(leftExpr, rightExpr, commonType); break; } - case Token.PERCENT_EQUALS: compound = true; - case Token.PERCENT: { + case Token.Percent_Equals: compound = true; + case Token.Percent: { leftExpr = this.compileExpression(left, contextualType); leftType = this.currentType; // 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; @@ -4287,7 +4291,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); @@ -4309,15 +4313,15 @@ 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.LessThan_LessThan_Equals: compound = true; + case Token.LessThan_LessThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4330,21 +4334,21 @@ 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); break; } - case Token.GREATERTHAN_GREATERTHAN_EQUALS: compound = true; - case Token.GREATERTHAN_GREATERTHAN: { + case Token.GreaterThan_GreaterThan_Equals: compound = true; + case Token.GreaterThan_GreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4358,21 +4362,21 @@ 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); break; } - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: compound = true; - case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: { + case Token.GreaterThan_GreaterThan_GreaterThan_Equals: compound = true; + case Token.GreaterThan_GreaterThan_GreaterThan: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4385,21 +4389,21 @@ 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); break; } - case Token.AMPERSAND_EQUALS: compound = true; - case Token.AMPERSAND: { + case Token.Ampersand_Equals: compound = true; + case Token.Ampersand: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4414,7 +4418,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); @@ -4436,15 +4440,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeAnd(leftExpr, rightExpr, commonType); break; } - case Token.BAR_EQUALS: compound = true; - case Token.BAR: { + case Token.Bar_Equals: compound = true; + case Token.Bar: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4459,7 +4463,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); @@ -4481,15 +4485,15 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeOr(leftExpr, rightExpr, commonType); break; } - case Token.CARET_EQUALS: compound = true; - case Token.CARET: { + case Token.Caret_Equals: compound = true; + case Token.Caret: { leftExpr = this.compileExpression(left, contextualType.intType); leftType = this.currentType; // 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; @@ -4504,7 +4508,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); @@ -4529,9 +4533,9 @@ export class Compiler extends DiagnosticEmitter { // logical (no overloading) - case Token.AMPERSAND_AMPERSAND: { // left && right -> (t = left) ? right : t + 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; @@ -4545,7 +4549,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); @@ -4553,7 +4557,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)); @@ -4563,7 +4567,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; this.currentFlow = flow; @@ -4578,8 +4582,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, @@ -4590,9 +4594,9 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.BAR_BAR: { // left || right -> ((t = left) ? t : right) + 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; @@ -4606,7 +4610,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); @@ -4614,7 +4618,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); @@ -4624,7 +4628,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; this.currentFlow = flow; @@ -4639,11 +4643,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 ); } @@ -4692,8 +4697,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); @@ -4702,7 +4707,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); } @@ -4722,8 +4727,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); @@ -4732,7 +4737,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); } @@ -4752,8 +4757,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); @@ -4762,7 +4767,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); } @@ -4782,8 +4787,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); @@ -4792,7 +4797,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); } @@ -4804,7 +4809,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4817,8 +4822,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: { @@ -4826,17 +4831,17 @@ export class Compiler extends DiagnosticEmitter { module.binary(BinaryOp.EqI8x16, leftExpr, rightExpr) ); } - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: - case TypeKind.ARRAYREF: 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.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: { + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: + case TypeKind.Arrayref: return module.ref_eq(leftExpr, rightExpr); + 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: { this.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, reportNode.range, @@ -4854,7 +4859,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4867,8 +4872,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: { @@ -4876,25 +4881,25 @@ export class Compiler extends DiagnosticEmitter { module.binary(BinaryOp.NeI8x16, leftExpr, rightExpr) ); } - case TypeKind.EQREF: - case TypeKind.I31REF: - case TypeKind.DATAREF: - case TypeKind.ARRAYREF: { + case TypeKind.Eqref: + case TypeKind.I31ref: + case TypeKind.Dataref: + case TypeKind.Arrayref: { return module.unary(UnaryOp.EqzI32, 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.FUNCREF: - case TypeKind.EXTERNREF: - case TypeKind.ANYREF: { + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + case TypeKind.StringviewIter: + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: { this.error( DiagnosticCode.Operation_0_cannot_be_applied_to_type_1, reportNode.range, @@ -4912,7 +4917,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4921,8 +4926,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); } @@ -4934,7 +4939,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4943,8 +4948,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); } @@ -4956,7 +4961,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -4965,8 +4970,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); } @@ -4978,7 +4983,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)), @@ -5022,7 +5027,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)) { @@ -5062,7 +5067,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)) { @@ -5070,8 +5075,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 @@ -5112,7 +5117,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; @@ -5158,7 +5163,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)) { @@ -5200,7 +5205,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)) { @@ -5225,8 +5230,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); @@ -5235,7 +5240,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); } @@ -5255,8 +5260,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); @@ -5265,7 +5270,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) { @@ -5286,7 +5291,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)) { @@ -5314,7 +5319,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)) { @@ -5331,7 +5336,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits on the RHS, but only for types smaller than 5 bits let 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: @@ -5351,8 +5356,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(); @@ -5363,7 +5368,7 @@ export class Compiler extends DiagnosticEmitter { // and signedness let 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)) @@ -5392,10 +5397,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(); @@ -5405,7 +5410,7 @@ export class Compiler extends DiagnosticEmitter { // Cares about garbage bits on the LHS, but on the RHS only for types smaller than 5 bits let 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: @@ -5425,8 +5430,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(); @@ -5436,7 +5441,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -5445,8 +5450,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(); @@ -5456,7 +5461,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5465,8 +5470,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(); @@ -5476,7 +5481,7 @@ export class Compiler extends DiagnosticEmitter { // Does not care about garbage bits or signedness let module = this.module; switch (type.kind) { - case TypeKind.BOOL: + case TypeKind.Bool: case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: @@ -5485,8 +5490,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(); @@ -5514,14 +5519,14 @@ export class Compiler extends DiagnosticEmitter { let rightType: Type; let signature = operatorInstance.signature; let 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]; } - let rightExpr = this.compileExpression(right, rightType, Constraints.CONV_IMPLICIT); + let rightExpr = this.compileExpression(right, rightType, Constraints.ConvImplicit); return this.makeCallDirect(operatorInstance, [ leftExpr, rightExpr ], reportNode); } @@ -5541,13 +5546,13 @@ export class Compiler extends DiagnosticEmitter { // to compile just the value, we need to know the target's type let 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, @@ -5557,17 +5562,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) { @@ -5579,17 +5584,17 @@ 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 indexedSet = classInstance.lookupOverload(OperatorKind.INDEXED_SET, isUnchecked); + let isUnchecked = flow.is(FlowFlags.UncheckedContext); + 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, @@ -5608,7 +5613,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, @@ -5662,9 +5667,9 @@ export class Compiler extends DiagnosticEmitter { let 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 @@ -5674,10 +5679,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, @@ -5688,13 +5693,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.sourceFunction.is(CommonFlags.CONSTRUCTOR); + let isConstructor = flow.sourceFunction.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, @@ -5706,24 +5711,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) { @@ -5734,12 +5739,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); @@ -5766,14 +5771,14 @@ 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); - let getterInstance = classInstance.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + assert(classInstance.kind == ElementKind.Class); + let isUnchecked = flow.is(FlowFlags.UncheckedContext); + let getterInstance = classInstance.lookupOverload(OperatorKind.IndexedGet, isUnchecked); if (!getterInstance) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, @@ -5781,7 +5786,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, @@ -5795,7 +5800,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]; @@ -5809,7 +5814,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); @@ -5863,13 +5868,13 @@ export class Compiler extends DiagnosticEmitter { let 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; @@ -5928,11 +5933,11 @@ export class Compiler extends DiagnosticEmitter { let flow = this.currentFlow; let fieldType = field.type; let fieldTypeRef = fieldType.toRef(); - assert(field.parent.kind == ElementKind.CLASS); + assert(field.parent.kind == ElementKind.Class); let 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); } @@ -5968,10 +5973,10 @@ export class Compiler extends DiagnosticEmitter { let flow = this.currentFlow; // handle call to super - if (expression.expression.kind == NodeKind.SUPER) { + if (expression.expression.kind == NodeKind.Super) { let flow = this.currentFlow; let sourceFunction = flow.sourceFunction; - if (!sourceFunction.is(CommonFlags.CONSTRUCTOR)) { + if (!sourceFunction.is(CommonFlags.Constructor)) { this.error( DiagnosticCode.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors, expression.range @@ -5980,7 +5985,7 @@ export class Compiler extends DiagnosticEmitter { } let parent = assert(sourceFunction.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let baseClassInstance = classInstance.base; if (!baseClassInstance) { @@ -6004,8 +6009,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, @@ -6013,7 +6018,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); } @@ -6028,9 +6033,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); } @@ -6039,14 +6044,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( @@ -6059,7 +6064,7 @@ 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) { @@ -6072,7 +6077,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)); @@ -6091,7 +6096,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.unreachable(); } - case ElementKind.GLOBAL: { + case ElementKind.Global: { let global = target; signature = global.type.signatureReference; if (signature) { @@ -6104,19 +6109,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 @@ -6130,13 +6135,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)); @@ -6150,11 +6155,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); @@ -6168,13 +6173,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 @@ -6220,7 +6225,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. let call = this._reusableCallExpression; @@ -6241,7 +6246,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); let typeArguments: Type[] | null = null; @@ -6250,7 +6255,7 @@ export class Compiler extends DiagnosticEmitter { let typeParameterNodes = prototype.typeParameterNodes; let 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 @@ -6270,7 +6275,7 @@ export class Compiler extends DiagnosticEmitter { prototype, typeArguments, expression.args, - callee.kind == NodeKind.PROPERTYACCESS + callee.kind == NodeKind.PropertyAccess ? (callee).expression : null, contextualType, @@ -6285,7 +6290,7 @@ export class Compiler extends DiagnosticEmitter { } // class builtins let 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; @@ -6380,7 +6385,7 @@ export class Compiler extends DiagnosticEmitter { argumentExpressions: Expression[], reportNode: Node, thisArg: ExpressionRef = 0, - constraints: Constraints = Constraints.NONE + constraints: Constraints = Constraints.None ): ExpressionRef { let numArguments = argumentExpressions.length; let signature = instance.signature; @@ -6393,19 +6398,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 sourceFunction = this.currentFlow.sourceFunction; - if (sourceFunction.is(CommonFlags.CONSTRUCTOR) && reportNode.isAccessOnThis) { + if (sourceFunction.is(CommonFlags.Constructor) && reportNode.isAccessOnThis) { let parent = sourceFunction.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( @@ -6419,11 +6424,11 @@ export class Compiler extends DiagnosticEmitter { // otherwise, the arguments may not be inlined, e.g. `abc(abc(123))` 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 inlineStack.push(instance); - 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; } @@ -6440,11 +6445,11 @@ export class Compiler extends DiagnosticEmitter { let 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( @@ -6466,7 +6471,7 @@ export class Compiler extends DiagnosticEmitter { 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); @@ -6483,8 +6488,8 @@ export class Compiler extends DiagnosticEmitter { let paramType = parameterTypes[i]; let argumentLocal = flow.addScopedLocal(instance.getParameterName(i), paramType); // 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.push( module.local_set(argumentLocal.index, paramExpr, paramType.isManaged) ); @@ -6493,21 +6498,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; - let isConstructor = instance.is(CommonFlags.CONSTRUCTOR); - if (isConstructor) flow.set(FlowFlags.CTORPARAM_CONTEXT); + let 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); @@ -6515,7 +6520,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); } @@ -6552,7 +6557,7 @@ export class Compiler extends DiagnosticEmitter { let originalParameterTypes = originalSignature.parameterTypes; let originalParameterDeclarations = original.prototype.functionTypeNode.parameters; let returnType = originalSignature.returnType; - let isInstance = original.is(CommonFlags.INSTANCE); + let isInstance = original.is(CommonFlags.Instance); // arguments excl. `this`, operands incl. `this` let minArguments = originalSignature.requiredParameters; @@ -6593,7 +6598,7 @@ export class Compiler extends DiagnosticEmitter { // accounting for additional locals and a proper `this` context. let previousFlow = this.currentFlow; let 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 @@ -6628,7 +6633,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 { @@ -6662,7 +6667,7 @@ export class Compiler extends DiagnosticEmitter { typesToRefs(stub.getNonParameterLocalTypes()), module.flatten(stmts, returnType.toRef()) ); - stub.set(CommonFlags.COMPILED); + stub.set(CommonFlags.Compiled); stub.finalize(module, funcRef); return stub; } @@ -6693,9 +6698,9 @@ export class Compiler extends DiagnosticEmitter { /** Finalizes the virtual stub of the specified function. */ private finalizeVirtualStub(instance: Function): void { let 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); let module = this.module; let usizeType = this.options.usizeType; let sizeTypeRef = usizeType.toRef(); @@ -6723,7 +6728,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)) { @@ -6813,7 +6818,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. */ @@ -6856,9 +6861,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( @@ -6868,7 +6873,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); @@ -6893,7 +6898,7 @@ export class Compiler extends DiagnosticEmitter { let parameterTypes = instance.signature.parameterTypes; let maxArguments = parameterTypes.length; let maxOperands = maxArguments; - if (instance.is(CommonFlags.INSTANCE)) { + if (instance.is(CommonFlags.Instance)) { ++minOperands; ++maxOperands; --numArguments; @@ -6919,18 +6924,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( @@ -6948,7 +6953,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(); @@ -6976,7 +6981,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); } @@ -7016,7 +7021,7 @@ export class Compiler extends DiagnosticEmitter { let 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); @@ -7067,10 +7072,11 @@ export class Compiler extends DiagnosticEmitter { if (getSideEffects(functionArg, module.ref) & SideEffects.WritesGlobal) { let flow = this.currentFlow; let temp = flow.getTempLocal(this.options.usizeType); + 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); } else { // simplify functionArg = module.block(null, [ @@ -7100,7 +7106,7 @@ export class Compiler extends DiagnosticEmitter { let 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); @@ -7118,12 +7124,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 indexedGet = classReference.lookupOverload(OperatorKind.INDEXED_GET, isUnchecked); + let isUnchecked = this.currentFlow.is(FlowFlags.UncheckedContext); + let indexedGet = classReference.lookupOverload(OperatorKind.IndexedGet, 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( @@ -7161,7 +7167,7 @@ export class Compiler extends DiagnosticEmitter { : declaration.name.text, sourceFunction, declaration, - DecoratorFlags.NONE + DecoratorFlags.None ); let instance: Function | null; let contextualTypeArguments = cloneMap(flow.contextualTypeArguments); @@ -7305,7 +7311,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); } } @@ -7319,7 +7325,7 @@ export class Compiler extends DiagnosticEmitter { let filesByName = this.program.filesByName; assert(filesByName.has(internalPath)); let enclosingFile = assert(filesByName.get(internalPath)); - if (!enclosingFile.is(CommonFlags.COMPILED)) { + if (!enclosingFile.is(CommonFlags.Compiled)) { this.compileFileByPath(internalPath, expression); } } @@ -7335,7 +7341,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(); @@ -7359,15 +7365,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 = sourceFunction.signature.thisType; if (!thisType) { this.error( @@ -7377,32 +7383,32 @@ export class Compiler extends DiagnosticEmitter { this.currentType = this.options.usizeType; return module.unreachable(); } - if (sourceFunction.is(CommonFlags.CONSTRUCTOR)) { - if (flow.is(FlowFlags.CTORPARAM_CONTEXT)) { + if (sourceFunction.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 = sourceFunction.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 (sourceFunction.is(CommonFlags.CONSTRUCTOR)) { - if (flow.is(FlowFlags.CTORPARAM_CONTEXT)) { + case NodeKind.Super: { + if (sourceFunction.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, @@ -7421,9 +7427,9 @@ export class Compiler extends DiagnosticEmitter { } } } - if (sourceFunction.is(CommonFlags.INSTANCE)) { + if (sourceFunction.is(CommonFlags.Instance)) { let parent = assert(sourceFunction.parent); - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; let baseClassInstance = classInstance.base; if (baseClassInstance) { @@ -7458,7 +7464,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); @@ -7471,12 +7477,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; @@ -7492,7 +7498,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(); @@ -7508,15 +7514,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 @@ -7525,13 +7531,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; @@ -7549,7 +7555,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" @@ -7587,13 +7593,13 @@ export class Compiler extends DiagnosticEmitter { let 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.sourceFunction, ReportMode.SWALLOW); - if (element && element.kind == ElementKind.CLASS_PROTOTYPE) { + let element = this.resolver.resolveTypeName(namedType.name, flow.sourceFunction, 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); } } @@ -7652,6 +7658,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( @@ -7659,11 +7666,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) ); @@ -7697,6 +7704,7 @@ export class Compiler extends DiagnosticEmitter { // perform null checking, which would error earlier when checking // uninitialized (thus zero) `let 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( @@ -7704,11 +7712,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) ); @@ -7775,7 +7783,7 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { let module = this.module; switch (expression.literalKind) { - case LiteralKind.ARRAY: { + case LiteralKind.Array: { assert(!implicitlyNegate); return this.compileArrayLiteral( expression, @@ -7783,7 +7791,7 @@ export class Compiler extends DiagnosticEmitter { constraints ); } - case LiteralKind.FLOAT: { + case LiteralKind.Float: { let floatValue = (expression).value; if (implicitlyNegate) { floatValue = -floatValue; @@ -7794,7 +7802,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; @@ -7808,28 +7816,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, @@ -7939,7 +7947,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. @@ -7977,21 +7985,21 @@ export class Compiler extends DiagnosticEmitter { // to avoid generating unnecessary static data that is not explicitly signaled to be used. let tsaArrayInstance = this.program.templateStringsArrayInstance; let arrayInstance = tsaArrayInstance; - let target = this.resolver.lookupExpression(tag, this.currentFlow, Type.auto, ReportMode.SWALLOW); + let 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) { @@ -8071,7 +8079,7 @@ export class Compiler extends DiagnosticEmitter { // handle normal arrays let element = this.resolver.lookupExpression(expression, flow, this.currentType); if (!element) return module.unreachable(); - assert(element.kind == ElementKind.CLASS); + assert(element.kind == ElementKind.Class); let arrayInstance = element; let arrayType = arrayInstance.type; let elementType = arrayInstance.getTypeArgumentsTo(program.arrayPrototype)![0]; @@ -8088,8 +8096,8 @@ export class Compiler extends DiagnosticEmitter { let 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 { @@ -8114,7 +8122,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; @@ -8129,7 +8137,7 @@ export class Compiler extends DiagnosticEmitter { } // otherwise compile an explicit instantiation with indexed sets - let indexedSet = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true); + let indexedSet = arrayInstance.lookupOverload(OperatorKind.IndexedSet, true); if (!indexedSet) { this.error( DiagnosticCode.Index_signature_in_type_0_only_permits_reading, @@ -8150,7 +8158,7 @@ export class Compiler extends DiagnosticEmitter { ); // tempData = tempThis.dataStart let 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, @@ -8237,8 +8245,8 @@ export class Compiler extends DiagnosticEmitter { let 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; @@ -8260,7 +8268,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)); @@ -8285,7 +8293,7 @@ export class Compiler extends DiagnosticEmitter { } // otherwise compile an explicit instantiation with indexed sets - let indexedSet = arrayInstance.lookupOverload(OperatorKind.INDEXED_SET, true); + let indexedSet = arrayInstance.lookupOverload(OperatorKind.IndexedSet, true); if (!indexedSet) { this.error( DiagnosticCode.Index_signature_in_type_0_only_permits_reading, @@ -8342,14 +8350,14 @@ export class Compiler extends DiagnosticEmitter { } let 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 @@ -8369,7 +8377,7 @@ export class Compiler extends DiagnosticEmitter { let 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 @@ -8390,7 +8398,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 } } @@ -8400,7 +8408,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() @@ -8408,7 +8416,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() @@ -8416,7 +8424,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() @@ -8427,7 +8435,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), @@ -8464,17 +8472,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( @@ -8505,7 +8513,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 ) ); @@ -8530,14 +8538,14 @@ export class Compiler extends DiagnosticEmitter { // obtain the class being instantiated let target = this.resolver.resolveTypeName(expression.typeName, flow.sourceFunction); 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 @@ -8552,7 +8560,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( @@ -8570,9 +8578,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; let 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); @@ -8590,9 +8598,9 @@ export class Compiler extends DiagnosticEmitter { let 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. @@ -8622,7 +8630,7 @@ export class Compiler extends DiagnosticEmitter { CommonNames.constructor, classInstance, // bound this.program.makeNativeFunctionDeclaration(CommonNames.constructor, - CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR + CommonFlags.Instance | CommonFlags.Constructor ) ), null, @@ -8631,10 +8639,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; @@ -8717,10 +8725,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, @@ -8736,7 +8744,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, @@ -8765,11 +8773,11 @@ export class Compiler extends DiagnosticEmitter { /** Node to report on. */ reportNode: Node ): ExpressionRef { - assert(ctorInstance.is(CommonFlags.CONSTRUCTOR)); + assert(ctorInstance.is(CommonFlags.Constructor)); let parent = ctorInstance.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; - if (classInstance.type.isUnmanaged || ctorInstance.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(reportNode); + if (classInstance.type.isUnmanaged || ctorInstance.hasDecorator(DecoratorFlags.Unsafe)) this.checkUnsafe(reportNode); let expr = this.compileCallDirect( ctorInstance, argumentExpressions, @@ -8797,10 +8805,10 @@ export class Compiler extends DiagnosticEmitter { let target = resolver.lookupExpression(expression, flow, ctxType); // reports if (!target) return module.unreachable(); let 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; @@ -8814,47 +8822,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.sourceFunction.is(CommonFlags.CONSTRUCTOR) && - thisExpression.kind == NodeKind.THIS && - !flow.isThisFieldFlag(fieldInstance, FieldFlags.INITIALIZED) && - !fieldInstance.is(CommonFlags.DEFINITELY_ASSIGNED) + flow.sourceFunction.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, @@ -8871,8 +8879,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); } @@ -8884,33 +8892,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(); @@ -8946,10 +8954,10 @@ export class Compiler extends DiagnosticEmitter { // Try to eliminate unnecesssary branches if the condition is constant // FIXME: skips common denominator, inconsistently picking branch type let 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)); } @@ -9011,7 +9019,7 @@ export class Compiler extends DiagnosticEmitter { let 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, @@ -9029,14 +9037,14 @@ export class Compiler extends DiagnosticEmitter { let expr: ExpressionRef; switch (expression.operator) { - case Token.PLUS_PLUS: { + case Token.Plus_Plus: { // 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); + let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns getValue = getLocalSetValue(getValue); tempLocal = null; @@ -9055,7 +9063,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: @@ -9078,8 +9086,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, @@ -9113,20 +9121,20 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MINUS_MINUS: { + case Token.Minus_Minus: { // 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); + let isInstance = overload.is(CommonFlags.Instance); if (tempLocal && !isInstance) { // revert: static overload simply returns getValue = getLocalSetValue(getValue); 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 } } @@ -9139,7 +9147,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: @@ -9162,8 +9170,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, @@ -9252,17 +9260,17 @@ export class Compiler extends DiagnosticEmitter { let expr: ExpressionRef; switch (expression.operator) { - case Token.PLUS: { + case Token.Plus: { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // 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) { @@ -9276,11 +9284,11 @@ 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. - 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; @@ -9289,13 +9297,13 @@ export class Compiler extends DiagnosticEmitter { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // 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) { @@ -9307,7 +9315,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: @@ -9322,8 +9330,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), @@ -9349,21 +9357,21 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.PLUS_PLUS: { + case Token.Plus_Plus: { compound = true; expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // 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 + if (overload.is(CommonFlags.Instance)) break; // re-assign return expr; // skip re-assign } } @@ -9376,7 +9384,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: @@ -9391,8 +9399,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, @@ -9418,21 +9426,21 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.MINUS_MINUS: { + case Token.Minus_Minus: { compound = true; expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // 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 + if (overload.is(CommonFlags.Instance)) break; // re-assign return expr; // skip re-assign } } @@ -9445,7 +9453,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: @@ -9460,8 +9468,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, @@ -9487,17 +9495,17 @@ export class Compiler extends DiagnosticEmitter { } break; } - case Token.EXCLAMATION: { + case Token.Exclamation: { expr = this.compileExpression( expression.operand, contextualType.exceptVoid, - Constraints.NONE + Constraints.None ); // 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 } @@ -9506,7 +9514,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 @@ -9514,13 +9522,13 @@ export class Compiler extends DiagnosticEmitter { : contextualType.isFloatValue ? Type.i64 : contextualType, - Constraints.NONE + Constraints.None ); // 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) { @@ -9534,7 +9542,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: @@ -9549,8 +9557,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, @@ -9568,10 +9576,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.Dot_Dot_Dot: { this.error( DiagnosticCode.Not_implemented_0, expression.range, "Spread operator" @@ -9607,19 +9615,19 @@ export class Compiler extends DiagnosticEmitter { let expr: ExpressionRef = 0; let stringInstance = this.program.stringInstance; let 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(); @@ -9634,13 +9642,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; } @@ -9687,7 +9695,7 @@ export class Compiler extends DiagnosticEmitter { let module = this.module; let 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, @@ -9699,7 +9707,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, @@ -9713,7 +9721,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, @@ -9771,24 +9779,24 @@ 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: - case TypeKind.ARRAYREF: { - 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: + case TypeKind.Arrayref: { + 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(); @@ -9857,17 +9865,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); let module = this.module; let 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 ============================================================== @@ -9877,35 +9885,35 @@ export class Compiler extends DiagnosticEmitter { let 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: - case TypeKind.ARRAYREF: - case TypeKind.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.Dataref: + case TypeKind.Arrayref: + case TypeKind.Stringref: + case TypeKind.StringviewWTF8: + case TypeKind.StringviewWTF16: + 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)); } } @@ -9916,20 +9924,20 @@ export class Compiler extends DiagnosticEmitter { let 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)); } } @@ -9944,14 +9952,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)); } } @@ -9966,13 +9974,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; @@ -9981,7 +9989,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)))) @@ -10016,7 +10024,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)))) @@ -10050,21 +10058,21 @@ 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.STRINGREF: - case TypeKind.STRINGVIEW_WTF8: - case TypeKind.STRINGVIEW_WTF16: - case TypeKind.STRINGVIEW_ITER: { + case TypeKind.Funcref: + case TypeKind.Externref: + case TypeKind.Anyref: + case TypeKind.Eqref: + case TypeKind.I31ref: + 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)); } - case TypeKind.VOID: + case TypeKind.Void: default: { this.error( DiagnosticCode.An_expression_of_type_0_cannot_be_tested_for_truthiness, @@ -10132,7 +10140,7 @@ export class Compiler extends DiagnosticEmitter { let module = this.module; let 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, [ @@ -10193,11 +10201,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; @@ -10239,7 +10247,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) ); @@ -10264,7 +10272,7 @@ export class Compiler extends DiagnosticEmitter { let stringInstance = program.stringInstance; let 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); } @@ -10313,8 +10321,9 @@ export class Compiler extends DiagnosticEmitter { let module = this.module; let flow = this.currentFlow; let temp = flow.getTempLocal(type); - if (!flow.canOverflow(expr, type)) flow.setLocalFlag(temp.index, LocalFlags.WRAPPED); - flow.setLocalFlag(temp.index, LocalFlags.NONNULL); + let tempIndex = temp.index; + if (!flow.canOverflow(expr, type)) flow.setLocalFlag(tempIndex, LocalFlags.Wrapped); + flow.setLocalFlag(tempIndex, LocalFlags.NonNull); let staticAbortCallExpr = this.makeStaticAbort( this.ensureStaticString("unexpected null"), @@ -10322,21 +10331,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 ); } @@ -10359,6 +10368,7 @@ export class Compiler extends DiagnosticEmitter { let module = this.module; let flow = this.currentFlow; let temp = flow.getTempLocal(type); + let tempIndex = temp.index; let instanceofInstance = this.program.instanceofInstance; assert(this.compileFunction(instanceofInstance)); @@ -10372,21 +10382,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) @@ -10406,26 +10416,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; let program = element.program; - let decorator = assert(findDecorator(DecoratorKind.EXTERNAL, declaration.decorators)); + let decorator = assert(findDecorator(DecoratorKind.External, declaration.decorators)); let 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 f2a3d2c86f..e122c46da5 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 ""; @@ -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 ? "^" : "~"); @@ -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 f1f12dd149..ebe9217f90 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 { let 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; } @@ -686,7 +686,7 @@ export class ASTBuilder { visitStringLiteral(str: string): void { let 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 { let 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("`"); } @@ -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,16 +779,16 @@ export class ASTBuilder { let 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 { 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 { @@ -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); } @@ -909,8 +909,8 @@ export class ASTBuilder { visitDoStatement(node: DoStatement): void { let 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"); @@ -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); let values = node.values; @@ -1015,23 +1015,23 @@ export class ASTBuilder { visitExportDefaultStatement(node: ExportDefaultStatement): void { let 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); let sb = this.sb; - if (node.flags & CommonFlags.DEFINITELY_ASSIGNED) { + if (node.flags & CommonFlags.DefinitelyAssigned) { sb.push("!"); } let type = node.type; @@ -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 { @@ -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 { let 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(") "); let ifTrue = node.ifTrue; this.visitNode(ifTrue); - if (ifTrue.kind != NodeKind.BLOCK) { + if (ifTrue.kind != NodeKind.Block) { sb.push(";\n"); } let 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); @@ -1420,10 +1420,10 @@ export class ASTBuilder { let sb = this.sb; sb.push("try {\n"); let indentLevel = ++this.indentLevel; - let statements = node.statements; - for (let i = 0, k = statements.length; i < k; ++i) { + let bodyStatements = node.bodyStatements; + for (let i = 0, k = bodyStatements.length; i < k; ++i) { indent(sb, indentLevel); - this.visitNodeAndTerminate(statements[i]); + this.visitNodeAndTerminate(bodyStatements[i]); } let catchVariable = node.catchVariable; if (catchVariable) { @@ -1480,11 +1480,11 @@ export class ASTBuilder { visitModuleDeclaration(node: ModuleDeclaration): void { let sb = this.sb; - if (node.flags & CommonFlags.DECLARE) { + if (node.flags & CommonFlags.Declare) { sb.push("declare "); } sb.push("module \""); - sb.push(escapeString(node.moduleName, CharCode.DOUBLEQUOTE)); + sb.push(escapeString(node.moduleName, CharCode.DoubleQuote)); sb.push("\""); } @@ -1492,7 +1492,7 @@ export class ASTBuilder { this.visitIdentifierExpression(node.name); let type = node.type; let 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 { let numDeclarations = assert(declarations.length); let 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(", "); @@ -1530,12 +1530,12 @@ export class ASTBuilder { let sb = this.sb; sb.push("while ("); this.visitNode(node.condition); - let statement = node.statement; - if (statement.kind == NodeKind.EMPTY) { + let body = node.body; + if (body.isEmpty) { sb.push(")"); } else { sb.push(") "); - this.visitNode(node.statement); + this.visitNode(body); } } @@ -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); let type = node.type; let 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); @@ -1591,33 +1591,33 @@ export class ASTBuilder { serializeExternalModifiers(node: DeclarationStatement): void { let 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 { let 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 8c1ff7e1ac..401ce58b46 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -96,101 +96,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. */ @@ -199,7 +199,7 @@ export class Flow { /** Creates the default top-level flow of the specified function. */ static createDefault(targetFunction: Function): Flow { let flow = new Flow(targetFunction); - if (targetFunction.is(CommonFlags.CONSTRUCTOR)) { + if (targetFunction.is(CommonFlags.Constructor)) { flow.initThisFieldFlags(); } return flow; @@ -211,7 +211,7 @@ export class Flow { // when it is inlined into itself. let flow = new Flow(targetFunction, inlineFunction); flow.inlineReturnLabel = `${inlineFunction.internalName}|inlined.${(inlineFunction.nextInlineId++)}`; - if (inlineFunction.is(CommonFlags.CONSTRUCTOR)) { + if (inlineFunction.is(CommonFlags.Constructor)) { flow.initThisFieldFlags(); } return flow; @@ -232,7 +232,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. */ @@ -287,21 +287,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; } @@ -313,10 +313,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; @@ -324,7 +324,7 @@ export class Flow { branch.breakLabel = this.breakLabel; } branch.localFlags = this.localFlags.slice(); - if (this.sourceFunction.is(CommonFlags.CONSTRUCTOR)) { + if (this.sourceFunction.is(CommonFlags.Constructor)) { let thisFieldFlags = assert(this.thisFieldFlags); branch.thisFieldFlags = cloneMap(thisFieldFlags); } else { @@ -356,7 +356,7 @@ export class Flow { let 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; } @@ -372,7 +372,7 @@ export class Flow { declarationNode.range, name ); } - scopedDummy.set(CommonFlags.SCOPED); + scopedDummy.set(CommonFlags.Scoped); scopedLocals.set(name, scopedDummy); return scopedDummy; } @@ -403,7 +403,7 @@ export class Flow { } assert(index < this.targetFunction.localsByIndex.length); let scopedAlias = new Local(name, index, type, this.targetFunction); - scopedAlias.set(CommonFlags.SCOPED); + scopedAlias.set(CommonFlags.Scoped); scopedLocals.set(name, scopedAlias); return scopedAlias; } @@ -468,16 +468,16 @@ export class Flow { /** Initializes `this` field flags. */ initThisFieldFlags(): void { let sourceFunction = this.sourceFunction; - assert(sourceFunction.is(CommonFlags.CONSTRUCTOR)); + assert(sourceFunction.is(CommonFlags.Constructor)); let parent = sourceFunction.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); let classInstance = parent; this.thisFieldFlags = new Map(); let members = classInstance.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 @@ -487,9 +487,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); } } } @@ -509,7 +509,7 @@ export class Flow { setThisFieldFlag(field: Field, flag: FieldFlags): void { let fieldFlags = this.thisFieldFlags; if (fieldFlags) { - assert(this.sourceFunction.is(CommonFlags.CONSTRUCTOR)); + assert(this.sourceFunction.is(CommonFlags.Constructor)); if (fieldFlags.has(field)) { let flags = changetype(fieldFlags.get(field)); fieldFlags.set(field, flags | flag); @@ -517,7 +517,7 @@ export class Flow { fieldFlags.set(field, flag); } } else { - assert(!this.sourceFunction.is(CommonFlags.CONSTRUCTOR)); + assert(!this.sourceFunction.is(CommonFlags.Constructor)); } } @@ -555,13 +555,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 @@ -570,11 +570,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.targetFunction == this.targetFunction); 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, @@ -584,73 +584,73 @@ export class Flow { let thisFlags = this.flags; let otherFlags = other.flags; - let newFlags = FlowFlags.NONE; + let 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 let thisLocalFlags = this.localFlags; @@ -662,10 +662,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 ); } @@ -682,98 +682,98 @@ export class Flow { let leftFlags = left.flags; let rightFlags = right.flags; - let newFlags = FlowFlags.NONE; + let 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 let 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]; @@ -788,10 +788,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 ); } } @@ -805,10 +805,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; @@ -835,14 +835,14 @@ export class Flow { let local = localsByIndex[i]; let type = local.type; if (type.isShortIntegerValue) { - 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 needsRecompile = true; } } if (type.isNullableReference) { - 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 needsRecompile = true; } } @@ -862,17 +862,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.targetFunction.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.targetFunction.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; @@ -899,16 +899,16 @@ export class Flow { case ExpressionId.LocalSet: { if (!isLocalTee(expr)) break; let local = this.targetFunction.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.targetFunction.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; } @@ -1101,7 +1101,7 @@ export class Flow { // overflows if the local isn't wrapped or the conversion does case ExpressionId.LocalGet: { let local = this.targetFunction.localsByIndex[getLocalGetIndex(expr)]; - return !this.isLocalFlag(local.index, LocalFlags.WRAPPED, true) + return !this.isLocalFlag(local.index, LocalFlags.Wrapped, true) || canConversionOverflow(local.type, type); } @@ -1115,7 +1115,7 @@ export class Flow { case ExpressionId.GlobalGet: { // TODO: this is inefficient because it has to read a string let global = assert(this.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); } @@ -1278,7 +1278,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; @@ -1330,10 +1330,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 @@ -1353,21 +1353,21 @@ export class Flow { ++levels; } let 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.sourceFunction})[${levels}] ${sb.join(" ")}`; } } diff --git a/src/index-wasm.ts b/src/index-wasm.ts index f7a26fb707..101070d5d9 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; /** 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; /** 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 { @@ -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 e37c3ac790..a7c88871b6 100644 --- a/src/module.ts +++ b/src/module.ts @@ -181,7 +181,6 @@ export const enum FeatureFlags { MultiValue = 512 /* _BinaryenFeatureMultivalue */, GC = 1024 /* _BinaryenFeatureGC */, Memory64 = 2048 /* _BinaryenFeatureMemory64 */, - // GCNNLocals is for off-spec experimentation RelaxedSIMD = 8192 /* _BinaryenFeatureRelaxedSIMD */, ExtendedConst = 16384 /* _BinaryenFeatureExtendedConst */, Stringref = 32768 /* _BinaryenFeatureStrings */, @@ -2346,7 +2345,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)) ); @@ -3484,7 +3483,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); let len = ptrs.length; let ptr = binaryen._malloc(len << 2); let idx = ptr; @@ -3660,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 ); } @@ -3685,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); @@ -3703,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: @@ -3719,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 } @@ -3768,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: @@ -3784,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, @@ -3890,7 +3889,7 @@ function prepareType(builder: binaryen.TypeBuilderRef, seen: Mapstatement, tn.range(startPos, tn.pos)); } default: { @@ -473,8 +473,8 @@ export class Parser extends DiagnosticEmitter { let first = Node.createSimpleTypeName(tn.readIdentifier(), tn.range()); let 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 { let 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 { let thisType: NamedTypeNode | null = null; let isSignature: bool = false; let firstParamNameNoType: IdentifierExpression | null = null; - let firstParamKind: ParameterKind = ParameterKind.DEFAULT; + let firstParamKind: ParameterKind = ParameterKind.Default; - if (tn.skip(Token.CLOSEPAREN)) { + if (tn.skip(Token.CloseParen)) { isSignature = true; tn.discard(state); parameters = []; @@ -718,21 +718,21 @@ 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.Dot_Dot_Dot)) { 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); if (!type) return null; - if (type.kind != NodeKind.NAMEDTYPE) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -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 { } let returnType: TypeNode | null; - if (tn.skip(Token.EQUALS_GREATERTHAN)) { + if (tn.skip(Token.Equals_GreaterThan)) { if (!isSignature) { isSignature = true; tn.discard(state); @@ -885,8 +885,8 @@ 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)) { - if (tn.skipIdentifier(IdentifierHandling.PREFER)) { + while (tn.skip(Token.Dot)) { + if (tn.skipIdentifier(IdentifierHandling.Prefer)) { name = tn.readIdentifier(); expression = Node.createPropertyAccessExpression( expression, @@ -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)); let ret = Node.createVariableStatement(decorators, declarations, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -966,28 +966,28 @@ export class Parser extends DiagnosticEmitter { ); } let flags = parentFlags; - if (tn.skip(Token.EXCLAMATION)) { - flags |= CommonFlags.DEFINITELY_ASSIGNED; + if (tn.skip(Token.Exclamation)) { + flags |= CommonFlags.DefinitelyAssigned; } let type: TypeNode | null = null; - if (tn.skip(Token.COLON)) { + if (tn.skip(Token.Colon)) { type = this.parseType(tn, true); } let initializer: Expression | null = null; - if (tn.skip(Token.EQUALS)) { - if (flags & CommonFlags.AMBIENT) { + 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) { - 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 { } } let 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 @@ -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; } let 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; } let members = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { - let member = this.parseEnumValue(tn, CommonFlags.NONE); + 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 { } let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); let 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 { let startPos = tn.tokenPos; let 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; } let 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 { let typeParameters = new Array(); let seenOptional = false; let 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,16 +1168,16 @@ 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) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1187,10 +1187,10 @@ 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) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1231,11 +1231,11 @@ 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) { + if (thisType.kind == NodeKind.NamedType) { this.parseParametersThis = thisType; } else { this.error( @@ -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( @@ -1318,31 +1318,31 @@ export class Parser extends DiagnosticEmitter { let isRest = false; let isOptional = false; let startRange: Range | null = null; - let accessFlags: CommonFlags = CommonFlags.NONE; + let 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)) { + accessFlags |= CommonFlags.Public; + } else if (tn.skip(Token.Protected)) { startRange = tn.range(); - accessFlags |= CommonFlags.PROTECTED; - } else if (tn.skip(Token.PRIVATE)) { + accessFlags |= CommonFlags.Protected; + } else if (tn.skip(Token.Private)) { startRange = tn.range(); - accessFlags |= CommonFlags.PRIVATE; + 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; + accessFlags |= CommonFlags.Readonly; } else { // identifier tn.reset(state); } } } - if (tn.skip(Token.DOT_DOT_DOT)) { + if (tn.skip(Token.Dot_Dot_Dot)) { 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 { let signatureStart = -1; let 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; + flags |= CommonFlags.Generic; } - if (!tn.skip(Token.OPENPAREN)) { + if (!tn.skip(Token.OpenParen)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "(" @@ -1461,7 +1461,7 @@ export class Parser extends DiagnosticEmitter { if (!parameters) return null; let thisType = this.parseParametersThis; - let isSetter = (flags & CommonFlags.SET) != 0; + let 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, @@ -1487,7 +1487,7 @@ export class Parser extends DiagnosticEmitter { } let 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,8 +1513,8 @@ export class Parser extends DiagnosticEmitter { ); let body: Statement | null = null; - if (tn.skip(Token.OPENBRACE)) { - if (flags & CommonFlags.AMBIENT) { + if (tn.skip(Token.OpenBrace)) { + 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,31 +1537,31 @@ export class Parser extends DiagnosticEmitter { typeParameters, signature, body, - ArrowKind.NONE, + ArrowKind.None, tn.range(startPos, tn.pos) ); ret.overriddenModuleName = this.currentModuleName; - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } parseFunctionExpression(tn: Tokenizer): FunctionExpression | null { let startPos = tn.tokenPos; let name: IdentifierExpression; - let arrowKind = ArrowKind.NONE; + let arrowKind = ArrowKind.None; // either at 'function': // Identifier? // '(' 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), "(" @@ -1574,8 +1574,8 @@ export class Parser extends DiagnosticEmitter { // Statement } else { - arrowKind = ArrowKind.ARROW_PARENTHESIZED; - assert(tn.token == Token.OPENPAREN); + 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; let 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 { @@ -1609,7 +1609,7 @@ export class Parser extends DiagnosticEmitter { } if (arrowKind) { - if (!tn.skip(Token.EQUALS_GREATERTHAN)) { + if (!tn.skip(Token.Equals_GreaterThan)) { this.error( DiagnosticCode._0_expected, tn.range(tn.pos), "=>" @@ -1628,14 +1628,14 @@ export class Parser extends DiagnosticEmitter { let 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), "{" @@ -1649,7 +1649,7 @@ export class Parser extends DiagnosticEmitter { let declaration = Node.createFunctionDeclaration( name, null, - CommonFlags.NONE, + CommonFlags.None, null, signature, body, @@ -1673,7 +1673,7 @@ export class Parser extends DiagnosticEmitter { // ('implements' Type (',' Type)*)? // '{' ClassMember* '}' - let isInterface = tn.token == Token.INTERFACE; + let isInterface = tn.token == Token.Interface; if (!tn.skipIdentifier()) { this.error( @@ -1689,17 +1689,17 @@ export class Parser extends DiagnosticEmitter { ); 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; + flags |= CommonFlags.Generic; } 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) { + if (type.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, type.range @@ -1710,7 +1710,7 @@ export class Parser extends DiagnosticEmitter { } let 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, @@ -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 @@ -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,11 +1768,11 @@ 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) { - if (member.kind == NodeKind.INDEXSIGNATURE) { + if (member.kind == NodeKind.IndexSignature) { declaration.indexSignature = member; } else { assert(member instanceof DeclarationStatement); @@ -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), "{" @@ -1820,18 +1820,18 @@ export class Parser extends DiagnosticEmitter { let declaration = Node.createClassDeclaration( name, null, - CommonFlags.NONE, + CommonFlags.None, null, null, null, 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) { - if (member.kind == NodeKind.INDEXSIGNATURE) { + if (member.kind == NodeKind.IndexSignature) { declaration.indexSignature = member; } else { assert(declaration instanceof DeclarationStatement); @@ -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); @@ -1867,17 +1867,17 @@ export class Parser extends DiagnosticEmitter { // ('get' | 'set')? // Identifier ... - let isInterface = parent.kind == NodeKind.INTERFACEDECLARATION; + let isInterface = parent.kind == NodeKind.InterfaceDeclaration; let startPos = 0; let 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, @@ -1887,15 +1887,15 @@ export class Parser extends DiagnosticEmitter { } // inherit ambient status - let flags = parent.flags & CommonFlags.AMBIENT; + let flags = parent.flags & CommonFlags.Ambient; // implemented methods are virtual - if (isInterface) flags |= CommonFlags.VIRTUAL; + if (isInterface) flags |= CommonFlags.Virtual; let declareStart = 0; let declareEnd = 0; - let contextIsAmbient = parent.is(CommonFlags.AMBIENT); - if (tn.skip(Token.DECLARE)) { + let contextIsAmbient = parent.is(CommonFlags.Ambient); + if (tn.skip(Token.Declare)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, @@ -1908,50 +1908,50 @@ 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; } let accessStart = 0; let accessEnd = 0; - if (tn.skip(Token.PUBLIC)) { + if (tn.skip(Token.Public)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, tn.range(), "public" ); } else { - flags |= CommonFlags.PUBLIC; + flags |= CommonFlags.Public; accessStart = tn.tokenPos; 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, tn.range(), "private" ); } else { - flags |= CommonFlags.PRIVATE; + flags |= CommonFlags.Private; accessStart = tn.tokenPos; 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, tn.range(), "protected" ); } else { - flags |= CommonFlags.PROTECTED; + flags |= CommonFlags.Protected; accessStart = tn.tokenPos; accessEnd = tn.pos; } @@ -1962,46 +1962,46 @@ export class Parser extends DiagnosticEmitter { let staticEnd = 0; let abstractStart = 0; let abstractEnd = 0; - if (tn.skip(Token.STATIC)) { + if (tn.skip(Token.Static)) { if (isInterface) { this.error( DiagnosticCode._0_modifier_cannot_be_used_here, 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; - if (tn.skip(Token.ABSTRACT)) { - if (isInterface || !parent.is(CommonFlags.ABSTRACT)) { + flags |= CommonFlags.Instance; + if (tn.skip(Token.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; } let overrideStart = 0; let 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, tn.range(), "override" ); } else { - flags |= CommonFlags.OVERRIDE; + flags |= CommonFlags.Override; overrideStart = tn.tokenPos; overrideEnd = tn.pos; } @@ -2010,12 +2010,12 @@ export class Parser extends DiagnosticEmitter { let readonlyStart = 0; let 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; + flags |= CommonFlags.Readonly; readonlyStart = tn.tokenPos; readonlyEnd = tn.pos; if (!startPos) startPos = readonlyStart; @@ -2034,14 +2034,14 @@ export class Parser extends DiagnosticEmitter { let setStart = 0; let setEnd = 0; if (!isInterface) { - if (tn.skip(Token.GET)) { - if (tn.peek(true, IdentifierHandling.PREFER) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { - flags |= CommonFlags.GET; + if (tn.skip(Token.Get)) { + if (tn.peek(true, IdentifierHandling.Prefer) == Token.Identifier && !tn.nextTokenOnNewLine) { + 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" @@ -2050,14 +2050,14 @@ 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) { - flags |= CommonFlags.SET; + } else if (tn.skip(Token.Set)) { + if (tn.peek(true, IdentifierHandling.Prefer) == Token.Identifier && !tn.nextTokenOnNewLine) { + 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" @@ -2066,23 +2066,23 @@ export class Parser extends DiagnosticEmitter { } else { tn.reset(state); } - } else if (tn.skip(Token.CONSTRUCTOR)) { - flags |= CommonFlags.CONSTRUCTOR; + } else if (tn.skip(Token.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" @@ -2096,38 +2096,38 @@ 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) { + 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" @@ -2143,10 +2143,10 @@ export class Parser extends DiagnosticEmitter { } return null; } - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return retIndex; } - if (!tn.skipIdentifier(IdentifierHandling.ALWAYS)) { + if (!tn.skipIdentifier(IdentifierHandling.Always)) { this.error( DiagnosticCode.Identifier_expected, tn.range() @@ -2157,7 +2157,7 @@ export class Parser extends DiagnosticEmitter { name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } let 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; @@ -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 (tn.skip(Token.OpenParen)) { + 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 @@ -2239,8 +2239,8 @@ export class Parser extends DiagnosticEmitter { } let returnType: TypeNode | null = null; - if (tn.skip(Token.COLON)) { - if (name.kind == NodeKind.CONSTRUCTOR) { + if (tn.skip(Token.Colon)) { + 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 @@ -2272,13 +2272,13 @@ export class Parser extends DiagnosticEmitter { ); let body: Statement | null = null; - if (tn.skip(Token.OPENBRACE)) { - if (flags & CommonFlags.AMBIENT) { + if (tn.skip(Token.OpenBrace)) { + 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() @@ -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; @@ -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" @@ -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)) { - flags |= CommonFlags.DEFINITELY_ASSIGNED; + 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,8 +2374,8 @@ export class Parser extends DiagnosticEmitter { ); // recoverable } let initializer: Expression | null = null; - if (tn.skip(Token.EQUALS)) { - if (flags & CommonFlags.AMBIENT) { + if (tn.skip(Token.Equals)) { + 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, @@ -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,21 +2429,21 @@ 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) { + if (keyType.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Type_expected, tn.range() ); 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) { + if (valueType.kind != NodeKind.NamedType) { this.error( DiagnosticCode.Identifier_expected, valueType.range @@ -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,10 +2504,10 @@ 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) { + if (member.kind == NodeKind.Export) { this.error( DiagnosticCode.A_default_export_can_only_be_used_in_a_module, member.range, @@ -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 { let path: StringLiteralExpression | null = null; let 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( @@ -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.skip(Token.As)) { + if (tn.skipIdentifier(IdentifierHandling.Always)) { asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } else { this.error( @@ -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 { let members: ImportDeclaration[] | null = null; let namespaceName: IdentifierExpression | null = null; let 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( @@ -2804,10 +2804,10 @@ 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.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 { let token = tn.next(); let statement: Statement | null = null; switch (token) { - case Token.BREAK: { + case Token.Break: { statement = this.parseBreak(tn); break; } - case Token.CONST: { - statement = this.parseVariable(tn, CommonFlags.CONST, null, tn.tokenPos); + 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: { - statement = this.parseVariable(tn, CommonFlags.LET, null, tn.tokenPos); + case Token.Let: { + statement = this.parseVariable(tn, CommonFlags.Let, null, tn.tokenPos); break; } - case Token.VAR: { - statement = this.parseVariable(tn, CommonFlags.NONE, null, tn.tokenPos); + 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,32 +2932,32 @@ 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) { - statement = this.parseTypeDeclaration(tn, CommonFlags.NONE, null, tn.tokenPos); + case Token.Type: { // also identifier + if (tn.peek(false, IdentifierHandling.Prefer) == Token.Identifier) { + statement = this.parseTypeDeclaration(tn, CommonFlags.None, null, tn.tokenPos); break; } // fall-through @@ -2986,11 +2986,11 @@ export class Parser extends DiagnosticEmitter { let startPos = tn.tokenPos; let 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 { } } let 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? ';'? let identifier: IdentifierExpression | null = null; - if (tn.peek(true) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { - tn.next(IdentifierHandling.PREFER); + if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { + tn.next(IdentifierHandling.Prefer); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } let 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? ';'? let identifier: IdentifierExpression | null = null; - if (tn.peek(true) == Token.IDENTIFIER && !tn.nextTokenOnNewLine) { - tn.next(IdentifierHandling.PREFER); + if (tn.peek(true) == Token.Identifier && !tn.nextTokenOnNewLine) { + tn.next(IdentifierHandling.Prefer); identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); } let 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 { let 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; let ret = Node.createExpressionStatement(expr); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3098,26 +3098,26 @@ export class Parser extends DiagnosticEmitter { let startPos = tn.tokenPos; - if (tn.skip(Token.OPENPAREN)) { + if (tn.skip(Token.OpenParen)) { let initializer: Statement | null = null; - if (tn.skip(Token.CONST)) { - 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); - } else if (tn.skip(Token.VAR)) { - initializer = this.parseVariable(tn, CommonFlags.NONE, null, tn.tokenPos, true); + if (tn.skip(Token.Const)) { + 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); + } 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) { + 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 @@ -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 { let 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)? let 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* '}' ';'? let 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 { let expression = this.parseExpression(tn); if (!expression) return null; let ret = Node.createThrowStatement(expression, tn.range(startPos, tn.pos)); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } @@ -3422,18 +3422,18 @@ export class Parser extends DiagnosticEmitter { let startPos = tn.tokenPos; let stmt: Statement | null; - if (tn.skip(Token.OPENBRACE)) { - let statements = new Array(); - while (!tn.skip(Token.CLOSEBRACE)) { + if (tn.skip(Token.OpenBrace)) { + 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; 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); @@ -3492,13 +3492,13 @@ export class Parser extends DiagnosticEmitter { return null; } let ret = Node.createTryStatement( - statements, + bodyStatements, catchVariable, catchStatements, finallyStatements, tn.range(startPos, tn.pos) ); - tn.skip(Token.SEMICOLON); + tn.skip(Token.Semicolon); return ret; } else { this.error( @@ -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; @@ -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; + 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 ';'? let startPos = tn.tokenPos; - assert(tn.next() == Token.STRINGLITERAL); // checked earlier + assert(tn.next() == Token.StringLiteral); // checked earlier let moduleName = tn.readString(); let 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 ';'? let startPos = tn.tokenPos; - let expression = this.parseExpression(tn, Precedence.GROUPING); + let expression = this.parseExpression(tn, Precedence.Grouping); if (!expression) return null; let 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 ';'? let 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( @@ -3671,34 +3671,34 @@ export class Parser extends DiagnosticEmitter { parseExpressionStart( tn: Tokenizer ): Expression | null { - let token = tn.next(IdentifierHandling.PREFER); + let token = tn.next(IdentifierHandling.Prefer); let startPos = tn.tokenPos; switch (token) { // TODO: SpreadExpression, YieldExpression - case Token.DOT_DOT_DOT: - case Token.YIELD: // fallthrough to unsupported UnaryPrefixExpression + case Token.Dot_Dot_Dot: + 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.Plus_Plus: + case Token.Minus_Minus: { + let operand = this.parseExpression(tn, Precedence.UnaryPrefix); 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, @@ -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,45 +3740,45 @@ 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)), [], null, - ArrowKind.ARROW_PARENTHESIZED + ArrowKind.Parenthesized ); } let state = tn.mark(); let again = true; do { - switch (tn.next(IdentifierHandling.PREFER)) { + switch (tn.next(IdentifierHandling.Prefer)) { // function expression - case Token.DOT_DOT_DOT: { + case Token.Dot_Dot_Dot: { 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.Equals_GreaterThan) ) { 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,39 +3912,39 @@ 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, + AssertionKind.Prefix, expr, toType, 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.Equals_GreaterThan && !tn.nextTokenOnNewLine) { return this.parseFunctionExpressionCommon( tn, Node.createEmptyIdentifierExpression(tn.range(startPos)), [ Node.createParameter( - ParameterKind.DEFAULT, + ParameterKind.Default, identifier, Node.createOmittedType(identifier.range.atEnd), null, @@ -3952,14 +3952,14 @@ export class Parser extends DiagnosticEmitter { ) ], null, - ArrowKind.ARROW_SINGLE, + ArrowKind.Single, startPos ); } 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)* '>' '(' let state = tn.mark(); - if (!tn.skip(Token.LESSTHAN)) return null; + if (!tn.skip(Token.LessThan)) return null; let start = tn.tokenPos; let 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)*)? ')' let 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); let expr = this.parseExpressionStart(tn); if (!expr) return null; let startPos = expr.range.start; @@ -4109,10 +4109,10 @@ 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, + 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) @@ -4129,9 +4129,9 @@ export class Parser extends DiagnosticEmitter { } break; } - case Token.EXCLAMATION: { + case Token.Exclamation: { expr = Node.createAssertionExpression( - AssertionKind.NONNULL, + AssertionKind.NonNull, expr, null, tn.range(startPos, tn.pos) @@ -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,12 +4170,12 @@ export class Parser extends DiagnosticEmitter { break; } // UnaryPostfixExpression - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { + 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, @@ -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,19 +4214,19 @@ 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: { - if (tn.skipIdentifier(IdentifierHandling.ALWAYS)) { // expr '.' Identifier + case Token.Dot: { + if (tn.skipIdentifier(IdentifierHandling.Always)) { // expr '.' Identifier let next = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); expr = Node.createPropertyAccessExpression( expr, @@ -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 { @@ -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.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: { 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.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: { let next = this.parseExpression(tn, nextPrecedence + 1); if (!next) return null; expr = Node.createBinaryExpression(token, expr, next, tn.range(startPos, tn.pos)); @@ -4320,14 +4320,14 @@ 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(), "}" ); 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)); @@ -4341,7 +4341,7 @@ export class Parser extends DiagnosticEmitter { ): Expression | null { let 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; @@ -4374,7 +4374,7 @@ export class Parser extends DiagnosticEmitter { ): Expression { let 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 { let again = true; do { switch (tn.next()) { - case Token.ENDOFFILE: { + case Token.EndOfFile: { this.error( DiagnosticCode._0_expected, tn.range(), "}" @@ -4449,37 +4449,37 @@ 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); - tn.readString(CharCode.BACKTICK); + tn.readString(CharCode.Backtick); } 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.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.LogicalOr; + 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.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.UnaryPostfix; + case Token.Dot: + case Token.OpenBracket: + case Token.Exclamation: return Precedence.MemberAccess; } - return Precedence.NONE; + return Precedence.None; } diff --git a/src/passes/shadowstack.ts b/src/passes/shadowstack.ts index 0db7a83522..1f9f8eee66 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); let 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 3c386e20c5..421a76618b 100644 --- a/src/program.ts +++ b/src/program.ts @@ -198,49 +198,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 { @@ -249,173 +249,173 @@ 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; - if (arg == "[]=") return OperatorKind.INDEXED_SET; + case CharCode.OpenBracket: { + 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; + case CharCode.OpenBrace: { + if (arg == "{}") return OperatorKind.UncheckedIndexedGet; + if (arg == "{}=") return OperatorKind.UncheckedIndexedSet; break; } - case CharCode.PLUS: { - if (arg == "+") return OperatorKind.ADD; + case CharCode.Plus: { + if (arg == "+") return OperatorKind.Add; break; } - case CharCode.MINUS: { - if (arg == "-") return OperatorKind.SUB; + case CharCode.Minus: { + if (arg == "-") return OperatorKind.Sub; break; } - case CharCode.ASTERISK: { - if (arg == "*") return OperatorKind.MUL; - if (arg == "**") return OperatorKind.POW; + case CharCode.Asterisk: { + if (arg == "*") return OperatorKind.Mul; + if (arg == "**") return OperatorKind.Pow; break; } - case CharCode.SLASH: { - if (arg == "/") return OperatorKind.DIV; + case CharCode.Slash: { + if (arg == "/") return OperatorKind.Div; break; } - case CharCode.PERCENT: { - if (arg == "%") return OperatorKind.REM; + case CharCode.Percent: { + if (arg == "%") return OperatorKind.Rem; break; } - case CharCode.AMPERSAND: { - if (arg == "&") return OperatorKind.BITWISE_AND; + case CharCode.Ampersand: { + if (arg == "&") return OperatorKind.BitwiseAnd; break; } - case CharCode.BAR: { - if (arg == "|") return OperatorKind.BITWISE_OR; + case CharCode.Bar: { + if (arg == "|") return OperatorKind.BitwiseOr; break; } - case CharCode.CARET: { - if (arg == "^") return OperatorKind.BITWISE_XOR; + case CharCode.Caret: { + if (arg == "^") return OperatorKind.BitwiseXor; break; } - case CharCode.EQUALS: { - if (arg == "==") return OperatorKind.EQ; + case CharCode.Equals: { + if (arg == "==") return OperatorKind.Eq; break; } - case CharCode.EXCLAMATION: { - if (arg == "!=") return OperatorKind.NE; + case CharCode.Exclamation: { + 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; + case CharCode.GreaterThan: { + 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; + case CharCode.LessThan: { + if (arg == "<") return OperatorKind.Lt; + if (arg == "<=") return OperatorKind.Le; + if (arg == "<<") return OperatorKind.BitwiseShl; break; } } break; } - case DecoratorKind.OPERATOR_PREFIX: { + case DecoratorKind.OperatorPrefix: { switch (arg.charCodeAt(0)) { - case CharCode.PLUS: { - if (arg == "+") return OperatorKind.PLUS; - if (arg == "++") return OperatorKind.PREFIX_INC; + case CharCode.Plus: { + 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; + case CharCode.Minus: { + if (arg == "-") return OperatorKind.Minus; + if (arg == "--") return OperatorKind.PrefixDec; break; } - case CharCode.EXCLAMATION: { - if (arg == "!") return OperatorKind.NOT; + case CharCode.Exclamation: { + if (arg == "!") return OperatorKind.Not; break; } - case CharCode.TILDE: { - if (arg == "~") return OperatorKind.BITWISE_NOT; + case CharCode.Tilde: { + if (arg == "~") return OperatorKind.BitwiseNot; break; } } break; } - case DecoratorKind.OPERATOR_POSTFIX: { + case DecoratorKind.OperatorPostfix: { switch (arg.charCodeAt(0)) { - case CharCode.PLUS: { - if (arg == "++") return OperatorKind.POSTFIX_INC; + case CharCode.Plus: { + if (arg == "++") return OperatorKind.PostfixInc; break; } - case CharCode.MINUS: { - if (arg == "--") return OperatorKind.POSTFIX_DEC; + case CharCode.Minus: { + 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.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.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.BitwiseAnd; + case Token.Bar: + case Token.Bar_Equals: return OperatorKind.BitwiseOr; + case Token.Caret: + case Token.Caret_Equals: return OperatorKind.BitwiseXor; + 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.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; } - 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.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.BitwiseNot; + case Token.Plus_Plus: return OperatorKind.PrefixInc; + case Token.Minus_Minus: 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.PLUS_PLUS: return OperatorKind.POSTFIX_INC; - case Token.MINUS_MINUS: return OperatorKind.POSTFIX_DEC; + case Token.Plus_Plus: return OperatorKind.PostfixInc; + case Token.Minus_Minus: return OperatorKind.PostfixDec; } - return OperatorKind.INVALID; + return OperatorKind.Invalid; } } @@ -430,7 +430,7 @@ export class Program extends DiagnosticEmitter { diagnostics: DiagnosticMessage[] | null = null ) { super(diagnostics); - let nativeSource = new Source(SourceKind.LIBRARY_ENTRY, LIBRARY_PREFIX + "native.ts", "[native code]"); + let 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); @@ -502,7 +502,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Array` prototype. */ get arrayPrototype(): ClassPrototype { let 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; @@ -510,7 +510,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `StaticArray` prototype. */ get staticArrayPrototype(): ClassPrototype { let 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; @@ -518,7 +518,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Set` prototype. */ get setPrototype(): ClassPrototype { let 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; @@ -526,7 +526,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Map` prototype. */ get mapPrototype(): ClassPrototype { let 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; @@ -534,7 +534,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Function` prototype. */ get functionPrototype(): ClassPrototype { let 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; @@ -542,7 +542,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int8Array` prototype. */ get int8ArrayPrototype(): ClassPrototype { let 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; @@ -550,7 +550,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int16Array` prototype. */ get int16ArrayPrototype(): ClassPrototype { let 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; @@ -558,7 +558,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int32Array` prototype. */ get int32ArrayPrototype(): ClassPrototype { let 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; @@ -566,7 +566,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Int64Array` prototype. */ get int64ArrayPrototype(): ClassPrototype { let 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; @@ -574,7 +574,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint8Array` prototype. */ get uint8ArrayPrototype(): ClassPrototype { let 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; @@ -582,7 +582,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint8ClampedArray` prototype. */ get uint8ClampedArrayPrototype(): ClassPrototype { let 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; @@ -590,7 +590,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint16Array` prototype. */ get uint16ArrayPrototype(): ClassPrototype { let 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; @@ -598,7 +598,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint32Array` prototype. */ get uint32ArrayPrototype(): ClassPrototype { let 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; @@ -606,7 +606,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Uint64Array` prototype. */ get uint64ArrayPrototype(): ClassPrototype { let 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; @@ -614,7 +614,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Float32Array` prototype. */ get float32ArrayPrototype(): ClassPrototype { let 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; @@ -622,7 +622,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `Float64Array` prototype. */ get float64ArrayPrototype(): ClassPrototype { let 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; @@ -662,7 +662,7 @@ export class Program extends DiagnosticEmitter { /** Gets the standard `abort` instance, if not explicitly disabled. */ get abortInstance(): Function | null { let 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); } @@ -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; } } @@ -864,7 +864,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 { let range = this.nativeSource.range; return Node.createVariableDeclaration( @@ -878,7 +878,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 { let range = this.nativeSource.range; let identifier = Node.createIdentifierExpression(name, range); @@ -898,7 +898,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 { let range = this.nativeSource.range; let signature = this.nativeDummySignature; @@ -913,7 +913,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 ); } @@ -922,7 +922,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 { let range = this.nativeSource.range; return Node.createNamespaceDeclaration( @@ -940,9 +940,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, @@ -992,32 +992,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 @@ -1038,7 +1038,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, @@ -1064,35 +1064,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_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)); 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 let queuedImports = new Array(); @@ -1110,43 +1110,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; } @@ -1295,8 +1295,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)) { @@ -1315,18 +1315,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, @@ -1348,8 +1348,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; @@ -1378,7 +1378,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) { @@ -1412,7 +1412,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(); @@ -1494,7 +1494,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); } } @@ -1512,13 +1512,13 @@ export class Program extends DiagnosticEmitter { for (let j = 0, l = thisMembers.length; j < l; ++j) { let thisMember = thisMembers[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; @@ -1528,7 +1528,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); @@ -1536,12 +1536,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; @@ -1551,10 +1551,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; @@ -1565,13 +1565,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; @@ -1582,7 +1582,7 @@ 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); } } } @@ -1614,12 +1614,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 { - let prototype = this.require(name, ElementKind.CLASS_PROTOTYPE); + let prototype = this.require(name, ElementKind.ClassPrototype); let resolved = this.resolver.resolveClass(prototype, null); if (!resolved) throw new Error(`Invalid standard library class: ${name}`); return resolved; @@ -1627,7 +1627,7 @@ export class Program extends DiagnosticEmitter { /** Requires that a global function is present and returns it. */ requireFunction(name: string, typeArguments: Type[] | null = null): Function { - let prototype = this.require(name, ElementKind.FUNCTION_PROTOTYPE); + let prototype = this.require(name, ElementKind.FunctionPrototype); let resolved = this.resolver.resolveFunction(prototype, typeArguments); if (!resolved) throw new Error(`Invalid standard library function: ${name}`); return resolved; @@ -1653,9 +1653,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()) { @@ -1666,7 +1666,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); @@ -1674,10 +1674,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 } let staticMembers = element.members; if (staticMembers) { @@ -1691,7 +1691,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); let moduleImports = this.moduleImports; let module: Map; if (moduleImports.has(moduleName)) { @@ -1708,8 +1708,8 @@ export class Program extends DiagnosticEmitter { let 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); @@ -1720,7 +1720,7 @@ export class Program extends DiagnosticEmitter { let wrapperClasses = this.wrapperClasses; assert(!type.isInternalReference && !wrapperClasses.has(type)); let element = assert(this.lookup(className)); - assert(element.kind == ElementKind.CLASS_PROTOTYPE); + assert(element.kind == ElementKind.ClassPrototype); let classElement = assert(this.resolver.resolveClass(element, null)); classElement.wrappedType = type; wrapperClasses.set(type, classElement); @@ -1732,8 +1732,8 @@ export class Program extends DiagnosticEmitter { let 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); @@ -1745,8 +1745,8 @@ export class Program extends DiagnosticEmitter { let 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); @@ -1858,14 +1858,14 @@ export class Program extends DiagnosticEmitter { /** Accepted decorator flags. Emits diagnostics if any other decorators are present. */ acceptedFlags: DecoratorFlags ): DecoratorFlags { - let flags = DecoratorFlags.NONE; + let 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, @@ -1910,9 +1910,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; @@ -1923,7 +1923,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( @@ -1945,23 +1945,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 } } @@ -1978,15 +1978,15 @@ export class Program extends DiagnosticEmitter { let name = declaration.name.text; let decorators = declaration.decorators; let element: DeclaredElement; - let acceptedFlags: DecoratorFlags = DecoratorFlags.UNSAFE; - if (parent.is(CommonFlags.AMBIENT)) { - acceptedFlags |= DecoratorFlags.EXTERNAL; + let 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, @@ -1996,7 +1996,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, @@ -2015,15 +2015,15 @@ export class Program extends DiagnosticEmitter { parent: ClassPrototype ): FunctionPrototype | null { let name = declaration.name.text; - let isStatic = declaration.is(CommonFlags.STATIC); - let acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE; - if (!declaration.is(CommonFlags.GENERIC)) { - acceptedFlags |= DecoratorFlags.OPERATOR_BINARY - | DecoratorFlags.OPERATOR_PREFIX - | DecoratorFlags.OPERATOR_POSTFIX; + let isStatic = declaration.is(CommonFlags.Static); + let 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; } let element = new FunctionPrototype( name, @@ -2032,7 +2032,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; @@ -2054,18 +2054,18 @@ 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) { + if (kind == OperatorKind.Invalid) { this.error( DiagnosticCode._0_is_not_a_valid_operator, firstArg.range, text @@ -2108,11 +2108,11 @@ export class Program extends DiagnosticEmitter { parent: ClassPrototype ): PropertyPrototype | null { let 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; @@ -2122,7 +2122,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; @@ -2146,7 +2146,7 @@ export class Program extends DiagnosticEmitter { let property = this.ensureProperty(declaration, parent); if (!property) return; let name = declaration.name.text; - let isGetter = declaration.is(CommonFlags.GET); + let isGetter = declaration.is(CommonFlags.Get); if (isGetter) { if (property.getterPrototype) { this.error( @@ -2169,7 +2169,7 @@ export class Program extends DiagnosticEmitter { property, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.INLINE | DecoratorFlags.UNSAFE + DecoratorFlags.Inline | DecoratorFlags.Unsafe ) ); if (isGetter) { @@ -2192,9 +2192,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; @@ -2218,7 +2218,7 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.NONE + DecoratorFlags.None ) ); if (!parent.add(name, element)) return; @@ -2326,23 +2326,23 @@ export class Program extends DiagnosticEmitter { let declaration = statement.declaration; let 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; } @@ -2450,18 +2450,18 @@ export class Program extends DiagnosticEmitter { parent: Element ): FunctionPrototype | null { let name = declaration.name.text; - let validDecorators = DecoratorFlags.UNSAFE | DecoratorFlags.BUILTIN; - if (declaration.is(CommonFlags.AMBIENT)) { - validDecorators |= DecoratorFlags.EXTERNAL | DecoratorFlags.EXTERNAL_JS; + let 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; } } let element = new FunctionPrototype( @@ -2489,7 +2489,7 @@ export class Program extends DiagnosticEmitter { parent, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.GLOBAL + DecoratorFlags.Global ) ); if (!parent.add(name, element)) return null; @@ -2501,13 +2501,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); @@ -2533,7 +2533,7 @@ export class Program extends DiagnosticEmitter { Node.createMethodDeclaration( declaration.name, declaration.decorators, - declaration.flags | CommonFlags.GET, + declaration.flags | CommonFlags.Get, null, Node.createFunctionType( [], @@ -2547,17 +2547,17 @@ 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( [ Node.createParameter( - ParameterKind.DEFAULT, + ParameterKind.Default, declaration.name, typeNode, null, @@ -2593,7 +2593,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; let element = assert(parent.getMember(name)); // possibly merged @@ -2601,31 +2601,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; } @@ -2648,7 +2648,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 } @@ -2664,12 +2664,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, @@ -2712,71 +2712,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 { @@ -2784,20 +2784,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; } } } @@ -2808,9 +2808,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. */ @@ -2835,7 +2835,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 } } @@ -2845,7 +2845,7 @@ export abstract class Element { let current: Element = this; do { current = current.parent; - if (current.kind == ElementKind.FILE) return current; + if (current.kind == ElementKind.File) return current; } while (true); } @@ -2910,7 +2910,7 @@ export abstract class Element { } members.set(name, element); let 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); @@ -2920,18 +2920,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); } @@ -2993,7 +2993,7 @@ export abstract class DeclaredElement extends Element { get identifierAndSignatureRange(): Range { let declaration = this.declaration; let 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); } @@ -3012,7 +3012,7 @@ export abstract class DeclaredElement extends Element { let checkCompatibleOverride = false; if (kind == base.kind) { switch (kind) { - case ElementKind.FUNCTION_PROTOTYPE : { + case ElementKind.FunctionPrototype : { let selfFunction = this.program.resolver.resolveFunction(self, null); if (!selfFunction) return false; let baseFunction = this.program.resolver.resolveFunction(base, null); @@ -3022,10 +3022,10 @@ export abstract class DeclaredElement extends Element { checkCompatibleOverride = true; // fall-through } - case ElementKind.FUNCTION: { + case ElementKind.Function: { return (self).signature.isAssignableTo((base).signature, checkCompatibleOverride); } - case ElementKind.PROPERTY_PROTOTYPE: { + case ElementKind.PropertyPrototype: { let selfProperty = this.program.resolver.resolveProperty(self); if (!selfProperty) return false; let baseProperty = this.program.resolver.resolveProperty(base); @@ -3034,7 +3034,7 @@ export abstract class DeclaredElement extends Element { base = baseProperty; // fall-through } - case ElementKind.PROPERTY: { + case ElementKind.Property: { let selfProperty = self; let baseProperty = base; let selfGetter = selfProperty.getterInstance; @@ -3101,9 +3101,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); } } @@ -3127,7 +3127,7 @@ export class File extends Element { public source: Source ) { super( - ElementKind.FILE, + ElementKind.File, source.normalizedPath, source.internalPath, program, @@ -3147,12 +3147,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 @@ -3186,7 +3186,7 @@ export class File extends Element { let 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++) { @@ -3226,7 +3226,7 @@ export class File extends Element { let declaration = this.program.makeNativeNamespaceDeclaration(name); declaration.name = localIdentifier; let 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 @@ -3267,10 +3267,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, @@ -3303,10 +3303,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, @@ -3336,10 +3336,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, @@ -3361,18 +3361,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. */ @@ -3392,7 +3392,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 @@ -3414,18 +3414,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); } } @@ -3441,10 +3441,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 @@ -3477,7 +3477,7 @@ export class Global extends VariableLikeElement { declaration: VariableLikeDeclarationStatement = parent.program.makeNativeVariableDeclaration(name) ) { super( - ElementKind.GLOBAL, + ElementKind.Global, name, parent, declaration @@ -3519,7 +3519,7 @@ export class Local extends VariableLikeElement { declaration: VariableLikeDeclarationStatement = parent.program.makeNativeVariableDeclaration(name) ) { super( - ElementKind.LOCAL, + ElementKind.Local, name, parent, declaration @@ -3535,7 +3535,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. */ @@ -3553,12 +3553,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 @@ -3590,19 +3590,19 @@ export class FunctionPrototype extends DeclaredElement { get isBound(): bool { let parent = this.parent; let 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); let boundPrototypes = this.boundPrototypes; if (!boundPrototypes) this.boundPrototypes = boundPrototypes = new Map(); else if (boundPrototypes.has(classInstance)) return assert(boundPrototypes.get(classInstance)); let declaration = this.declaration; - assert(declaration.kind == NodeKind.METHODDECLARATION); + assert(declaration.kind == NodeKind.MethodDeclaration); let bound = new FunctionPrototype( this.name, classInstance, // ! @@ -3680,9 +3680,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 @@ -3690,14 +3690,14 @@ 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; let program = prototype.program; this.type = signature.type; this.flow = Flow.createDefault(this); - if (!prototype.is(CommonFlags.AMBIENT)) { + if (!prototype.is(CommonFlags.Ambient)) { let localIndex = 0; let thisType = signature.thisType; if (thisType) { @@ -3757,8 +3757,8 @@ export class Function extends TypedElement { /** Gets the class or interface this function belongs to, if an instance method. */ getClassOrInterface(): Class | null { let 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; @@ -3774,7 +3774,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; } @@ -3865,12 +3865,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 @@ -3916,7 +3916,7 @@ export class Field extends VariableLikeElement { type: Type ) { super( - ElementKind.FIELD, + ElementKind.Field, prototype.name, parent, prototype.declaration @@ -3932,7 +3932,7 @@ export class Field extends VariableLikeElement { /** Gets the field's `this` type. */ get thisType(): Type { let parent = this.parent; - assert(parent.kind == ElementKind.CLASS); + assert(parent.kind == ElementKind.Class); return (parent).type; } @@ -4000,34 +4000,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); let boundPrototypes = this.boundPrototypes; if (!boundPrototypes) this.boundPrototypes = boundPrototypes = new Map(); else if (boundPrototypes.has(classInstance)) return assert(boundPrototypes.get(classInstance)); let firstDeclaration = this.declaration; - assert(firstDeclaration.kind == NodeKind.METHODDECLARATION); + assert(firstDeclaration.kind == NodeKind.MethodDeclaration); let bound = new PropertyPrototype( this.name, classInstance, // ! @@ -4065,15 +4065,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 ) @@ -4081,7 +4081,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); } } @@ -4096,7 +4096,7 @@ export class IndexSignature extends TypedElement { parent: Class ) { super( - ElementKind.INDEXSIGNATURE, + ElementKind.IndexSignature, "[]", parent.internalName + "[]", parent.program, @@ -4107,12 +4107,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); } } @@ -4142,13 +4142,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 @@ -4216,8 +4216,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; @@ -4291,20 +4291,20 @@ export class Class extends TypedElement { let 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? ) ) && ( - this.lookupOverload(OperatorKind.INDEXED_GET) != null || - this.lookupOverload(OperatorKind.UNCHECKED_INDEXED_GET) != null + this.lookupOverload(OperatorKind.IndexedGet) != null || + this.lookupOverload(OperatorKind.UncheckedIndexedGet) != null ); } /** Tests if this is an interface. */ get isInterface(): bool { - return this.kind == ElementKind.INTERFACE; + return this.kind == ElementKind.Interface; } /** Constructs a new class. */ @@ -4318,9 +4318,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 @@ -4331,11 +4331,11 @@ export class Class extends TypedElement { this.decoratorFlags = prototype.decoratorFlags; this.typeArguments = typeArguments; let usizeType = program.options.usizeType; - let type = new Type(usizeType.kind, usizeType.flags & ~TypeFlags.VALUE | TypeFlags.REFERENCE, usizeType.size); + let 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); @@ -4402,7 +4402,7 @@ export class Class extends TypedElement { let 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) { @@ -4420,13 +4420,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; } @@ -4447,7 +4447,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 { let 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; @@ -4456,7 +4456,7 @@ export class Class extends TypedElement { /** Calculates the memory offset of the specified field. */ offsetof(fieldName: string): u32 { let member = assert(this.getMember(fieldName)); - assert(member.kind == ElementKind.FIELD); + assert(member.kind == ElementKind.Field); return (member).memoryOffset; } @@ -4478,7 +4478,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 { let 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; @@ -4501,18 +4501,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); } @@ -4612,7 +4612,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; } @@ -4714,14 +4714,14 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null { if (newer.members) return null; let 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); @@ -4732,30 +4732,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); @@ -4766,8 +4766,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); @@ -4776,11 +4776,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); @@ -4793,8 +4793,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, @@ -4828,23 +4828,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 f301f18e5e..6b862ceb17 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 { let nameNode = node.name; let 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 { let explicitThisType = node.explicitThisType; let thisType: Type | null = null; @@ -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; @@ -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 { let returnTypeNode = node.returnType; let 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; let 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() @@ -489,10 +489,10 @@ export class Resolver extends DiagnosticEmitter { } return null; } - let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + let overload = classReference.lookupOverload(OperatorKind.IndexedGet); 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; @@ -525,10 +525,10 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; let 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) { + 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; let 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 { let 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 { let 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 { } let 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 { let 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 @@ -737,11 +737,11 @@ 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 - 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 { let 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.sourceFunction, 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.sourceFunction, 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.sourceFunction, // 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.sourceFunction, // 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 { } let 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; } 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 @@ -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; let typeNode = global.typeNode; let 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 { let targetNode = node.expression; let 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); + let indexedGet = classInstance.lookupOverload(OperatorKind.IndexedGet); 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 { let element = this.lookupPropertyAccessExpression(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 @@ -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 { let targetExpression = node.expression; let 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 { let element = this.lookupElementAccessExpression(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 @@ -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.sourceFunction, @@ -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.sourceFunction, @@ -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 { let type = this.resolveUnaryPrefixExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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 { let operand = node.operand; let 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)) { + if (operand.isLiteralKind(LiteralKind.Integer)) { return this.determineIntegerLiteralType( operand, true, @@ -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.Plus_Plus: + case Token.Minus_Minus: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); if (!type) return null; let classReference = type.getClassOrWrapper(this.program); @@ -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() @@ -1844,26 +1844,26 @@ 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); 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 } - case Token.TILDE: { + case Token.Tilde: { let type = this.resolveExpression(operand, ctxFlow, ctxType, reportMode); 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) { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, node.range, "~", type.toString() @@ -1873,8 +1873,8 @@ export class Resolver extends DiagnosticEmitter { } return type.intType; } - case Token.DOT_DOT_DOT: { - if (reportMode == ReportMode.REPORT) { + case Token.Dot_Dot_Dot: { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Not_implemented_0, node.range, "Spread operator" @@ -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); @@ -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 { let type = this.resolveUnaryPostfixExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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,12 +1924,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 ): Type | null { let operator = node.operator; switch (operator) { - case Token.PLUS_PLUS: - case Token.MINUS_MINUS: { + 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); @@ -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 { let type = this.resolveBinaryExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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 { let left = node.left; let right = node.right; @@ -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.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: { 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.LessThan_Equals: + case Token.GreaterThan_Equals: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -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() @@ -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.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,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.Equals_Equals_Equals: + case Token.Exclamation_Equals_Equals: { 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.Asterisk_Asterisk: { let leftType = this.resolveExpression(left, ctxFlow, ctxType, reportMode); if (!leftType) return null; let classReference = leftType.getClassOrWrapper(this.program); @@ -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() @@ -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.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); @@ -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() @@ -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); @@ -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() @@ -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.Ampersand_Ampersand: + case Token.Bar_Bar: { return this.resolveExpression(left, ctxFlow, ctxType, reportMode); } } @@ -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 { let element = this.lookupThisExpression(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 @@ -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 { } } let parent: Element | null = ctxFlow.sourceFunction.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 { let element = this.lookupSuperExpression(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 @@ -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 { let element = this.lookupLiteralExpression(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 @@ -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 { let type = this.resolveCallExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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 { let targetExpression = node.expression; let 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 { let 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 { let 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 { let type = this.resolveTernaryExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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 { let 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; let 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 { let element = this.resolveTypeName(node.typeName, ctxFlow.sourceFunction, 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 { let element = this.lookupNewExpression(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 @@ -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 { let type = this.resolveFunctionExpression(node, ctxFlow, ctxType, reportMode); if (!type) return null; let 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.sourceFunction, 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 { - let actualParent = prototype.parent.kind == ElementKind.PROPERTY_PROTOTYPE + let actualParent = prototype.parent.kind == ElementKind.PropertyPrototype ? prototype.parent.parent : prototype.parent; let classInstance: Class | null = null; // if an instance method let 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; } @@ -2798,12 +2798,12 @@ export class Resolver extends DiagnosticEmitter { let 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; 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 let 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 { - let actualParent = prototype.parent.kind == ElementKind.PROPERTY_PROTOTYPE + let actualParent = prototype.parent.kind == ElementKind.PropertyPrototype ? prototype.parent.parent : prototype.parent; let 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 { let instanceKey = typeArguments ? typesToString(typeArguments) : ""; @@ -3037,7 +3037,7 @@ export class Resolver extends DiagnosticEmitter { // Otherwise create let 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, @@ -3361,19 +3361,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); } } @@ -3399,10 +3399,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)); @@ -3421,7 +3421,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, @@ -3439,13 +3439,13 @@ 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); - if (overloadPrototype.is(CommonFlags.GENERIC)) { + assert(overloadKind != OperatorKind.Invalid); + 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, @@ -3467,15 +3467,15 @@ 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: - 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) { + 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,15 +3487,15 @@ 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); } } } else { - if (reportMode == ReportMode.REPORT) { + if (reportMode == ReportMode.Report) { this.error( DiagnosticCode.Duplicate_decorator, operatorInstance.declaration.range @@ -3542,12 +3542,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 { let 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, @@ -3561,7 +3561,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 @@ -3585,7 +3585,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 { let instance = prototype.instance; if (instance) return instance; @@ -3613,7 +3613,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]); } @@ -3626,12 +3626,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 { let 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/tokenizer.ts b/src/tokenizer.ts index 37634e5e95..767ee03489 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -43,143 +43,143 @@ 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, + 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, // literals - IDENTIFIER, - STRINGLITERAL, - INTEGERLITERAL, - FLOATLITERAL, - TEMPLATELITERAL, + Identifier, + StringLiteral, + IntegerLiteral, + FloatLiteral, + TemplateLiteral, // meta - INVALID, - ENDOFFILE + Invalid, + EndOfFile } export const enum IdentifierHandling { - DEFAULT, - PREFER, - ALWAYS + Default, + Prefer, + Always } export function tokenFromKeyword(text: string): Token { @@ -188,191 +188,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; } } @@ -391,54 +391,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.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 "^="; default: { assert(false); return ""; @@ -479,7 +479,7 @@ export class Tokenizer extends DiagnosticEmitter { // skip bom if ( pos < end && - text.charCodeAt(pos) == CharCode.BYTEORDERMARK + text.charCodeAt(pos) == CharCode.ByteOrderMark ) { ++pos; } @@ -487,13 +487,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; } @@ -503,17 +503,17 @@ export class Tokenizer extends DiagnosticEmitter { this.end = end; } - next(identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT): Token { + next(identifierHandling: IdentifierHandling = IdentifierHandling.Default): Token { this.nextToken = -1; let token: Token; do token = this.unsafeNext(identifierHandling); - while (token == Token.INVALID); + while (token == Token.Invalid); this.token = token; return token; } private unsafeNext( - identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT, + identifierHandling: IdentifierHandling = IdentifierHandling.Default, maxTokenLength: i32 = i32.MAX_VALUE ): Token { let text = this.source.text; @@ -523,182 +523,182 @@ 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.EXCLAMATION_EQUALS_EQUALS; + return Token.Exclamation_Equals_Equals; } this.pos = pos; - return Token.EXCLAMATION_EQUALS; + return Token.Exclamation_Equals; } this.pos = pos; - return Token.EXCLAMATION; + return Token.Exclamation; } - case CharCode.DOUBLEQUOTE: - case CharCode.SINGLEQUOTE: { + case CharCode.DoubleQuote: + case CharCode.SingleQuote: { this.pos = pos; - return Token.STRINGLITERAL; + return Token.StringLiteral; } - case CharCode.BACKTICK: { + case CharCode.Backtick: { this.pos = pos; - return Token.TEMPLATELITERAL; + 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.PERCENT_EQUALS; + return Token.Percent_Equals; } this.pos = pos; - return Token.PERCENT; + 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.AMPERSAND_AMPERSAND; + return Token.Ampersand_Ampersand; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.AMPERSAND_EQUALS; + return Token.Ampersand_Equals; } } this.pos = pos; - return Token.AMPERSAND; + return Token.Ampersand; } - case CharCode.OPENPAREN: { + case CharCode.OpenParen: { this.pos = pos + 1; - return Token.OPENPAREN; + return Token.OpenParen; } - case CharCode.CLOSEPAREN: { + case CharCode.CloseParen: { this.pos = pos + 1; - return Token.CLOSEPAREN; + 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.ASTERISK_EQUALS; + return Token.Asterisk_Equals; } - 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.ASTERISK_ASTERISK_EQUALS; + return Token.Asterisk_Asterisk_Equals; } this.pos = pos; - return Token.ASTERISK_ASTERISK; + return Token.Asterisk_Asterisk; } } this.pos = pos; - return Token.ASTERISK; + 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.PLUS_PLUS; + return Token.Plus_Plus; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.PLUS_EQUALS; + return Token.Plus_Equals; } } this.pos = pos; - return Token.PLUS; + return Token.Plus; } - case CharCode.COMMA: { + case CharCode.Comma: { this.pos = pos + 1; - return Token.COMMA; + 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.MINUS_MINUS; + return Token.Minus_Minus; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.MINUS_EQUALS; + return Token.Minus_Equals; } } this.pos = pos; - return Token.MINUS; + return Token.Minus; } - case CharCode.DOT: { + case CharCode.Dot: { ++pos; if (maxTokenLength > 1 && pos < end) { 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 && - chr == CharCode.DOT && - text.charCodeAt(pos + 1) == CharCode.DOT + chr == CharCode.Dot && + text.charCodeAt(pos + 1) == CharCode.Dot ) { this.pos = pos + 2; - return Token.DOT_DOT_DOT; + return Token.Dot_Dot_Dot; } } this.pos = pos; - return Token.DOT; + 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 - let commentKind = CommentKind.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; + commentKind = CommentKind.Triple; } while (++pos < end) { - if (text.charCodeAt(pos) == CharCode.LINEFEED) { + if (text.charCodeAt(pos) == CharCode.LineFeed) { ++pos; break; } @@ -712,14 +712,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; @@ -733,20 +733,20 @@ export class Tokenizer extends DiagnosticEmitter { ); } else if (this.onComment) { this.onComment( - CommentKind.BLOCK, + CommentKind.Block, text.substring(commentStartPos, pos), this.range(commentStartPos, pos) ); } break; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.SLASH_EQUALS; + return Token.Slash_Equals; } } this.pos = pos; - return Token.SLASH; + return Token.Slash; } case CharCode._0: case CharCode._1: @@ -760,158 +760,158 @@ 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: { + case CharCode.Colon: { this.pos = pos + 1; - return Token.COLON; + return Token.Colon; } - case CharCode.SEMICOLON: { + case CharCode.Semicolon: { this.pos = pos + 1; - return Token.SEMICOLON; + 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.LESSTHAN_LESSTHAN_EQUALS; + return Token.LessThan_LessThan_Equals; } this.pos = pos; - return Token.LESSTHAN_LESSTHAN; + return Token.LessThan_LessThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.LESSTHAN_EQUALS; + return Token.LessThan_Equals; } } this.pos = pos; - return Token.LESSTHAN; + 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.EQUALS_EQUALS_EQUALS; + return Token.Equals_Equals_Equals; } this.pos = pos; - return Token.EQUALS_EQUALS; + return Token.Equals_Equals; } - if (chr == CharCode.GREATERTHAN) { + if (chr == CharCode.GreaterThan) { this.pos = pos + 1; - return Token.EQUALS_GREATERTHAN; + return Token.Equals_GreaterThan; } } this.pos = pos; - return Token.EQUALS; + 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.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS; + return Token.GreaterThan_GreaterThan_GreaterThan_Equals; } this.pos = pos; - return Token.GREATERTHAN_GREATERTHAN_GREATERTHAN; + return Token.GreaterThan_GreaterThan_GreaterThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.GREATERTHAN_GREATERTHAN_EQUALS; + return Token.GreaterThan_GreaterThan_Equals; } } this.pos = pos; - return Token.GREATERTHAN_GREATERTHAN; + return Token.GreaterThan_GreaterThan; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.GREATERTHAN_EQUALS; + return Token.GreaterThan_Equals; } } this.pos = pos; - return Token.GREATERTHAN; + return Token.GreaterThan; } - case CharCode.QUESTION: { + case CharCode.Question: { this.pos = pos + 1; - return Token.QUESTION; + return Token.Question; } - case CharCode.OPENBRACKET: { + case CharCode.OpenBracket: { this.pos = pos + 1; - return Token.OPENBRACKET; + return Token.OpenBracket; } - case CharCode.CLOSEBRACKET: { + case CharCode.CloseBracket: { this.pos = pos + 1; - return Token.CLOSEBRACKET; + 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.CARET_EQUALS; + return Token.Caret_Equals; } this.pos = pos; - return Token.CARET; + return Token.Caret; } - case CharCode.OPENBRACE: { + case CharCode.OpenBrace: { this.pos = pos + 1; - return Token.OPENBRACE; + 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.BAR_BAR; + return Token.Bar_Bar; } - if (chr == CharCode.EQUALS) { + if (chr == CharCode.Equals) { this.pos = pos + 1; - return Token.BAR_EQUALS; + return Token.Bar_Equals; } } this.pos = pos; - return Token.BAR; + return Token.Bar; } - case CharCode.CLOSEBRACE: { + case CharCode.CloseBrace: { this.pos = pos + 1; - return Token.CLOSEBRACE; + return Token.CloseBrace; } - case CharCode.TILDE: { + case CharCode.Tilde: { this.pos = pos + 1; - return Token.TILDE; + return Token.Tilde; } - case CharCode.AT: { + case CharCode.At: { this.pos = pos + 1; - return Token.AT; + return Token.At; } default: { // Unicode-aware from here on @@ -924,12 +924,12 @@ export class Tokenizer extends DiagnosticEmitter { (pos += numCodeUnits(c)) < end && isIdentifierPart(c = text.codePointAt(pos)) ) { /* nop */ } - if (identifierHandling != IdentifierHandling.ALWAYS) { + if (identifierHandling != IdentifierHandling.Always) { let maybeKeywordToken = tokenFromKeyword(text.substring(posBefore, pos)); if ( - maybeKeywordToken != Token.INVALID && + maybeKeywordToken != Token.Invalid && !( - identifierHandling == IdentifierHandling.PREFER && + identifierHandling == IdentifierHandling.Prefer && tokenIsAlsoIdentifier(maybeKeywordToken) ) ) { @@ -938,7 +938,7 @@ export class Tokenizer extends DiagnosticEmitter { } } this.pos = posBefore; - return Token.IDENTIFIER; + return Token.Identifier; } else if (isWhiteSpace(c)) { ++pos; // assume no supplementary whitespaces break; @@ -950,17 +950,17 @@ 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( checkOnNewLine: bool = false, - identifierHandling: IdentifierHandling = IdentifierHandling.DEFAULT, + identifierHandling: IdentifierHandling = IdentifierHandling.Default, maxCompoundLength: i32 = i32.MAX_VALUE ): Token { let text = this.source.text; @@ -970,7 +970,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) { @@ -989,21 +989,21 @@ export class Tokenizer extends DiagnosticEmitter { return this.nextToken; } - skipIdentifier(identifierHandling: IdentifierHandling = IdentifierHandling.PREFER): bool { - return this.skip(Token.IDENTIFIER, identifierHandling); + 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 { let posBefore = this.pos; let tokenBefore = this.token; let tokenPosBefore = this.tokenPos; let maxCompoundLength = i32.MAX_VALUE; - if (token == Token.GREATERTHAN) { // where parsing type arguments + if (token == Token.GreaterThan) { // where parsing type arguments maxCompoundLength = 1; } let 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; @@ -1096,7 +1096,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); @@ -1104,8 +1104,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; @@ -1156,12 +1156,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} @@ -1171,18 +1171,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); } } @@ -1200,13 +1200,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, @@ -1272,7 +1272,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++; @@ -1585,7 +1585,7 @@ export class Tokenizer extends DiagnosticEmitter { let end = this.end; let start = this.pos; let 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(); } @@ -1594,7 +1594,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; @@ -1737,7 +1737,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/types.ts b/src/types.ts index c8279d9e4d..521a0dbd38 100644 --- a/src/types.ts +++ b/src/types.ts @@ -25,7 +25,7 @@ import * as binaryen from "./glue/binaryen"; /** Indicates the kind of a type. */ export const enum TypeKind { /** A 1-bit unsigned integer. */ - BOOL, + Bool, // signed integers @@ -38,7 +38,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 @@ -51,7 +51,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 @@ -68,65 +68,65 @@ 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, /** Array reference. */ - ARRAYREF, + Arrayref, /** String reference. */ - STRINGREF, + Stringref, /** WTF8 string view. */ - STRINGVIEW_WTF8, + StringviewWTF8, /** WTF16 string view. */ - STRINGVIEW_WTF16, + StringviewWTF16, /** String iterator. */ - STRINGVIEW_ITER, + StringviewIter, // 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. */ @@ -154,7 +154,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; @@ -165,26 +165,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. */ @@ -200,47 +200,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. */ @@ -255,27 +255,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. */ @@ -331,7 +331,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; @@ -340,22 +340,22 @@ export class Type { /** Tests if this is a class type explicitly annotated as unmanaged. */ get isUnmanaged(): bool { let 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; @@ -384,7 +384,7 @@ export class Type { /** Computes the truncating mask in the target type. */ computeSmallIntegerMask(targetType: Type): i32 { let size = this.size; - if (!this.is(TypeFlags.UNSIGNED)) size -= 1; + if (!this.is(TypeFlags.Unsigned)) size -= 1; return ~0 >>> (targetType.size - size); } @@ -399,7 +399,7 @@ export class Type { let 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; @@ -414,7 +414,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; } @@ -452,7 +452,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; } @@ -504,11 +504,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; @@ -561,33 +561,33 @@ export class Type { } } switch (this.kind) { - case TypeKind.BOOL: return CommonNames.bool; + case TypeKind.Bool: return CommonNames.bool; case TypeKind.I8: return CommonNames.i8; case TypeKind.I16: return CommonNames.i16; case TypeKind.I32: return CommonNames.i32; case TypeKind.I64: return CommonNames.i64; - case TypeKind.ISIZE: return CommonNames.isize; + case TypeKind.Isize: return CommonNames.isize; case TypeKind.U8: return CommonNames.u8; case TypeKind.U16: return CommonNames.u16; case TypeKind.U32: return CommonNames.u32; case TypeKind.U64: return CommonNames.u64; - case TypeKind.USIZE: return CommonNames.usize; + case TypeKind.Usize: return CommonNames.usize; case TypeKind.F32: return CommonNames.f32; case TypeKind.F64: return CommonNames.f64; case TypeKind.V128: return CommonNames.v128; - case TypeKind.FUNCREF: return CommonNames.funcref; - case TypeKind.EXTERNREF: return CommonNames.externref; - case TypeKind.ANYREF: return CommonNames.anyref; - case TypeKind.EQREF: return CommonNames.eqref; - case TypeKind.I31REF: return CommonNames.i31ref; - case TypeKind.DATAREF: return CommonNames.dataref; - case TypeKind.ARRAYREF: return CommonNames.arrayref; - case TypeKind.STRINGREF: return CommonNames.stringref; - case TypeKind.STRINGVIEW_WTF8: return CommonNames.stringview_wtf8; - case TypeKind.STRINGVIEW_WTF16: return CommonNames.stringview_wtf16; - case TypeKind.STRINGVIEW_ITER: return CommonNames.stringview_iter; + case TypeKind.Funcref: return CommonNames.funcref; + case TypeKind.Externref: return CommonNames.externref; + case TypeKind.Anyref: return CommonNames.anyref; + case TypeKind.Eqref: return CommonNames.eqref; + case TypeKind.I31ref: return CommonNames.i31ref; + case TypeKind.Dataref: return CommonNames.dataref; + case TypeKind.Arrayref: return CommonNames.arrayref; + case TypeKind.Stringref: return CommonNames.stringref; + case TypeKind.StringviewWTF8: return CommonNames.stringview_wtf8; + case TypeKind.StringviewWTF16: return CommonNames.stringview_wtf16; + case TypeKind.StringviewIter: return CommonNames.stringview_iter; default: assert(false); - case TypeKind.VOID: return CommonNames.void_; + case TypeKind.Void: return CommonNames.void_; } } @@ -596,54 +596,54 @@ export class Type { /** Converts this type to its respective type reference. */ toRef(): TypeRef { switch (this.kind) { - 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; - 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.Extern, this.is(TypeFlags.NULLABLE)); + case TypeKind.Externref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Extern, 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.ARRAYREF: { - return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Array, this.is(TypeFlags.NULLABLE)); + case TypeKind.Arrayref: { + return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Array, 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; } // TODO: not used yet assert(false); @@ -654,208 +654,208 @@ 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 ); /** Array reference. */ - static readonly arrayref: Type = new Type(TypeKind.ARRAYREF, - TypeFlags.EXTERNAL | - TypeFlags.NULLABLE | - TypeFlags.REFERENCE, 0 + static readonly arrayref: Type = new Type(TypeKind.Arrayref, + TypeFlags.External | + TypeFlags.Nullable | + TypeFlags.Reference, 0 ); /** 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. */ - 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); @@ -917,7 +917,7 @@ export class Signature { let usizeType = program.options.usizeType; let 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/src/util/path.ts b/src/util/path.ts index 22c72ada6a..742d3611d9 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 2a85906729..d94f5d2f07 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: { @@ -159,21 +159,21 @@ export function isWhiteSpace(c: i32): bool { // If Unicode ever adds one, uses of this function must be updated to // conditionally advance by two code units, i.e. using `numCodeUnits`. 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; } } } @@ -262,7 +262,7 @@ export function isAlphaOrDecimal(c: i32): bool { export function isIdentifierStart(cp: i32): bool { return isAlpha(cp) || cp == CharCode._ - || cp == CharCode.DOLLAR + || cp == CharCode.Dollar || cp >= unicodeIdentifierStartMin && cp <= unicodeIdentifierStartMax && lookupInUnicodeMap(cp, unicodeIdentifierStart); } @@ -271,7 +271,7 @@ export function isIdentifierStart(cp: i32): bool { export function isIdentifierPart(cp: i32): bool { return isAlphaOrDecimal(cp) || cp == CharCode._ - || cp == CharCode.DOLLAR + || cp == CharCode.Dollar || cp >= unicodeIdentifierPartMin && cp <= unicodeIdentifierPartMax && lookupInUnicodeMap(cp, unicodeIdentifierPart); } @@ -713,50 +713,50 @@ export function escapeString(str: string, quote: CharCode): string { let 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; @@ -765,8 +765,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; @@ -775,14 +775,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; diff --git a/std/assembly/shared/feature.ts b/std/assembly/shared/feature.ts index e180e21e47..19027742ed 100644 --- a/std/assembly/shared/feature.ts +++ b/std/assembly/shared/feature.ts @@ -3,57 +3,57 @@ /** 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 /** 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. */ 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.RELAXED_SIMD: return "relaxed-simd"; - case Feature.EXTENDED_CONST: return "extended-const"; - case Feature.STRINGREF: return "stringref"; + case Feature.Memory64: return "memory64"; + case Feature.RelaxedSimd: return "relaxed-simd"; + case Feature.ExtendedConst: return "extended-const"; + case Feature.Stringref: return "stringref"; } 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, } 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)();