mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-09 21:11:27 +00:00
Ensure consistent variable modifiers
'var' is a distinct local or mutable global, 'let' a shared local
This commit is contained in:
parent
7ee6e1cf7b
commit
23a7db4dc3
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -25,15 +25,15 @@ export class Formatter extends AbstractFormatter {
|
|||||||
|
|
||||||
mapToMessages(failures: RuleFailure[]): string[] {
|
mapToMessages(failures: RuleFailure[]): string[] {
|
||||||
return failures.map((failure: RuleFailure) => {
|
return failures.map((failure: RuleFailure) => {
|
||||||
const fileName = failure.getFileName();
|
var fileName = failure.getFileName();
|
||||||
const failureString = failure.getFailure();
|
var failureString = failure.getFailure();
|
||||||
const ruleName = failure.getRuleName();
|
var ruleName = failure.getRuleName();
|
||||||
const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
|
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
|
||||||
const positionTuple = `:${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`;
|
var positionTuple = `:${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`;
|
||||||
if (this.lastSeverity == failure.getRuleSeverity() && this.lastFailure == failureString) {
|
if (this.lastSeverity == failure.getRuleSeverity() && this.lastFailure == failureString) {
|
||||||
return " in " + fileName + positionTuple;
|
return " in " + fileName + positionTuple;
|
||||||
} else {
|
} else {
|
||||||
var message = this.lastSeverity ? "\n" : "";
|
let message = this.lastSeverity ? "\n" : "";
|
||||||
switch (this.lastSeverity = failure.getRuleSeverity()) {
|
switch (this.lastSeverity = failure.getRuleSeverity()) {
|
||||||
case "warning": {
|
case "warning": {
|
||||||
message += colorYellow + "WARNING:" + colorReset;
|
message += colorYellow + "WARNING:" + colorReset;
|
||||||
|
62
lib/tslint/asVariablesRule.js
Normal file
62
lib/tslint/asVariablesRule.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
"use strict";
|
||||||
|
var __extends = (this && this.__extends) || (function () {
|
||||||
|
var extendStatics = Object.setPrototypeOf ||
|
||||||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||||
|
return function (d, b) {
|
||||||
|
extendStatics(d, b);
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
exports.__esModule = true;
|
||||||
|
var Lint = require("tslint");
|
||||||
|
var tsutils_1 = require("tsutils");
|
||||||
|
var Rule = /** @class */ (function (_super) {
|
||||||
|
__extends(Rule, _super);
|
||||||
|
function Rule() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
Rule.prototype.apply = function (sourceFile) {
|
||||||
|
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
|
||||||
|
};
|
||||||
|
Rule.TOP_LEVEL_VAR = "Top-level variable should be 'var' (distinct local or global).";
|
||||||
|
Rule.BLOCK_LEVEL_LET = "Block-level variable should be 'let' (shared local).";
|
||||||
|
return Rule;
|
||||||
|
}(Lint.Rules.AbstractRule));
|
||||||
|
exports.Rule = Rule;
|
||||||
|
var DiagnosticsWalker = /** @class */ (function (_super) {
|
||||||
|
__extends(DiagnosticsWalker, _super);
|
||||||
|
function DiagnosticsWalker() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
DiagnosticsWalker.prototype.visitVariableDeclarationList = function (node) {
|
||||||
|
if (tsutils_1.isVariableStatement(node.parent)) {
|
||||||
|
if (tsutils_1.isBlock(node.parent.parent)) {
|
||||||
|
if (tsutils_1.isFunctionScopeBoundary(node.parent.parent.parent) ||
|
||||||
|
tsutils_1.isNamespaceDeclaration(node.parent.parent.parent)) {
|
||||||
|
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
|
||||||
|
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tsutils_1.isSourceFile(node.parent.parent) ||
|
||||||
|
tsutils_1.isModuleBlock(node.parent.parent)) {
|
||||||
|
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
|
||||||
|
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
_super.prototype.visitVariableDeclarationList.call(this, node);
|
||||||
|
};
|
||||||
|
return DiagnosticsWalker;
|
||||||
|
}(Lint.RuleWalker));
|
55
lib/tslint/asVariablesRule.ts
Normal file
55
lib/tslint/asVariablesRule.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import * as ts from "typescript";
|
||||||
|
import * as Lint from "tslint";
|
||||||
|
import {
|
||||||
|
getVariableDeclarationKind,
|
||||||
|
VariableDeclarationKind,
|
||||||
|
isVariableStatement,
|
||||||
|
isBlock,
|
||||||
|
isFunctionScopeBoundary,
|
||||||
|
isSourceFile,
|
||||||
|
isNamespaceDeclaration,
|
||||||
|
isExportSpecifier,
|
||||||
|
isModuleBlock
|
||||||
|
} from "tsutils";
|
||||||
|
|
||||||
|
export class Rule extends Lint.Rules.AbstractRule {
|
||||||
|
|
||||||
|
static TOP_LEVEL_VAR = "Top-level variable should be 'var' (distinct local or global).";
|
||||||
|
static BLOCK_LEVEL_LET = "Block-level variable should be 'let' (shared local).";
|
||||||
|
|
||||||
|
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||||
|
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DiagnosticsWalker extends Lint.RuleWalker {
|
||||||
|
|
||||||
|
visitVariableDeclarationList(node: ts.VariableDeclarationList): void {
|
||||||
|
if (isVariableStatement(node.parent)) {
|
||||||
|
if (isBlock(node.parent.parent)) {
|
||||||
|
if (
|
||||||
|
isFunctionScopeBoundary(node.parent.parent.parent) ||
|
||||||
|
isNamespaceDeclaration(node.parent.parent.parent)
|
||||||
|
) {
|
||||||
|
if (getVariableDeclarationKind(node) == VariableDeclarationKind.Let) {
|
||||||
|
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
|
||||||
|
}
|
||||||
|
} else if (getVariableDeclarationKind(node) == VariableDeclarationKind.Var) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
isSourceFile(node.parent.parent) ||
|
||||||
|
isModuleBlock(node.parent.parent)
|
||||||
|
) {
|
||||||
|
if (getVariableDeclarationKind(node) == VariableDeclarationKind.Let) {
|
||||||
|
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
|
||||||
|
}
|
||||||
|
} else if (getVariableDeclarationKind(node) == VariableDeclarationKind.Var) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
} else if (getVariableDeclarationKind(node) == VariableDeclarationKind.Var) {
|
||||||
|
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
|
||||||
|
}
|
||||||
|
super.visitVariableDeclarationList(node);
|
||||||
|
}
|
||||||
|
}
|
16
src/ast.ts
16
src/ast.ts
@ -603,7 +603,7 @@ export abstract class Node {
|
|||||||
stmt.members = members; setParent(members, stmt);
|
stmt.members = members; setParent(members, stmt);
|
||||||
stmt.path = path;
|
stmt.path = path;
|
||||||
if (path) {
|
if (path) {
|
||||||
var normalizedPath = normalizePath(path.value);
|
let normalizedPath = normalizePath(path.value);
|
||||||
if (path.value.startsWith(".")) { // relative
|
if (path.value.startsWith(".")) { // relative
|
||||||
stmt.normalizedPath = resolvePath(
|
stmt.normalizedPath = resolvePath(
|
||||||
normalizedPath,
|
normalizedPath,
|
||||||
@ -1806,7 +1806,7 @@ export function addModifier(modifier: ModifierNode, modifiers: ModifierNode[] |
|
|||||||
/** Gets a specific modifier from the specified set of modifiers. */
|
/** Gets a specific modifier from the specified set of modifiers. */
|
||||||
export function getModifier(kind: ModifierKind, modifiers: ModifierNode[] | null): ModifierNode | null {
|
export function getModifier(kind: ModifierKind, modifiers: ModifierNode[] | null): ModifierNode | null {
|
||||||
if (modifiers) {
|
if (modifiers) {
|
||||||
for (var i = 0, k = modifiers.length; i < k; ++i) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
if (modifiers[i].modifierKind == kind) {
|
if (modifiers[i].modifierKind == kind) {
|
||||||
return modifiers[i];
|
return modifiers[i];
|
||||||
}
|
}
|
||||||
@ -1823,9 +1823,9 @@ export function hasModifier(kind: ModifierKind, modifiers: ModifierNode[] | null
|
|||||||
/** Gets the first decorator by name within at set of decorators, if present. */
|
/** Gets the first decorator by name within at set of decorators, if present. */
|
||||||
export function getFirstDecorator(name: string, decorators: DecoratorNode[] | null): DecoratorNode | null {
|
export function getFirstDecorator(name: string, decorators: DecoratorNode[] | null): DecoratorNode | null {
|
||||||
if (decorators) {
|
if (decorators) {
|
||||||
for (var i = 0, k = decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
var decorator = decorators[i];
|
let decorator = decorators[i];
|
||||||
var expression = decorator.name;
|
let expression = decorator.name;
|
||||||
if (expression.kind == NodeKind.IDENTIFIER && (<IdentifierExpression>expression).text == name) {
|
if (expression.kind == NodeKind.IDENTIFIER && (<IdentifierExpression>expression).text == name) {
|
||||||
return decorator;
|
return decorator;
|
||||||
}
|
}
|
||||||
@ -1879,15 +1879,15 @@ export function mangleInternalPath(path: string): string {
|
|||||||
|
|
||||||
/** Sets the parent node on an array of nodes. */
|
/** Sets the parent node on an array of nodes. */
|
||||||
function setParent(nodes: Node[], parent: Node): void {
|
function setParent(nodes: Node[], parent: Node): void {
|
||||||
for (var i = 0, k = nodes.length; i < k; ++i) {
|
for (let i = 0, k = nodes.length; i < k; ++i) {
|
||||||
nodes[i].parent = parent;
|
nodes[i].parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the parent node on an array of nullable nodes. */
|
/** Sets the parent node on an array of nullable nodes. */
|
||||||
function setParentIfNotNull(nodes: (Node | null)[], parent: Node): void {
|
function setParentIfNotNull(nodes: (Node | null)[], parent: Node): void {
|
||||||
for (var i = 0, k = nodes.length; i < k; ++i) {
|
for (let i = 0, k = nodes.length; i < k; ++i) {
|
||||||
var node = nodes[i];
|
let node = nodes[i];
|
||||||
if (node) node.parent = parent;
|
if (node) node.parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1904,7 +1904,7 @@ export function compileCall(
|
|||||||
return arg0;
|
return arg0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var abort = compileAbort(compiler, operands.length == 2 ? operands[1] : null, reportNode);
|
let abort = compileAbort(compiler, operands.length == 2 ? operands[1] : null, reportNode);
|
||||||
|
|
||||||
compiler.currentType = type.nonNullableType;
|
compiler.currentType = type.nonNullableType;
|
||||||
|
|
||||||
|
174
src/compiler.ts
174
src/compiler.ts
@ -212,9 +212,6 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
/** Already processed file names. */
|
/** Already processed file names. */
|
||||||
files: Set<string> = new Set();
|
files: Set<string> = new Set();
|
||||||
|
|
||||||
/** Trampolines used where functions are called with omitted parameters. */
|
|
||||||
trampolines: Map<Function,Map<i32,string>> = new Map();
|
|
||||||
|
|
||||||
/** Compiles a {@link Program} to a {@link Module} using the specified options. */
|
/** Compiles a {@link Program} to a {@link Module} using the specified options. */
|
||||||
static compile(program: Program, options: Options | null = null): Module {
|
static compile(program: Program, options: Options | null = null): Module {
|
||||||
return new Compiler(program, options).compile();
|
return new Compiler(program, options).compile();
|
||||||
@ -255,7 +252,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// compile entry file(s) while traversing to reachable elements
|
// compile entry file(s) while traversing to reachable elements
|
||||||
var sources = program.sources;
|
var sources = program.sources;
|
||||||
for (var i = 0, k = sources.length; i < k; ++i) {
|
for (let i = 0, k = sources.length; i < k; ++i) {
|
||||||
if (sources[i].isEntry) {
|
if (sources[i].isEntry) {
|
||||||
this.compileSource(sources[i]);
|
this.compileSource(sources[i]);
|
||||||
}
|
}
|
||||||
@ -279,7 +276,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// set up static memory segments and the heap base pointer
|
// set up static memory segments and the heap base pointer
|
||||||
if (!options.noMemory) {
|
if (!options.noMemory) {
|
||||||
var memoryOffset = this.memoryOffset;
|
let memoryOffset = this.memoryOffset;
|
||||||
memoryOffset = i64_align(memoryOffset, options.usizeType.byteSize);
|
memoryOffset = i64_align(memoryOffset, options.usizeType.byteSize);
|
||||||
this.memoryOffset = memoryOffset;
|
this.memoryOffset = memoryOffset;
|
||||||
if (options.isWasm64) {
|
if (options.isWasm64) {
|
||||||
@ -299,7 +296,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determine initial page size
|
// determine initial page size
|
||||||
var pages = i64_shr_u(i64_align(memoryOffset, 0x10000), i64_new(16, 0));
|
let pages = i64_shr_u(i64_align(memoryOffset, 0x10000), i64_new(16, 0));
|
||||||
module.setMemory(
|
module.setMemory(
|
||||||
i64_low(pages),
|
i64_low(pages),
|
||||||
Module.MAX_MEMORY_WASM32, // TODO: not WASM64 compatible yet
|
Module.MAX_MEMORY_WASM32, // TODO: not WASM64 compatible yet
|
||||||
@ -316,9 +313,10 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// set up function table
|
// set up function table
|
||||||
var functionTable = this.functionTable;
|
var functionTable = this.functionTable;
|
||||||
if (k = functionTable.length) {
|
var functionTableSize = functionTable.length;
|
||||||
var entries = new Array<FunctionRef>(k);
|
if (functionTableSize) {
|
||||||
for (i = 0; i < k; ++i) {
|
let entries = new Array<FunctionRef>(functionTableSize);
|
||||||
|
for (let i = 0; i < functionTableSize; ++i) {
|
||||||
entries[i] = functionTable[i].ref;
|
entries[i] = functionTable[i].ref;
|
||||||
}
|
}
|
||||||
module.setFunctionTable(entries);
|
module.setFunctionTable(entries);
|
||||||
@ -335,7 +333,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// try file.ts
|
// try file.ts
|
||||||
var source: Source;
|
var source: Source;
|
||||||
var expected = normalizedPathWithoutExtension + ".ts";
|
var expected = normalizedPathWithoutExtension + ".ts";
|
||||||
for (var i = 0, k = sources.length; i < k; ++i) {
|
for (let i = 0, k = sources.length; i < k; ++i) {
|
||||||
source = sources[i];
|
source = sources[i];
|
||||||
if (source.normalizedPath == expected) {
|
if (source.normalizedPath == expected) {
|
||||||
this.compileSource(source);
|
this.compileSource(source);
|
||||||
@ -345,7 +343,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// try file/index.ts
|
// try file/index.ts
|
||||||
expected = normalizedPathWithoutExtension + "/index.ts";
|
expected = normalizedPathWithoutExtension + "/index.ts";
|
||||||
for (i = 0, k = sources.length; i < k; ++i) {
|
for (let i = 0, k = sources.length; i < k; ++i) {
|
||||||
source = sources[i];
|
source = sources[i];
|
||||||
if (source.normalizedPath == expected) {
|
if (source.normalizedPath == expected) {
|
||||||
this.compileSource(source);
|
this.compileSource(source);
|
||||||
@ -355,7 +353,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// try (lib)/file.ts
|
// try (lib)/file.ts
|
||||||
expected = LIBRARY_PREFIX + normalizedPathWithoutExtension + ".ts";
|
expected = LIBRARY_PREFIX + normalizedPathWithoutExtension + ".ts";
|
||||||
for (i = 0, k = sources.length; i < k; ++i) {
|
for (let i = 0, k = sources.length; i < k; ++i) {
|
||||||
source = sources[i];
|
source = sources[i];
|
||||||
if (source.normalizedPath == expected) {
|
if (source.normalizedPath == expected) {
|
||||||
this.compileSource(source);
|
this.compileSource(source);
|
||||||
@ -470,8 +468,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
compileGlobalDeclaration(declaration: VariableDeclaration): Global | null {
|
compileGlobalDeclaration(declaration: VariableDeclaration): Global | null {
|
||||||
// look up the initialized program element
|
// look up the initialized program element
|
||||||
var element = this.program.elements.get(declaration.fileLevelInternalName);
|
var element = assert(this.program.elements.get(declaration.fileLevelInternalName));
|
||||||
if (!element || element.kind != ElementKind.GLOBAL) throw new Error("global expected");
|
assert(element.kind == ElementKind.GLOBAL);
|
||||||
if (!this.compileGlobal(<Global>element)) return null; // reports
|
if (!this.compileGlobal(<Global>element)) return null; // reports
|
||||||
return <Global>element;
|
return <Global>element;
|
||||||
}
|
}
|
||||||
@ -596,13 +594,12 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (initializeInStart) { // initialize to mutable zero and set the actual value in start
|
if (initializeInStart) { // initialize to mutable zero and set the actual value in start
|
||||||
this.module.addGlobal(internalName, nativeType, true, global.type.toNativeZero(this.module));
|
this.module.addGlobal(internalName, nativeType, true, global.type.toNativeZero(this.module));
|
||||||
var setExpr = this.module.createSetGlobal(internalName, initExpr);
|
this.startFunctionBody.push(this.module.createSetGlobal(internalName, initExpr));
|
||||||
this.startFunctionBody.push(setExpr);
|
|
||||||
|
|
||||||
} else { // compile as-is
|
} else { // compile as-is
|
||||||
|
|
||||||
if (global.is(ElementFlags.CONSTANT)) {
|
if (global.is(ElementFlags.CONSTANT)) {
|
||||||
var exprType = _BinaryenExpressionGetType(initExpr);
|
let exprType = _BinaryenExpressionGetType(initExpr);
|
||||||
switch (exprType) {
|
switch (exprType) {
|
||||||
case NativeType.I32: {
|
case NativeType.I32: {
|
||||||
global.constantValueKind = ConstantValueKind.INTEGER;
|
global.constantValueKind = ConstantValueKind.INTEGER;
|
||||||
@ -649,9 +646,10 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// enums
|
// enums
|
||||||
|
|
||||||
compileEnumDeclaration(declaration: EnumDeclaration): Enum | null {
|
compileEnumDeclaration(declaration: EnumDeclaration): Enum | null {
|
||||||
var element = this.program.elements.get(declaration.fileLevelInternalName);
|
var element = assert(this.program.elements.get(declaration.fileLevelInternalName));
|
||||||
if (!element || element.kind != ElementKind.ENUM) throw new Error("enum expected");
|
assert(element.kind == ElementKind.ENUM);
|
||||||
return this.compileEnum(<Enum>element) ? <Enum>element : null;
|
if (!this.compileEnum(<Enum>element)) return null;
|
||||||
|
return <Enum>element;
|
||||||
}
|
}
|
||||||
|
|
||||||
compileEnum(element: Enum): bool {
|
compileEnum(element: Enum): bool {
|
||||||
@ -661,11 +659,11 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
this.currentEnum = element;
|
this.currentEnum = element;
|
||||||
var previousValue: EnumValue | null = null;
|
var previousValue: EnumValue | null = null;
|
||||||
if (element.members) {
|
if (element.members) {
|
||||||
for (var member of element.members.values()) {
|
for (let member of element.members.values()) {
|
||||||
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
|
||||||
var initInStart = false;
|
let initInStart = false;
|
||||||
var val = <EnumValue>member;
|
let val = <EnumValue>member;
|
||||||
var valueDeclaration = val.declaration;
|
let valueDeclaration = val.declaration;
|
||||||
val.set(ElementFlags.COMPILED);
|
val.set(ElementFlags.COMPILED);
|
||||||
if (val.is(ElementFlags.INLINED)) {
|
if (val.is(ElementFlags.INLINED)) {
|
||||||
if (element.declaration.isTopLevelExport) {
|
if (element.declaration.isTopLevelExport) {
|
||||||
@ -677,7 +675,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var initExpr: ExpressionRef;
|
let initExpr: ExpressionRef;
|
||||||
if (valueDeclaration.value) {
|
if (valueDeclaration.value) {
|
||||||
initExpr = this.compileExpression(<Expression>valueDeclaration.value, Type.i32);
|
initExpr = this.compileExpression(<Expression>valueDeclaration.value, Type.i32);
|
||||||
if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) {
|
if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) {
|
||||||
@ -717,8 +715,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
true, // mutable
|
true, // mutable
|
||||||
this.module.createI32(0)
|
this.module.createI32(0)
|
||||||
);
|
);
|
||||||
var setExpr = this.module.createSetGlobal(val.internalName, initExpr);
|
this.startFunctionBody.push(this.module.createSetGlobal(val.internalName, initExpr));
|
||||||
this.startFunctionBody.push(setExpr);
|
|
||||||
} else {
|
} else {
|
||||||
this.module.addGlobal(val.internalName, NativeType.I32, false, initExpr);
|
this.module.addGlobal(val.internalName, NativeType.I32, false, initExpr);
|
||||||
if (_BinaryenExpressionGetType(initExpr) == NativeType.I32) {
|
if (_BinaryenExpressionGetType(initExpr) == NativeType.I32) {
|
||||||
@ -756,10 +753,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
typeArguments: TypeNode[],
|
typeArguments: TypeNode[],
|
||||||
contextualTypeArguments: Map<string,Type> | null = null
|
contextualTypeArguments: Map<string,Type> | null = null
|
||||||
): Function | null {
|
): Function | null {
|
||||||
var element = this.program.elements.get(declaration.fileLevelInternalName);
|
var element = assert(this.program.elements.get(declaration.fileLevelInternalName));
|
||||||
if (!element || element.kind != ElementKind.FUNCTION_PROTOTYPE) {
|
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
|
||||||
throw new Error("function expected");
|
|
||||||
}
|
|
||||||
return this.compileFunctionUsingTypeArguments( // reports
|
return this.compileFunctionUsingTypeArguments( // reports
|
||||||
<FunctionPrototype>element,
|
<FunctionPrototype>element,
|
||||||
typeArguments,
|
typeArguments,
|
||||||
@ -780,8 +775,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
contextualTypeArguments,
|
contextualTypeArguments,
|
||||||
reportNode
|
reportNode
|
||||||
);
|
);
|
||||||
if (!instance) return null;
|
if (!(instance && this.compileFunction(instance))) return null;
|
||||||
return this.compileFunction(instance) ? instance : null;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Either reuses or creates the function type matching the specified signature. */
|
/** Either reuses or creates the function type matching the specified signature. */
|
||||||
@ -891,8 +886,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
compileNamespaceDeclaration(declaration: NamespaceDeclaration): void {
|
compileNamespaceDeclaration(declaration: NamespaceDeclaration): void {
|
||||||
var members = declaration.members;
|
var members = declaration.members;
|
||||||
var noTreeShaking = this.options.noTreeShaking;
|
var noTreeShaking = this.options.noTreeShaking;
|
||||||
for (var i = 0, k = members.length; i < k; ++i) {
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
var member = members[i];
|
let member = members[i];
|
||||||
switch (member.kind) {
|
switch (member.kind) {
|
||||||
case NodeKind.CLASSDECLARATION: {
|
case NodeKind.CLASSDECLARATION: {
|
||||||
if (
|
if (
|
||||||
@ -951,7 +946,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
noTreeShaking ||
|
noTreeShaking ||
|
||||||
hasModifier(ModifierKind.EXPORT, (<VariableStatement>member).modifiers)
|
hasModifier(ModifierKind.EXPORT, (<VariableStatement>member).modifiers)
|
||||||
) {
|
) {
|
||||||
var variableInit = this.compileVariableStatement(<VariableStatement>member, true);
|
let variableInit = this.compileVariableStatement(<VariableStatement>member, true);
|
||||||
if (variableInit) this.startFunctionBody.push(variableInit);
|
if (variableInit) this.startFunctionBody.push(variableInit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -967,7 +962,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
if (!ns.members) return;
|
if (!ns.members) return;
|
||||||
|
|
||||||
var noTreeShaking = this.options.noTreeShaking;
|
var noTreeShaking = this.options.noTreeShaking;
|
||||||
for (var element of ns.members.values()) {
|
for (let element of ns.members.values()) {
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
case ElementKind.CLASS_PROTOTYPE: {
|
case ElementKind.CLASS_PROTOTYPE: {
|
||||||
if (
|
if (
|
||||||
@ -1015,14 +1010,14 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
compileExportStatement(statement: ExportStatement): void {
|
compileExportStatement(statement: ExportStatement): void {
|
||||||
var members = statement.members;
|
var members = statement.members;
|
||||||
for (var i = 0, k = members.length; i < k; ++i) {
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
var member = members[i];
|
let member = members[i];
|
||||||
var internalExportName = (
|
let internalExportName = (
|
||||||
statement.range.source.internalPath +
|
statement.range.source.internalPath +
|
||||||
PATH_DELIMITER +
|
PATH_DELIMITER +
|
||||||
member.externalName.text
|
member.externalName.text
|
||||||
);
|
);
|
||||||
var element = this.program.exports.get(internalExportName);
|
let element = this.program.exports.get(internalExportName);
|
||||||
if (!element) continue; // reported in Program#initialize
|
if (!element) continue; // reported in Program#initialize
|
||||||
|
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
@ -1041,14 +1036,14 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
!(<FunctionPrototype>element).is(ElementFlags.GENERIC) &&
|
!(<FunctionPrototype>element).is(ElementFlags.GENERIC) &&
|
||||||
statement.range.source.isEntry
|
statement.range.source.isEntry
|
||||||
) {
|
) {
|
||||||
var functionInstance = this.compileFunctionUsingTypeArguments(
|
let functionInstance = this.compileFunctionUsingTypeArguments(
|
||||||
<FunctionPrototype>element,
|
<FunctionPrototype>element,
|
||||||
[],
|
[],
|
||||||
null,
|
null,
|
||||||
(<FunctionPrototype>element).declaration.name
|
(<FunctionPrototype>element).declaration.name
|
||||||
);
|
);
|
||||||
if (functionInstance) {
|
if (functionInstance) {
|
||||||
var functionDeclaration = functionInstance.prototype.declaration;
|
let functionDeclaration = functionInstance.prototype.declaration;
|
||||||
if (functionDeclaration && functionDeclaration.needsExplicitExport(member)) {
|
if (functionDeclaration && functionDeclaration.needsExplicitExport(member)) {
|
||||||
this.module.addFunctionExport(functionInstance.internalName, member.externalName.text);
|
this.module.addFunctionExport(functionInstance.internalName, member.externalName.text);
|
||||||
}
|
}
|
||||||
@ -1058,7 +1053,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
case ElementKind.GLOBAL: {
|
case ElementKind.GLOBAL: {
|
||||||
if (this.compileGlobal(<Global>element) && statement.range.source.isEntry) {
|
if (this.compileGlobal(<Global>element) && statement.range.source.isEntry) {
|
||||||
var globalDeclaration = (<Global>element).declaration;
|
let globalDeclaration = (<Global>element).declaration;
|
||||||
if (globalDeclaration && globalDeclaration.needsExplicitExport(member)) {
|
if (globalDeclaration && globalDeclaration.needsExplicitExport(member)) {
|
||||||
if ((<Global>element).is(ElementFlags.INLINED)) {
|
if ((<Global>element).is(ElementFlags.INLINED)) {
|
||||||
this.module.addGlobalExport(element.internalName, member.externalName.text);
|
this.module.addGlobalExport(element.internalName, member.externalName.text);
|
||||||
@ -1238,9 +1233,9 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileStatements(statements: Statement[]): ExpressionRef[] {
|
compileStatements(statements: Statement[]): ExpressionRef[] {
|
||||||
var k = statements.length;
|
var numStatements = statements.length;
|
||||||
var stmts = new Array<ExpressionRef>(k);
|
var stmts = new Array<ExpressionRef>(numStatements);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numStatements; ++i) {
|
||||||
stmts[i] = this.compileStatement(statements[i]);
|
stmts[i] = this.compileStatement(statements[i]);
|
||||||
}
|
}
|
||||||
return stmts; // array of 0-es in noEmit-mode
|
return stmts; // array of 0-es in noEmit-mode
|
||||||
@ -1454,10 +1449,10 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// introduce a local for evaluating the condition (exactly once)
|
// introduce a local for evaluating the condition (exactly once)
|
||||||
var tempLocal = this.currentFunction.getTempLocal(Type.u32);
|
var tempLocal = this.currentFunction.getTempLocal(Type.u32);
|
||||||
var k = statement.cases.length;
|
var numCases = statement.cases.length;
|
||||||
|
|
||||||
// Prepend initializer to inner block. Does not initiate a new branch, yet.
|
// Prepend initializer to inner block. Does not initiate a new branch, yet.
|
||||||
var breaks = new Array<ExpressionRef>(1 + k);
|
var breaks = new Array<ExpressionRef>(1 + numCases);
|
||||||
breaks[0] = this.module.createSetLocal( // initializer
|
breaks[0] = this.module.createSetLocal( // initializer
|
||||||
tempLocal.index,
|
tempLocal.index,
|
||||||
this.compileExpression(statement.condition, Type.u32)
|
this.compileExpression(statement.condition, Type.u32)
|
||||||
@ -1466,8 +1461,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// make one br_if per (possibly dynamic) labeled case (binaryen optimizes to br_table where possible)
|
// make one br_if per (possibly dynamic) labeled case (binaryen optimizes to br_table where possible)
|
||||||
var breakIndex = 1;
|
var breakIndex = 1;
|
||||||
var defaultIndex = -1;
|
var defaultIndex = -1;
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numCases; ++i) {
|
||||||
var case_ = statement.cases[i];
|
let case_ = statement.cases[i];
|
||||||
if (case_.label) {
|
if (case_.label) {
|
||||||
breaks[breakIndex++] = this.module.createBreak("case" + i.toString(10) + "|" + context,
|
breaks[breakIndex++] = this.module.createBreak("case" + i.toString(10) + "|" + context,
|
||||||
this.module.createBinary(BinaryOp.EqI32,
|
this.module.createBinary(BinaryOp.EqI32,
|
||||||
@ -1491,19 +1486,19 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// nest blocks in order
|
// nest blocks in order
|
||||||
var currentBlock = this.module.createBlock("case0|" + context, breaks, NativeType.None);
|
var currentBlock = this.module.createBlock("case0|" + context, breaks, NativeType.None);
|
||||||
var alwaysReturns = true;
|
var alwaysReturns = true;
|
||||||
for (i = 0; i < k; ++i) {
|
for (let i = 0; i < numCases; ++i) {
|
||||||
case_ = statement.cases[i];
|
let case_ = statement.cases[i];
|
||||||
var l = case_.statements.length;
|
let l = case_.statements.length;
|
||||||
var body = new Array<ExpressionRef>(1 + l);
|
let body = new Array<ExpressionRef>(1 + l);
|
||||||
body[0] = currentBlock;
|
body[0] = currentBlock;
|
||||||
|
|
||||||
// Each switch case initiates a new branch
|
// Each switch case initiates a new branch
|
||||||
this.currentFunction.flow = this.currentFunction.flow.enterBranchOrScope();
|
this.currentFunction.flow = this.currentFunction.flow.enterBranchOrScope();
|
||||||
var breakLabel = this.currentFunction.flow.breakLabel = "break|" + context;
|
let breakLabel = this.currentFunction.flow.breakLabel = "break|" + context;
|
||||||
|
|
||||||
var fallsThrough = i != k - 1;
|
let fallsThrough = i != numCases - 1;
|
||||||
var nextLabel = !fallsThrough ? breakLabel : "case" + (i + 1).toString(10) + "|" + context;
|
let nextLabel = !fallsThrough ? breakLabel : "case" + (i + 1).toString(10) + "|" + context;
|
||||||
for (var j = 0; j < l; ++j) {
|
for (let j = 0; j < l; ++j) {
|
||||||
body[j + 1] = this.compileStatement(case_.statements[j]);
|
body[j + 1] = this.compileStatement(case_.statements[j]);
|
||||||
}
|
}
|
||||||
if (!(fallsThrough || this.currentFunction.flow.is(FlowFlags.RETURNS))) {
|
if (!(fallsThrough || this.currentFunction.flow.is(FlowFlags.RETURNS))) {
|
||||||
@ -1549,6 +1544,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
*/
|
*/
|
||||||
compileVariableStatement(statement: VariableStatement, isKnownGlobal: bool = false): ExpressionRef {
|
compileVariableStatement(statement: VariableStatement, isKnownGlobal: bool = false): ExpressionRef {
|
||||||
var declarations = statement.declarations;
|
var declarations = statement.declarations;
|
||||||
|
var numDeclarations = declarations.length;
|
||||||
|
|
||||||
// top-level variables and constants become globals
|
// top-level variables and constants become globals
|
||||||
if (isKnownGlobal || (
|
if (isKnownGlobal || (
|
||||||
@ -1560,7 +1556,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// within any function declared in the same source, which is unknown at this point. the only
|
// within any function declared in the same source, which is unknown at this point. the only
|
||||||
// efficient way to deal with this would be to keep track of all occasions it is used and
|
// efficient way to deal with this would be to keep track of all occasions it is used and
|
||||||
// replace these instructions afterwards, dynamically. (TOOD: what about a Binaryen pass?)
|
// replace these instructions afterwards, dynamically. (TOOD: what about a Binaryen pass?)
|
||||||
for (var i = 0, k = declarations.length; i < k; ++i) {
|
for (let i = 0; i < numDeclarations; ++i) {
|
||||||
this.compileGlobalDeclaration(declarations[i]);
|
this.compileGlobalDeclaration(declarations[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1568,11 +1564,11 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// other variables become locals
|
// other variables become locals
|
||||||
var initializers = new Array<ExpressionRef>();
|
var initializers = new Array<ExpressionRef>();
|
||||||
for (i = 0, k = declarations.length; i < k; ++i) {
|
for (let i = 0; i < numDeclarations; ++i) {
|
||||||
var declaration = declarations[i];
|
let declaration = declarations[i];
|
||||||
var name = declaration.name.text;
|
let name = declaration.name.text;
|
||||||
var type: Type | null = null;
|
let type: Type | null = null;
|
||||||
var init: ExpressionRef = 0;
|
let init: ExpressionRef = 0;
|
||||||
if (declaration.type) {
|
if (declaration.type) {
|
||||||
type = this.program.resolveType( // reports
|
type = this.program.resolveType( // reports
|
||||||
declaration.type,
|
declaration.type,
|
||||||
@ -1607,7 +1603,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
if (init) {
|
if (init) {
|
||||||
init = this.precomputeExpressionRef(init);
|
init = this.precomputeExpressionRef(init);
|
||||||
if (_BinaryenExpressionGetId(init) == ExpressionId.Const) {
|
if (_BinaryenExpressionGetId(init) == ExpressionId.Const) {
|
||||||
var local = new Local(this.program, name, -1, type);
|
let local = new Local(this.program, name, -1, type);
|
||||||
switch (_BinaryenExpressionGetType(init)) {
|
switch (_BinaryenExpressionGetType(init)) {
|
||||||
case NativeType.I32: {
|
case NativeType.I32: {
|
||||||
local = local.withConstantIntegerValue(_BinaryenConstGetValueI32(init), 0);
|
local = local.withConstantIntegerValue(_BinaryenConstGetValueI32(init), 0);
|
||||||
@ -1633,7 +1629,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create a virtual local that doesn't actually exist in WebAssembly
|
// Create a virtual local that doesn't actually exist in WebAssembly
|
||||||
var scopedLocals = this.currentFunction.flow.scopedLocals;
|
let scopedLocals = this.currentFunction.flow.scopedLocals;
|
||||||
if (!scopedLocals) scopedLocals = this.currentFunction.flow.scopedLocals = new Map();
|
if (!scopedLocals) scopedLocals = this.currentFunction.flow.scopedLocals = new Map();
|
||||||
else if (scopedLocals.has(name)) {
|
else if (scopedLocals.has(name)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -4204,12 +4200,12 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
compileCommaExpression(expression: CommaExpression, contextualType: Type): ExpressionRef {
|
compileCommaExpression(expression: CommaExpression, contextualType: Type): ExpressionRef {
|
||||||
var expressions = expression.expressions;
|
var expressions = expression.expressions;
|
||||||
var k = expressions.length;
|
var numExpressions = expressions.length;
|
||||||
var exprs = new Array<ExpressionRef>(k--);
|
var exprs = new Array<ExpressionRef>(numExpressions--);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numExpressions; ++i) {
|
||||||
exprs[i] = this.compileExpression(expressions[i], Type.void); // drop all
|
exprs[i] = this.compileExpression(expressions[i], Type.void); // drop all
|
||||||
}
|
}
|
||||||
exprs[i] = this.compileExpression(expressions[i], contextualType); // except last
|
exprs[numExpressions] = this.compileExpression(expressions[numExpressions], contextualType); // except last
|
||||||
return this.module.createBlock(null, exprs, this.currentType.toNativeType());
|
return this.module.createBlock(null, exprs, this.currentType.toNativeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4381,7 +4377,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
switch (expression.literalKind) {
|
switch (expression.literalKind) {
|
||||||
case LiteralKind.ARRAY: {
|
case LiteralKind.ARRAY: {
|
||||||
assert(!implicitNegate);
|
assert(!implicitNegate);
|
||||||
var classType = contextualType.classType;
|
let classType = contextualType.classType;
|
||||||
if (
|
if (
|
||||||
classType &&
|
classType &&
|
||||||
classType == this.program.elements.get("Array") &&
|
classType == this.program.elements.get("Array") &&
|
||||||
@ -4399,7 +4395,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
case LiteralKind.FLOAT: {
|
case LiteralKind.FLOAT: {
|
||||||
var floatValue = (<FloatLiteralExpression>expression).value;
|
let floatValue = (<FloatLiteralExpression>expression).value;
|
||||||
if (implicitNegate) {
|
if (implicitNegate) {
|
||||||
floatValue = -floatValue;
|
floatValue = -floatValue;
|
||||||
}
|
}
|
||||||
@ -4410,7 +4406,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
return this.module.createF64(floatValue);
|
return this.module.createF64(floatValue);
|
||||||
}
|
}
|
||||||
case LiteralKind.INTEGER: {
|
case LiteralKind.INTEGER: {
|
||||||
var intValue = (<IntegerLiteralExpression>expression).value;
|
let intValue = (<IntegerLiteralExpression>expression).value;
|
||||||
if (implicitNegate) {
|
if (implicitNegate) {
|
||||||
intValue = i64_sub(
|
intValue = i64_sub(
|
||||||
i64_new(0),
|
i64_new(0),
|
||||||
@ -4512,13 +4508,13 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
compileStaticString(stringValue: string): ExpressionRef {
|
compileStaticString(stringValue: string): ExpressionRef {
|
||||||
var stringSegment: MemorySegment | null = this.stringSegments.get(stringValue);
|
var stringSegment: MemorySegment | null = this.stringSegments.get(stringValue);
|
||||||
if (!stringSegment) {
|
if (!stringSegment) {
|
||||||
var stringLength = stringValue.length;
|
let stringLength = stringValue.length;
|
||||||
var stringBuffer = new Uint8Array(4 + stringLength * 2);
|
let stringBuffer = new Uint8Array(4 + stringLength * 2);
|
||||||
stringBuffer[0] = stringLength & 0xff;
|
stringBuffer[0] = stringLength & 0xff;
|
||||||
stringBuffer[1] = (stringLength >>> 8) & 0xff;
|
stringBuffer[1] = (stringLength >>> 8) & 0xff;
|
||||||
stringBuffer[2] = (stringLength >>> 16) & 0xff;
|
stringBuffer[2] = (stringLength >>> 16) & 0xff;
|
||||||
stringBuffer[3] = (stringLength >>> 24) & 0xff;
|
stringBuffer[3] = (stringLength >>> 24) & 0xff;
|
||||||
for (var i = 0; i < stringLength; ++i) {
|
for (let i = 0; i < stringLength; ++i) {
|
||||||
stringBuffer[4 + i * 2] = stringValue.charCodeAt(i) & 0xff;
|
stringBuffer[4 + i * 2] = stringValue.charCodeAt(i) & 0xff;
|
||||||
stringBuffer[5 + i * 2] = (stringValue.charCodeAt(i) >>> 8) & 0xff;
|
stringBuffer[5 + i * 2] = (stringValue.charCodeAt(i) >>> 8) & 0xff;
|
||||||
}
|
}
|
||||||
@ -4567,7 +4563,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var exprs = new Array<ExpressionRef>(size);
|
var exprs = new Array<ExpressionRef>(size);
|
||||||
var expr: BinaryenExpressionRef;
|
var expr: BinaryenExpressionRef;
|
||||||
for (var i = 0; i < size; ++i) {
|
for (let i = 0; i < size; ++i) {
|
||||||
exprs[i] = expressions[i]
|
exprs[i] = expressions[i]
|
||||||
? this.compileExpression(<Expression>expressions[i], elementType)
|
? this.compileExpression(<Expression>expressions[i], elementType)
|
||||||
: elementType.toNativeZero(this.module);
|
: elementType.toNativeZero(this.module);
|
||||||
@ -4623,26 +4619,26 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
if (resolved.element.kind == ElementKind.CLASS_PROTOTYPE) {
|
if (resolved.element.kind == ElementKind.CLASS_PROTOTYPE) {
|
||||||
var prototype = <ClassPrototype>resolved.element;
|
let prototype = <ClassPrototype>resolved.element;
|
||||||
var instance = prototype.resolveUsingTypeArguments( // reports
|
let instance = prototype.resolveUsingTypeArguments( // reports
|
||||||
expression.typeArguments,
|
expression.typeArguments,
|
||||||
null,
|
null,
|
||||||
expression
|
expression
|
||||||
);
|
);
|
||||||
if (instance) {
|
if (instance) {
|
||||||
var thisExpr = compileBuiltinAllocate(this, instance, expression);
|
let thisExpr = compileBuiltinAllocate(this, instance, expression);
|
||||||
var initializers = new Array<ExpressionRef>();
|
let initializers = new Array<ExpressionRef>();
|
||||||
|
|
||||||
// use a temp local for 'this'
|
// use a temp local for 'this'
|
||||||
var tempLocal = this.currentFunction.getTempLocal(this.options.usizeType);
|
let tempLocal = this.currentFunction.getTempLocal(this.options.usizeType);
|
||||||
initializers.push(this.module.createSetLocal(tempLocal.index, thisExpr));
|
initializers.push(this.module.createSetLocal(tempLocal.index, thisExpr));
|
||||||
|
|
||||||
// apply field initializers
|
// apply field initializers
|
||||||
if (instance.members) {
|
if (instance.members) {
|
||||||
for (var member of instance.members.values()) {
|
for (let member of instance.members.values()) {
|
||||||
if (member.kind == ElementKind.FIELD) {
|
if (member.kind == ElementKind.FIELD) {
|
||||||
var field = <Field>member;
|
let field = <Field>member;
|
||||||
var fieldDeclaration = field.prototype.declaration;
|
let fieldDeclaration = field.prototype.declaration;
|
||||||
if (field.is(ElementFlags.CONSTANT)) {
|
if (field.is(ElementFlags.CONSTANT)) {
|
||||||
assert(false); // there are no built-in fields currently
|
assert(false); // there are no built-in fields currently
|
||||||
} else if (fieldDeclaration && fieldDeclaration.initializer) {
|
} else if (fieldDeclaration && fieldDeclaration.initializer) {
|
||||||
@ -4658,7 +4654,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply constructor
|
// apply constructor
|
||||||
var constructorInstance = instance.constructorInstance;
|
let constructorInstance = instance.constructorInstance;
|
||||||
if (constructorInstance) {
|
if (constructorInstance) {
|
||||||
initializers.push(this.compileCallDirect(constructorInstance, expression.arguments, expression,
|
initializers.push(this.compileCallDirect(constructorInstance, expression.arguments, expression,
|
||||||
this.module.createGetLocal(tempLocal.index, this.options.nativeSizeType)
|
this.module.createGetLocal(tempLocal.index, this.options.nativeSizeType)
|
||||||
@ -4755,9 +4751,9 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case ElementKind.PROPERTY: { // instance property (here: getter)
|
case ElementKind.PROPERTY: { // instance property (here: getter)
|
||||||
var prototype = (<Property>element).getterPrototype;
|
let prototype = (<Property>element).getterPrototype;
|
||||||
if (prototype) {
|
if (prototype) {
|
||||||
var instance = prototype.resolve(null); // reports
|
let instance = prototype.resolve(null); // reports
|
||||||
if (!instance) return this.module.createUnreachable();
|
if (!instance) return this.module.createUnreachable();
|
||||||
let signature = instance.signature;
|
let signature = instance.signature;
|
||||||
if (!this.checkCallSignature( // reports
|
if (!this.checkCallSignature( // reports
|
||||||
|
@ -37,7 +37,7 @@ export class Decompiler {
|
|||||||
this.push("function ");
|
this.push("function ");
|
||||||
this.push(name);
|
this.push(name);
|
||||||
this.push("(");
|
this.push("(");
|
||||||
for (var i: Index = 0, k: Index = _BinaryenFunctionGetNumParams(func); i < k; ++i) {
|
for (let i: Index = 0, k: Index = _BinaryenFunctionGetNumParams(func); i < k; ++i) {
|
||||||
if (i > 0) this.push(", ");
|
if (i > 0) this.push(", ");
|
||||||
this.push("$");
|
this.push("$");
|
||||||
this.push(i.toString(10));
|
this.push(i.toString(10));
|
||||||
|
@ -150,7 +150,7 @@ export function formatDiagnosticMessage(
|
|||||||
|
|
||||||
// range information if available
|
// range information if available
|
||||||
if (message.range) {
|
if (message.range) {
|
||||||
var range = message.range;
|
let range = message.range;
|
||||||
if (showContext) {
|
if (showContext) {
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
sb.push(context);
|
sb.push(context);
|
||||||
|
321
src/extra/ast.ts
321
src/extra/ast.ts
@ -314,7 +314,7 @@ export function serializeNode(node: Node, sb: string[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeSource(source: Source, sb: string[]): void {
|
export function serializeSource(source: Source, sb: string[]): void {
|
||||||
for (var i = 0, k = source.statements.length; i < k; ++i) {
|
for (let i = 0, k = source.statements.length; i < k; ++i) {
|
||||||
serializeTerminatedStatement(source.statements[i], sb);
|
serializeTerminatedStatement(source.statements[i], sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,11 +329,11 @@ export function serializeTypeNode(node: CommonTypeNode, sb: string[]): void {
|
|||||||
var typeNode = <TypeNode>node;
|
var typeNode = <TypeNode>node;
|
||||||
serializeIdentifierExpression(<IdentifierExpression>typeNode.name, sb);
|
serializeIdentifierExpression(<IdentifierExpression>typeNode.name, sb);
|
||||||
if (typeNode.typeArguments) {
|
if (typeNode.typeArguments) {
|
||||||
var k = typeNode.typeArguments.length;
|
let numTypeArguments = typeNode.typeArguments.length;
|
||||||
if (k) {
|
if (numTypeArguments) {
|
||||||
sb.push("<");
|
sb.push("<");
|
||||||
serializeTypeNode(typeNode.typeArguments[0], sb);
|
serializeTypeNode(typeNode.typeArguments[0], sb);
|
||||||
for (var i = 1; i < k; ++i) {
|
for (let i = 1; i < numTypeArguments; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeTypeNode(typeNode.typeArguments[i], sb);
|
serializeTypeNode(typeNode.typeArguments[i], sb);
|
||||||
}
|
}
|
||||||
@ -393,10 +393,10 @@ export function serializeIdentifierExpression(node: IdentifierExpression, sb: st
|
|||||||
export function serializeArrayLiteralExpression(node: ArrayLiteralExpression, sb: string[]): void {
|
export function serializeArrayLiteralExpression(node: ArrayLiteralExpression, sb: string[]): void {
|
||||||
sb.push("[");
|
sb.push("[");
|
||||||
var elements = node.elementExpressions;
|
var elements = node.elementExpressions;
|
||||||
var k = elements.length;
|
var numElements = elements.length;
|
||||||
if (k) {
|
if (numElements) {
|
||||||
if (elements[0]) serializeExpression(<Expression>elements[0], sb);
|
if (elements[0]) serializeExpression(<Expression>elements[0], sb);
|
||||||
for (var i = 1; i < k; ++i) {
|
for (let i = 1; i < numElements; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
if (elements[i]) serializeExpression(<Expression>elements[i], sb);
|
if (elements[i]) serializeExpression(<Expression>elements[i], sb);
|
||||||
}
|
}
|
||||||
@ -450,11 +450,12 @@ export function serializeCallExpression(node: CallExpression, sb: string[]): voi
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeCommaExpression(node: CommaExpression, sb: string[]): void {
|
export function serializeCommaExpression(node: CommaExpression, sb: string[]): void {
|
||||||
var k = assert(node.expressions.length);
|
var expressions = node.expressions;
|
||||||
serializeExpression(node.expressions[0], sb);
|
var numExpressions = assert(expressions.length);
|
||||||
for (var i = 1; i < k; ++i) {
|
serializeExpression(expressions[0], sb);
|
||||||
|
for (let i = 1; i < numExpressions; ++i) {
|
||||||
sb.push(",");
|
sb.push(",");
|
||||||
serializeExpression(node.expressions[i], sb);
|
serializeExpression(expressions[i], sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +526,8 @@ export function serializeStringLiteral(str: string, sb: string[], singleQuoted:
|
|||||||
var off = 0;
|
var off = 0;
|
||||||
var quote = singleQuoted ? "'" : "\"";
|
var quote = singleQuoted ? "'" : "\"";
|
||||||
sb.push(quote);
|
sb.push(quote);
|
||||||
for (var i = 0, k = str.length; i < k;) {
|
var i = 0;
|
||||||
|
for (let k = str.length; i < k;) {
|
||||||
switch (str.charCodeAt(i)) {
|
switch (str.charCodeAt(i)) {
|
||||||
case CharCode.NULL: {
|
case CharCode.NULL: {
|
||||||
if (i > off) sb.push(str.substring(off, off = i + 1));
|
if (i > off) sb.push(str.substring(off, off = i + 1));
|
||||||
@ -680,7 +682,7 @@ function serializeTerminatedStatement(statement: Statement, sb: string[]): void
|
|||||||
) {
|
) {
|
||||||
sb.push(";\n");
|
sb.push(";\n");
|
||||||
} else {
|
} else {
|
||||||
var last = sb[sb.length - 1];
|
let last = sb[sb.length - 1];
|
||||||
if (last.length && last.charCodeAt(last.length - 1) == CharCode.CLOSEBRACE) {
|
if (last.length && last.charCodeAt(last.length - 1) == CharCode.CLOSEBRACE) {
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
} else {
|
} else {
|
||||||
@ -690,71 +692,81 @@ function serializeTerminatedStatement(statement: Statement, sb: string[]): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeBlockStatement(node: BlockStatement, sb: string[]): void {
|
export function serializeBlockStatement(node: BlockStatement, sb: string[]): void {
|
||||||
|
var statements = node.statements;
|
||||||
sb.push("{\n");
|
sb.push("{\n");
|
||||||
for (var i = 0, k = node.statements.length; i < k; ++i) {
|
for (let i = 0, k = statements.length; i < k; ++i) {
|
||||||
serializeTerminatedStatement(node.statements[i], sb);
|
serializeTerminatedStatement(statements[i], sb);
|
||||||
}
|
}
|
||||||
sb.push("}");
|
sb.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeBreakStatement(node: BreakStatement, sb: string[]): void {
|
export function serializeBreakStatement(node: BreakStatement, sb: string[]): void {
|
||||||
if (node.label) {
|
var label = node.label;
|
||||||
|
if (label) {
|
||||||
sb.push("break ");
|
sb.push("break ");
|
||||||
serializeIdentifierExpression(node.label, sb);
|
serializeIdentifierExpression(label, sb);
|
||||||
} else {
|
} else {
|
||||||
sb.push("break");
|
sb.push("break");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeContinueStatement(node: ContinueStatement, sb: string[]): void {
|
export function serializeContinueStatement(node: ContinueStatement, sb: string[]): void {
|
||||||
if (node.label) {
|
var label = node.label;
|
||||||
|
if (label) {
|
||||||
sb.push("continue ");
|
sb.push("continue ");
|
||||||
serializeIdentifierExpression(node.label, sb);
|
serializeIdentifierExpression(label, sb);
|
||||||
} else {
|
} else {
|
||||||
sb.push("continue");
|
sb.push("continue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeClassDeclaration(node: ClassDeclaration, sb: string[]): void {
|
export function serializeClassDeclaration(node: ClassDeclaration, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
serializeModifier(node.modifiers[i], sb);
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
serializeModifier(modifiers[i], sb);
|
||||||
sb.push(" ");
|
sb.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push("class ");
|
sb.push("class ");
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
if (k = node.typeParameters.length) {
|
var typeParameters = node.typeParameters;
|
||||||
|
var numTypeParameters = typeParameters.length;
|
||||||
|
if (numTypeParameters) {
|
||||||
sb.push("<");
|
sb.push("<");
|
||||||
serializeTypeParameter(node.typeParameters[0], sb);
|
serializeTypeParameter(typeParameters[0], sb);
|
||||||
for (i = 1; i < k; ++i) {
|
for (let i = 1; i < numTypeParameters; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeTypeParameter(node.typeParameters[i], sb);
|
serializeTypeParameter(node.typeParameters[i], sb);
|
||||||
}
|
}
|
||||||
sb.push(">");
|
sb.push(">");
|
||||||
}
|
}
|
||||||
if (node.extendsType) {
|
var extendsType = node.extendsType;
|
||||||
|
if (extendsType) {
|
||||||
sb.push(" extends ");
|
sb.push(" extends ");
|
||||||
serializeTypeNode(node.extendsType, sb);
|
serializeTypeNode(extendsType, sb);
|
||||||
}
|
}
|
||||||
if (k = node.implementsTypes.length) {
|
var implementsTypes = node.implementsTypes;
|
||||||
|
var numImplementsTypes = implementsTypes.length;
|
||||||
|
if (numImplementsTypes) {
|
||||||
sb.push(" implements ");
|
sb.push(" implements ");
|
||||||
serializeTypeNode(node.implementsTypes[0], sb);
|
serializeTypeNode(implementsTypes[0], sb);
|
||||||
for (i = 1; i < k; ++i) {
|
for (let i = 1; i < numImplementsTypes; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeTypeNode(node.implementsTypes[i], sb);
|
serializeTypeNode(implementsTypes[i], sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push(" {\n");
|
sb.push(" {\n");
|
||||||
for (i = 0, k = node.members.length; i < k; ++i) {
|
var members = node.members;
|
||||||
serializeTerminatedStatement(node.members[i], sb);
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
|
serializeTerminatedStatement(members[i], sb);
|
||||||
}
|
}
|
||||||
sb.push("}");
|
sb.push("}");
|
||||||
}
|
}
|
||||||
@ -975,98 +987,110 @@ export function serializeIfStatement(node: IfStatement, sb: string[]): void {
|
|||||||
sb.push("if (");
|
sb.push("if (");
|
||||||
serializeExpression(node.condition, sb);
|
serializeExpression(node.condition, sb);
|
||||||
sb.push(") ");
|
sb.push(") ");
|
||||||
serializeStatement(node.ifTrue, sb);
|
var ifTrue = node.ifTrue;
|
||||||
if (node.ifTrue.kind != NodeKind.BLOCK) {
|
serializeStatement(ifTrue, sb);
|
||||||
|
if (ifTrue.kind != NodeKind.BLOCK) {
|
||||||
sb.push(";\n");
|
sb.push(";\n");
|
||||||
}
|
}
|
||||||
if (node.ifFalse) {
|
var ifFalse = node.ifFalse;
|
||||||
if (node.ifTrue.kind == NodeKind.BLOCK) {
|
if (ifFalse) {
|
||||||
|
if (ifTrue.kind == NodeKind.BLOCK) {
|
||||||
sb.push(" else ");
|
sb.push(" else ");
|
||||||
} else {
|
} else {
|
||||||
sb.push("else ");
|
sb.push("else ");
|
||||||
}
|
}
|
||||||
serializeStatement(node.ifFalse, sb);
|
serializeStatement(ifFalse, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeImportDeclaration(node: ImportDeclaration, sb: string[]): void {
|
export function serializeImportDeclaration(node: ImportDeclaration, sb: string[]): void {
|
||||||
serializeIdentifierExpression(node.externalName, sb);
|
var externalName = node.externalName;
|
||||||
if (node.externalName.text != node.name.text) {
|
var name = node.name;
|
||||||
|
serializeIdentifierExpression(externalName, sb);
|
||||||
|
if (externalName.text != name.text) {
|
||||||
sb.push(" as ");
|
sb.push(" as ");
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(name, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeImportStatement(node: ImportStatement, sb: string[]): void {
|
export function serializeImportStatement(node: ImportStatement, sb: string[]): void {
|
||||||
sb.push("import ");
|
sb.push("import ");
|
||||||
if (node.declarations) {
|
var declarations = node.declarations;
|
||||||
var k = node.declarations.length;
|
var namespaceName = node.namespaceName;
|
||||||
if (k) {
|
if (declarations) {
|
||||||
|
let numDeclarations = declarations.length;
|
||||||
|
if (numDeclarations) {
|
||||||
sb.push("{\n");
|
sb.push("{\n");
|
||||||
serializeImportDeclaration(node.declarations[0], sb);
|
serializeImportDeclaration(declarations[0], sb);
|
||||||
for (var i = 1; i < k; ++i) {
|
for (let i = 1; i < numDeclarations; ++i) {
|
||||||
sb.push(",\n");
|
sb.push(",\n");
|
||||||
serializeImportDeclaration(node.declarations[i], sb);
|
serializeImportDeclaration(declarations[i], sb);
|
||||||
}
|
}
|
||||||
sb.push("\n} from ");
|
sb.push("\n} from ");
|
||||||
} else {
|
} else {
|
||||||
sb.push("{} from ");
|
sb.push("{} from ");
|
||||||
}
|
}
|
||||||
} else if (node.namespaceName) {
|
} else if (namespaceName) {
|
||||||
sb.push("* as ");
|
sb.push("* as ");
|
||||||
serializeIdentifierExpression(node.namespaceName, sb);
|
serializeIdentifierExpression(namespaceName, sb);
|
||||||
sb.push(" from ");
|
sb.push(" from ");
|
||||||
}
|
}
|
||||||
serializeStringLiteralExpression(node.path, sb);
|
serializeStringLiteralExpression(node.path, sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeInterfaceDeclaration(node: InterfaceDeclaration, sb: string[]): void {
|
export function serializeInterfaceDeclaration(node: InterfaceDeclaration, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
serializeModifier(node.modifiers[i], sb);
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
serializeModifier(modifiers[i], sb);
|
||||||
sb.push(" ");
|
sb.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push("interface ");
|
sb.push("interface ");
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
if (k = node.typeParameters.length) {
|
var typeParameters = node.typeParameters;
|
||||||
|
var numTypeParameters = typeParameters.length;
|
||||||
|
if (numTypeParameters) {
|
||||||
sb.push("<");
|
sb.push("<");
|
||||||
serializeTypeParameter(node.typeParameters[0], sb);
|
serializeTypeParameter(node.typeParameters[0], sb);
|
||||||
for (i = 0; i < k; ++i) {
|
for (let i = 0; i < numTypeParameters; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeTypeParameter(node.typeParameters[i], sb);
|
serializeTypeParameter(node.typeParameters[i], sb);
|
||||||
}
|
}
|
||||||
sb.push(">");
|
sb.push(">");
|
||||||
}
|
}
|
||||||
if (node.extendsType) {
|
var extendsType = node.extendsType;
|
||||||
|
if (extendsType) {
|
||||||
sb.push(" extends ");
|
sb.push(" extends ");
|
||||||
serializeTypeNode(node.extendsType, sb);
|
serializeTypeNode(extendsType, sb);
|
||||||
}
|
}
|
||||||
sb.push(" {\n");
|
sb.push(" {\n");
|
||||||
for (i = 0, k = node.members.length; i < k; ++i) {
|
var members = node.members;
|
||||||
serializeTerminatedStatement(node.members[i], sb);
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
|
serializeTerminatedStatement(members[i], sb);
|
||||||
}
|
}
|
||||||
sb.push("}");
|
sb.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeMethodDeclaration(node: MethodDeclaration, sb: string[]): void {
|
export function serializeMethodDeclaration(node: MethodDeclaration, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
serializeModifier(node.modifiers[i], sb);
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
serializeModifier(modifiers[i], sb);
|
||||||
sb.push(" ");
|
sb.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1074,51 +1098,56 @@ export function serializeMethodDeclaration(node: MethodDeclaration, sb: string[]
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeNamespaceDeclaration(node: NamespaceDeclaration, sb: string[]): void {
|
export function serializeNamespaceDeclaration(node: NamespaceDeclaration, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
serializeModifier(node.modifiers[i], sb);
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
serializeModifier(modifiers[i], sb);
|
||||||
sb.push(" ");
|
sb.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push("namespace ");
|
sb.push("namespace ");
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
sb.push(" {\n");
|
sb.push(" {\n");
|
||||||
for (i = 0, k = node.members.length; i < k; ++i) {
|
var members = node.members;
|
||||||
serializeTerminatedStatement(node.members[i], sb);
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
|
serializeTerminatedStatement(members[i], sb);
|
||||||
}
|
}
|
||||||
sb.push("}");
|
sb.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeReturnStatement(node: ReturnStatement, sb: string[]): void {
|
export function serializeReturnStatement(node: ReturnStatement, sb: string[]): void {
|
||||||
if (node.value) {
|
var value = node.value;
|
||||||
|
if (value) {
|
||||||
sb.push("return ");
|
sb.push("return ");
|
||||||
serializeExpression(node.value, sb);
|
serializeExpression(value, sb);
|
||||||
} else {
|
} else {
|
||||||
sb.push("return");
|
sb.push("return");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeSwitchCase(node: SwitchCase, sb: string[]): void {
|
export function serializeSwitchCase(node: SwitchCase, sb: string[]): void {
|
||||||
if (node.label) {
|
var label = node.label;
|
||||||
|
if (label) {
|
||||||
sb.push("case ");
|
sb.push("case ");
|
||||||
serializeExpression(node.label, sb);
|
serializeExpression(label, sb);
|
||||||
sb.push(":\n");
|
sb.push(":\n");
|
||||||
} else {
|
} else {
|
||||||
sb.push("default:\n");
|
sb.push("default:\n");
|
||||||
}
|
}
|
||||||
var k = node.statements.length;
|
var statements = node.statements;
|
||||||
if (k) {
|
var numStatements = statements.length;
|
||||||
serializeTerminatedStatement(node.statements[0], sb);
|
if (numStatements) {
|
||||||
for (var i = 1; i < k; ++i) {
|
serializeTerminatedStatement(statements[0], sb);
|
||||||
|
for (let i = 1; i < numStatements; ++i) {
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
serializeTerminatedStatement(node.statements[i], sb);
|
serializeTerminatedStatement(statements[i], sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1127,8 +1156,9 @@ export function serializeSwitchStatement(node: SwitchStatement, sb: string[]): v
|
|||||||
sb.push("switch (");
|
sb.push("switch (");
|
||||||
serializeExpression(node.condition, sb);
|
serializeExpression(node.condition, sb);
|
||||||
sb.push(") {\n");
|
sb.push(") {\n");
|
||||||
for (var i = 0, k = node.cases.length; i < k; ++i) {
|
var cases = node.cases;
|
||||||
serializeSwitchCase(node.cases[i], sb);
|
for (let i = 0, k = cases.length; i < k; ++i) {
|
||||||
|
serializeSwitchCase(cases[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
sb.push("}");
|
sb.push("}");
|
||||||
@ -1141,27 +1171,30 @@ export function serializeThrowStatement(node: ThrowStatement, sb: string[]): voi
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeTryStatement(node: TryStatement, sb: string[]): void {
|
export function serializeTryStatement(node: TryStatement, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
|
||||||
sb.push("try {\n");
|
sb.push("try {\n");
|
||||||
for (i = 0, k = node.statements.length; i < k; ++i) {
|
var statements = node.statements;
|
||||||
serializeStatement(node.statements[i], sb);
|
for (let i = 0, k = statements.length; i < k; ++i) {
|
||||||
|
serializeStatement(statements[i], sb);
|
||||||
sb.push(";\n");
|
sb.push(";\n");
|
||||||
}
|
}
|
||||||
if (node.catchVariable) {
|
var catchVariable = node.catchVariable;
|
||||||
|
if (catchVariable) {
|
||||||
sb.push("} catch (");
|
sb.push("} catch (");
|
||||||
serializeIdentifierExpression(node.catchVariable, sb);
|
serializeIdentifierExpression(catchVariable, sb);
|
||||||
sb.push(") {\n");
|
sb.push(") {\n");
|
||||||
if (node.catchStatements) {
|
let catchStatements = node.catchStatements;
|
||||||
for (i = 0, k = node.catchStatements.length; i < k; ++i) {
|
if (catchStatements) {
|
||||||
serializeStatement(node.catchStatements[i], sb);
|
for (let i = 0, k = catchStatements.length; i < k; ++i) {
|
||||||
|
serializeStatement(catchStatements[i], sb);
|
||||||
sb.push(";\n");
|
sb.push(";\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.finallyStatements) {
|
var finallyStatements = node.finallyStatements;
|
||||||
|
if (finallyStatements) {
|
||||||
sb.push("} finally {\n");
|
sb.push("} finally {\n");
|
||||||
for (i = 0, k = node.finallyStatements.length; i < k; ++i) {
|
for (let i = 0, k = finallyStatements.length; i < k; ++i) {
|
||||||
serializeStatement(node.finallyStatements[i], sb);
|
serializeStatement(finallyStatements[i], sb);
|
||||||
sb.push(";\n");
|
sb.push(";\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1169,57 +1202,64 @@ export function serializeTryStatement(node: TryStatement, sb: string[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeTypeDeclaration(node: TypeDeclaration, sb: string[]): void {
|
export function serializeTypeDeclaration(node: TypeDeclaration, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
serializeModifier(node.modifiers[i], sb);
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
serializeModifier(modifiers[i], sb);
|
||||||
sb.push(" ");
|
sb.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push("type ");
|
sb.push("type ");
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
var typeParameters = node.typeParameters;
|
var typeParameters = node.typeParameters;
|
||||||
if (typeParameters && (k = typeParameters.length)) {
|
if (typeParameters) {
|
||||||
|
let numTypeParameters = typeParameters.length;
|
||||||
|
if (numTypeParameters) {
|
||||||
sb.push("<");
|
sb.push("<");
|
||||||
for (i = 0; i < k; ++i) {
|
for (let i = 0; i < numTypeParameters; ++i) {
|
||||||
serializeTypeParameter(typeParameters[i], sb);
|
serializeTypeParameter(typeParameters[i], sb);
|
||||||
}
|
}
|
||||||
sb.push(">");
|
sb.push(">");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sb.push(" = ");
|
sb.push(" = ");
|
||||||
serializeTypeNode(node.type, sb);
|
serializeTypeNode(node.type, sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeVariableDeclaration(node: VariableDeclaration, sb: string[]): void {
|
export function serializeVariableDeclaration(node: VariableDeclaration, sb: string[]): void {
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
if (node.type) {
|
var type = node.type;
|
||||||
|
if (type) {
|
||||||
sb.push(": ");
|
sb.push(": ");
|
||||||
serializeTypeNode(node.type, sb);
|
serializeTypeNode(type, sb);
|
||||||
}
|
}
|
||||||
if (node.initializer) {
|
var initializer = node.initializer;
|
||||||
|
if (initializer) {
|
||||||
sb.push(" = ");
|
sb.push(" = ");
|
||||||
serializeExpression(node.initializer, sb);
|
serializeExpression(initializer, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeVariableStatement(node: VariableStatement, sb: string[]): void {
|
export function serializeVariableStatement(node: VariableStatement, sb: string[]): void {
|
||||||
var i: i32, k: i32;
|
var decorators = node.decorators;
|
||||||
if (node.decorators) {
|
if (decorators) {
|
||||||
for (i = 0, k = node.decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
serializeDecorator(node.decorators[i], sb);
|
serializeDecorator(decorators[i], sb);
|
||||||
sb.push("\n");
|
sb.push("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var isConst = false, isLet = false;
|
var isConst = false, isLet = false;
|
||||||
if (node.modifiers) {
|
var modifiers = node.modifiers;
|
||||||
for (i = 0, k = node.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
var modifier = node.modifiers[i];
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
let modifier = modifiers[i];
|
||||||
switch (modifier.modifierKind) {
|
switch (modifier.modifierKind) {
|
||||||
case ModifierKind.CONST: {
|
case ModifierKind.CONST: {
|
||||||
assert(!isLet);
|
assert(!isLet);
|
||||||
@ -1240,9 +1280,10 @@ export function serializeVariableStatement(node: VariableStatement, sb: string[]
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push(isConst ? "const " : isLet ? "let " : "var ");
|
sb.push(isConst ? "const " : isLet ? "let " : "var ");
|
||||||
k = assert(node.declarations.length);
|
var declarations = node.declarations;
|
||||||
|
var numDeclarations = assert(declarations.length);
|
||||||
serializeVariableDeclaration(node.declarations[0], sb);
|
serializeVariableDeclaration(node.declarations[0], sb);
|
||||||
for (i = 1; i < k; ++i) {
|
for (let i = 1; i < numDeclarations; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeVariableDeclaration(node.declarations[i], sb);
|
serializeVariableDeclaration(node.declarations[i], sb);
|
||||||
}
|
}
|
||||||
@ -1260,14 +1301,15 @@ export function serializeWhileStatement(node: WhileStatement, sb: string[]): voi
|
|||||||
export function serializeDecorator(node: DecoratorNode, sb: string[]): void {
|
export function serializeDecorator(node: DecoratorNode, sb: string[]): void {
|
||||||
sb.push("@");
|
sb.push("@");
|
||||||
serializeExpression(node.name, sb);
|
serializeExpression(node.name, sb);
|
||||||
if (node.arguments) {
|
var args = node.arguments;
|
||||||
|
if (args) {
|
||||||
sb.push("(");
|
sb.push("(");
|
||||||
var k = node.arguments.length;
|
let numArgs = args.length;
|
||||||
if (k) {
|
if (numArgs) {
|
||||||
serializeExpression(node.arguments[0], sb);
|
serializeExpression(args[0], sb);
|
||||||
for (var i = 1; i < k; ++i) {
|
for (let i = 1; i < numArgs; ++i) {
|
||||||
sb.push(", ");
|
sb.push(", ");
|
||||||
serializeExpression(node.arguments[i], sb);
|
serializeExpression(args[i], sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.push(")");
|
sb.push(")");
|
||||||
@ -1279,21 +1321,24 @@ export function serializeModifier(node: ModifierNode, sb: string[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function serializeParameter(node: ParameterNode, sb: string[]): void {
|
export function serializeParameter(node: ParameterNode, sb: string[]): void {
|
||||||
if (node.parameterKind == ParameterKind.REST) {
|
var kind = node.parameterKind;
|
||||||
|
if (kind == ParameterKind.REST) {
|
||||||
sb.push("...");
|
sb.push("...");
|
||||||
}
|
}
|
||||||
serializeIdentifierExpression(node.name, sb);
|
serializeIdentifierExpression(node.name, sb);
|
||||||
if (node.type) {
|
var type = node.type;
|
||||||
if (node.parameterKind == ParameterKind.OPTIONAL && !node.initializer) {
|
var initializer = node.initializer;
|
||||||
|
if (type) {
|
||||||
|
if (kind == ParameterKind.OPTIONAL && !initializer) {
|
||||||
sb.push("?: ");
|
sb.push("?: ");
|
||||||
} else {
|
} else {
|
||||||
sb.push(": ");
|
sb.push(": ");
|
||||||
}
|
}
|
||||||
serializeTypeNode(node.type, sb);
|
serializeTypeNode(type, sb);
|
||||||
}
|
}
|
||||||
if (node.initializer) {
|
if (initializer) {
|
||||||
sb.push(" = ");
|
sb.push(" = ");
|
||||||
serializeExpression(node.initializer, sb);
|
serializeExpression(initializer, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ export class Module {
|
|||||||
static createFrom(buffer: Uint8Array): Module {
|
static createFrom(buffer: Uint8Array): Module {
|
||||||
var cArr = allocU8Array(buffer);
|
var cArr = allocU8Array(buffer);
|
||||||
try {
|
try {
|
||||||
var module = new Module();
|
let module = new Module();
|
||||||
module.ref = _BinaryenModuleRead(cArr, buffer.length);
|
module.ref = _BinaryenModuleRead(cArr, buffer.length);
|
||||||
module.out = allocate_memory(3 * 8); // LLVM C-ABI, max used is 3 * usize
|
module.out = allocate_memory(3 * 8); // LLVM C-ABI, max used is 3 * usize
|
||||||
return module;
|
return module;
|
||||||
@ -549,18 +549,19 @@ export class Module {
|
|||||||
condition: ExpressionRef,
|
condition: ExpressionRef,
|
||||||
value: ExpressionRef = 0
|
value: ExpressionRef = 0
|
||||||
): ExpressionRef {
|
): ExpressionRef {
|
||||||
var strs = new Array<usize>(names.length);
|
var numNames = names.length;
|
||||||
for (var i = 0, k: i32 = names.length; i < k; ++i) {
|
var strs = new Array<usize>(numNames);
|
||||||
|
for (let i = 0; i < numNames; ++i) {
|
||||||
strs[i] = allocString(names[i]);
|
strs[i] = allocString(names[i]);
|
||||||
}
|
}
|
||||||
var cArr = allocI32Array(strs);
|
var cArr = allocI32Array(strs);
|
||||||
var cStr = allocString(defaultName);
|
var cStr = allocString(defaultName);
|
||||||
try {
|
try {
|
||||||
return _BinaryenSwitch(this.ref, cArr, k, cStr, condition, value);
|
return _BinaryenSwitch(this.ref, cArr, numNames, cStr, condition, value);
|
||||||
} finally {
|
} finally {
|
||||||
free_memory(cStr);
|
free_memory(cStr);
|
||||||
free_memory(cArr);
|
free_memory(cArr);
|
||||||
for (i = k - 1; i >= 0; --i) free_memory(strs[i]);
|
for (let i = numNames - 1; i >= 0; --i) free_memory(strs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,9 +811,9 @@ export class Module {
|
|||||||
var segs = new Array<usize>(k);
|
var segs = new Array<usize>(k);
|
||||||
var offs = new Array<ExpressionRef>(k);
|
var offs = new Array<ExpressionRef>(k);
|
||||||
var sizs = new Array<Index>(k);
|
var sizs = new Array<Index>(k);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < k; ++i) {
|
||||||
var buffer = segments[i].buffer;
|
let buffer = segments[i].buffer;
|
||||||
var offset = segments[i].offset;
|
let offset = segments[i].offset;
|
||||||
segs[i] = allocU8Array(buffer);
|
segs[i] = allocU8Array(buffer);
|
||||||
offs[i] = target == Target.WASM64
|
offs[i] = target == Target.WASM64
|
||||||
? this.createI64(i64_low(offset), i64_high(offset))
|
? this.createI64(i64_low(offset), i64_high(offset))
|
||||||
@ -828,7 +829,7 @@ export class Module {
|
|||||||
free_memory(cArr3);
|
free_memory(cArr3);
|
||||||
free_memory(cArr2);
|
free_memory(cArr2);
|
||||||
free_memory(cArr1);
|
free_memory(cArr1);
|
||||||
for (i = k - 1; i >= 0; --i) free_memory(segs[i]);
|
for (let i = k - 1; i >= 0; --i) free_memory(segs[i]);
|
||||||
free_memory(cStr);
|
free_memory(cStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -867,21 +868,23 @@ export class Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runPasses(passes: string[], func: FunctionRef = 0): void {
|
runPasses(passes: string[], func: FunctionRef = 0): void {
|
||||||
var k = passes.length;
|
var numNames = passes.length;
|
||||||
var names = new Array<usize>(k);
|
var names = new Array<usize>(numNames);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numNames; ++i) {
|
||||||
names[i] = allocString(passes[i]);
|
names[i] = allocString(passes[i]);
|
||||||
}
|
}
|
||||||
var cArr = allocI32Array(names);
|
var cArr = allocI32Array(names);
|
||||||
try {
|
try {
|
||||||
if (func) {
|
if (func) {
|
||||||
_BinaryenFunctionRunPasses(func, this.ref, cArr, k);
|
_BinaryenFunctionRunPasses(func, this.ref, cArr, numNames);
|
||||||
} else {
|
} else {
|
||||||
_BinaryenModuleRunPasses(this.ref, cArr, k);
|
_BinaryenModuleRunPasses(this.ref, cArr, numNames);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
free_memory(cArr);
|
free_memory(cArr);
|
||||||
for (; i >= 0; --i) free_memory(names[i]);
|
for (let i = numNames; i >= 0; --i) {
|
||||||
|
free_memory(names[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,9 +904,9 @@ export class Module {
|
|||||||
try {
|
try {
|
||||||
_BinaryenModuleAllocateAndWrite(out, this.ref, cStr);
|
_BinaryenModuleAllocateAndWrite(out, this.ref, cStr);
|
||||||
binaryPtr = readInt(out);
|
binaryPtr = readInt(out);
|
||||||
var binaryBytes = readInt(out + 4);
|
let binaryBytes = readInt(out + 4);
|
||||||
sourceMapPtr = readInt(out + 4 * 2);
|
sourceMapPtr = readInt(out + 4 * 2);
|
||||||
var ret = new Binary();
|
let ret = new Binary();
|
||||||
ret.output = readBuffer(binaryPtr, binaryBytes);
|
ret.output = readBuffer(binaryPtr, binaryBytes);
|
||||||
ret.sourceMap = readString(sourceMapPtr);
|
ret.sourceMap = readString(sourceMapPtr);
|
||||||
return ret;
|
return ret;
|
||||||
@ -972,7 +975,7 @@ export class Module {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case ExpressionId.GetGlobal: {
|
case ExpressionId.GetGlobal: {
|
||||||
var globalName = _BinaryenGetGlobalGetName(expr);
|
let globalName = _BinaryenGetGlobalGetName(expr);
|
||||||
if (!globalName) break;
|
if (!globalName) break;
|
||||||
return _BinaryenGetGlobal(this.ref, globalName, _BinaryenExpressionGetType(expr));
|
return _BinaryenGetGlobal(this.ref, globalName, _BinaryenExpressionGetType(expr));
|
||||||
}
|
}
|
||||||
@ -1093,9 +1096,10 @@ export class Relooper {
|
|||||||
|
|
||||||
function allocU8Array(u8s: Uint8Array | null): usize {
|
function allocU8Array(u8s: Uint8Array | null): usize {
|
||||||
if (!u8s) return 0;
|
if (!u8s) return 0;
|
||||||
var ptr = allocate_memory(u8s.length);
|
var numValues = u8s.length;
|
||||||
|
var ptr = allocate_memory(numValues);
|
||||||
var idx = ptr;
|
var idx = ptr;
|
||||||
for (var i = 0, k = u8s.length; i < k; ++i) {
|
for (let i = 0; i < numValues; ++i) {
|
||||||
store<u8>(idx++, u8s[i]);
|
store<u8>(idx++, u8s[i]);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -1105,8 +1109,8 @@ function allocI32Array(i32s: i32[] | null): usize {
|
|||||||
if (!i32s) return 0;
|
if (!i32s) return 0;
|
||||||
var ptr = allocate_memory(i32s.length << 2);
|
var ptr = allocate_memory(i32s.length << 2);
|
||||||
var idx = ptr;
|
var idx = ptr;
|
||||||
for (var i = 0, k = i32s.length; i < k; ++i) {
|
for (let i = 0, k = i32s.length; i < k; ++i) {
|
||||||
var val = i32s[i];
|
let val = i32s[i];
|
||||||
// store<i32>(idx, val) is not portable
|
// store<i32>(idx, val) is not portable
|
||||||
store<u8>(idx , ( val & 0xff) as u8);
|
store<u8>(idx , ( val & 0xff) as u8);
|
||||||
store<u8>(idx + 1, ((val >> 8) & 0xff) as u8);
|
store<u8>(idx + 1, ((val >> 8) & 0xff) as u8);
|
||||||
@ -1119,8 +1123,8 @@ function allocI32Array(i32s: i32[] | null): usize {
|
|||||||
|
|
||||||
function stringLengthUTF8(str: string): usize {
|
function stringLengthUTF8(str: string): usize {
|
||||||
var len = 0;
|
var len = 0;
|
||||||
for (var i = 0, k = str.length; i < k; ++i) {
|
for (let i = 0, k = str.length; i < k; ++i) {
|
||||||
var u = str.charCodeAt(i);
|
let u = str.charCodeAt(i);
|
||||||
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k) {
|
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k) {
|
||||||
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
||||||
}
|
}
|
||||||
@ -1145,8 +1149,8 @@ function allocString(str: string | null): usize {
|
|||||||
if (str == null) return 0;
|
if (str == null) return 0;
|
||||||
var ptr = allocate_memory(stringLengthUTF8(str) + 1);
|
var ptr = allocate_memory(stringLengthUTF8(str) + 1);
|
||||||
var idx = ptr;
|
var idx = ptr;
|
||||||
for (var i = 0, k = str.length; i < k; ++i) {
|
for (let i = 0, k = str.length; i < k; ++i) {
|
||||||
var u = str.charCodeAt(i);
|
let u = str.charCodeAt(i);
|
||||||
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k) {
|
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k) {
|
||||||
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
||||||
}
|
}
|
||||||
@ -1194,7 +1198,7 @@ export function readInt(ptr: usize): i32 {
|
|||||||
|
|
||||||
export function readBuffer(ptr: usize, length: usize): Uint8Array {
|
export function readBuffer(ptr: usize, length: usize): Uint8Array {
|
||||||
var ret = new Uint8Array(length);
|
var ret = new Uint8Array(length);
|
||||||
for (var i: usize = 0; i < length; ++i) {
|
for (let i: usize = 0; i < length; ++i) {
|
||||||
ret[i] = load<u8>(ptr + i);
|
ret[i] = load<u8>(ptr + i);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
220
src/parser.ts
220
src/parser.ts
@ -109,11 +109,13 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
path: string,
|
path: string,
|
||||||
isEntry: bool
|
isEntry: bool
|
||||||
): void {
|
): void {
|
||||||
|
var program = this.program;
|
||||||
|
|
||||||
// check if already parsed
|
// check if already parsed
|
||||||
var normalizedPath = normalizePath(path);
|
var normalizedPath = normalizePath(path);
|
||||||
for (var i = 0, k = this.program.sources.length; i < k; ++i) {
|
var sources = program.sources;
|
||||||
if (this.program.sources[i].normalizedPath == normalizedPath) return;
|
for (let i = 0, k = sources.length; i < k; ++i) {
|
||||||
|
if (sources[i].normalizedPath == normalizedPath) return;
|
||||||
}
|
}
|
||||||
this.seenlog.add(normalizedPath);
|
this.seenlog.add(normalizedPath);
|
||||||
|
|
||||||
@ -127,13 +129,13 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
? SourceKind.LIBRARY
|
? SourceKind.LIBRARY
|
||||||
: SourceKind.DEFAULT
|
: SourceKind.DEFAULT
|
||||||
);
|
);
|
||||||
this.program.sources.push(source);
|
sources.push(source);
|
||||||
|
|
||||||
// tokenize and parse
|
// tokenize and parse
|
||||||
var tn = new Tokenizer(source, this.program.diagnostics);
|
var tn = new Tokenizer(source, program.diagnostics);
|
||||||
source.tokenizer = tn;
|
source.tokenizer = tn;
|
||||||
while (!tn.skip(Token.ENDOFFILE)) {
|
while (!tn.skip(Token.ENDOFFILE)) {
|
||||||
var statement = this.parseTopLevelStatement(tn);
|
let statement = this.parseTopLevelStatement(tn);
|
||||||
if (statement) {
|
if (statement) {
|
||||||
statement.parent = source;
|
statement.parent = source;
|
||||||
source.statements.push(statement);
|
source.statements.push(statement);
|
||||||
@ -151,7 +153,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// check decorators
|
// check decorators
|
||||||
var decorators: DecoratorNode[] | null = null;
|
var decorators: DecoratorNode[] | null = null;
|
||||||
while (tn.skip(Token.AT)) {
|
while (tn.skip(Token.AT)) {
|
||||||
var decorator = this.parseDecorator(tn);
|
let decorator = this.parseDecorator(tn);
|
||||||
if (!decorator) break;
|
if (!decorator) break;
|
||||||
if (!decorators) decorators = [];
|
if (!decorators) decorators = [];
|
||||||
decorators.push(decorator);
|
decorators.push(decorator);
|
||||||
@ -282,7 +284,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// check for decorators that weren't consumed
|
// check for decorators that weren't consumed
|
||||||
if (decorators) {
|
if (decorators) {
|
||||||
for (var i = 0, k = decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
this.error(
|
this.error(
|
||||||
DiagnosticCode.Decorators_are_not_valid_here,
|
DiagnosticCode.Decorators_are_not_valid_here,
|
||||||
decorators[i].range
|
decorators[i].range
|
||||||
@ -411,14 +413,14 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// Identifier
|
// Identifier
|
||||||
} else if (token == Token.IDENTIFIER) {
|
} else if (token == Token.IDENTIFIER) {
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var parameters = new Array<TypeNode>();
|
let parameters = new Array<TypeNode>();
|
||||||
var nullable = false;
|
let nullable = false;
|
||||||
|
|
||||||
// Name<T>
|
// Name<T>
|
||||||
if (tn.skip(Token.LESSTHAN)) {
|
if (tn.skip(Token.LESSTHAN)) {
|
||||||
do {
|
do {
|
||||||
var parameter = this.parseType(tn, true, suppressErrors);
|
let parameter = this.parseType(tn, true, suppressErrors);
|
||||||
if (!parameter) return null;
|
if (!parameter) return null;
|
||||||
parameters.push(<TypeNode>parameter);
|
parameters.push(<TypeNode>parameter);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -459,7 +461,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
// ... [][]
|
// ... [][]
|
||||||
while (tn.skip(Token.OPENBRACKET)) {
|
while (tn.skip(Token.OPENBRACKET)) {
|
||||||
var bracketStart = tn.tokenPos;
|
let bracketStart = tn.tokenPos;
|
||||||
if (!tn.skip(Token.CLOSEBRACKET)) {
|
if (!tn.skip(Token.CLOSEBRACKET)) {
|
||||||
if (!suppressErrors) {
|
if (!suppressErrors) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -469,10 +471,10 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var bracketRange = tn.range(bracketStart, tn.pos);
|
let bracketRange = tn.range(bracketStart, tn.pos);
|
||||||
|
|
||||||
// ...[] | null
|
// ...[] | null
|
||||||
nullable = false;
|
let nullable = false;
|
||||||
if (tn.skip(Token.BAR)) {
|
if (tn.skip(Token.BAR)) {
|
||||||
if (tn.skip(Token.NULL)) {
|
if (tn.skip(Token.NULL)) {
|
||||||
nullable = true;
|
nullable = true;
|
||||||
@ -522,7 +524,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
} else {
|
} else {
|
||||||
isSignature = false; // not yet known
|
isSignature = false; // not yet known
|
||||||
do {
|
do {
|
||||||
var kind = ParameterKind.DEFAULT;
|
let kind = ParameterKind.DEFAULT;
|
||||||
if (tn.skip(Token.DOT_DOT_DOT)) {
|
if (tn.skip(Token.DOT_DOT_DOT)) {
|
||||||
isSignature = true;
|
isSignature = true;
|
||||||
tn.discard(state);
|
tn.discard(state);
|
||||||
@ -549,7 +551,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else if (tn.skip(Token.IDENTIFIER)) {
|
} else if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range(tn.tokenPos, tn.pos));
|
let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range(tn.tokenPos, tn.pos));
|
||||||
if (tn.skip(Token.QUESTION)) {
|
if (tn.skip(Token.QUESTION)) {
|
||||||
isSignature = true;
|
isSignature = true;
|
||||||
tn.discard(state);
|
tn.discard(state);
|
||||||
@ -565,12 +567,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
if (tn.skip(Token.COLON)) {
|
if (tn.skip(Token.COLON)) {
|
||||||
isSignature = true;
|
isSignature = true;
|
||||||
tn.discard(state);
|
tn.discard(state);
|
||||||
var type = this.parseType(tn); // not suppressing errors because known
|
let type = this.parseType(tn); // not suppressing errors because known
|
||||||
if (!type) {
|
if (!type) {
|
||||||
this.tryParseSignatureIsSignature = isSignature;
|
this.tryParseSignatureIsSignature = isSignature;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var param = new ParameterNode();
|
let param = new ParameterNode();
|
||||||
param.parameterKind = kind;
|
param.parameterKind = kind;
|
||||||
param.name = name;
|
param.name = name;
|
||||||
param.type = type;
|
param.type = type;
|
||||||
@ -648,8 +650,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var name = tn.readIdentifier();
|
let name = tn.readIdentifier();
|
||||||
var expression: Expression = Node.createIdentifierExpression(name, tn.range(startPos, tn.pos));
|
let expression: Expression = Node.createIdentifierExpression(name, tn.range(startPos, tn.pos));
|
||||||
while (tn.skip(Token.DOT)) {
|
while (tn.skip(Token.DOT)) {
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
name = tn.readIdentifier();
|
name = tn.readIdentifier();
|
||||||
@ -666,7 +668,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var args: Expression[] | null;
|
let args: Expression[] | null;
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
args = this.parseArguments(tn);
|
args = this.parseArguments(tn);
|
||||||
if (args) {
|
if (args) {
|
||||||
@ -696,7 +698,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var members = new Array<VariableDeclaration>();
|
var members = new Array<VariableDeclaration>();
|
||||||
var isDeclare = hasModifier(ModifierKind.DECLARE, modifiers);
|
var isDeclare = hasModifier(ModifierKind.DECLARE, modifiers);
|
||||||
do {
|
do {
|
||||||
var member = this.parseVariableDeclaration(tn, isDeclare, modifiers, decorators);
|
let member = this.parseVariableDeclaration(tn, isDeclare, modifiers, decorators);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(<VariableDeclaration>member);
|
members.push(<VariableDeclaration>member);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -791,7 +793,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var members = new Array<EnumValueDeclaration>();
|
var members = new Array<EnumValueDeclaration>();
|
||||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
do {
|
do {
|
||||||
var member = this.parseEnumValue(tn);
|
let member = this.parseEnumValue(tn);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(<EnumValueDeclaration>member);
|
members.push(<EnumValueDeclaration>member);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -869,7 +871,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var typeParameters = new Array<TypeParameterNode>();
|
var typeParameters = new Array<TypeParameterNode>();
|
||||||
if (!tn.skip(Token.GREATERTHAN)) {
|
if (!tn.skip(Token.GREATERTHAN)) {
|
||||||
do {
|
do {
|
||||||
var typeParameter = this.parseTypeParameter(tn);
|
let typeParameter = this.parseTypeParameter(tn);
|
||||||
if (!typeParameter) return null;
|
if (!typeParameter) return null;
|
||||||
typeParameters.push(<TypeParameterNode>typeParameter);
|
typeParameters.push(<TypeParameterNode>typeParameter);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -896,11 +898,11 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// before: Identifier ('extends' Type)?
|
// before: Identifier ('extends' Type)?
|
||||||
|
|
||||||
if (tn.next() == Token.IDENTIFIER) {
|
if (tn.next() == Token.IDENTIFIER) {
|
||||||
var identifier = Node.createIdentifierExpression(
|
let identifier = Node.createIdentifierExpression(
|
||||||
tn.readIdentifier(),
|
tn.readIdentifier(),
|
||||||
tn.range()
|
tn.range()
|
||||||
);
|
);
|
||||||
var extendsType: TypeNode | null = null;
|
let extendsType: TypeNode | null = null;
|
||||||
if (tn.skip(Token.EXTENDS)) {
|
if (tn.skip(Token.EXTENDS)) {
|
||||||
let t = this.parseType(tn);
|
let t = this.parseType(tn);
|
||||||
if (!t) return null;
|
if (!t) return null;
|
||||||
@ -940,7 +942,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (tn.peek() != Token.CLOSEPAREN) {
|
if (tn.peek() != Token.CLOSEPAREN) {
|
||||||
do {
|
do {
|
||||||
var param = this.parseParameter(tn);
|
let param = this.parseParameter(tn);
|
||||||
if (!param) return null;
|
if (!param) return null;
|
||||||
if (seenRest && !reportedRest) {
|
if (seenRest && !reportedRest) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -997,8 +999,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
if (!isRest) startRange = tn.range();
|
if (!isRest) startRange = tn.range();
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var type: CommonTypeNode | null = null;
|
let type: CommonTypeNode | null = null;
|
||||||
if (isOptional = tn.skip(Token.QUESTION)) {
|
if (isOptional = tn.skip(Token.QUESTION)) {
|
||||||
if (isRest) {
|
if (isRest) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1011,7 +1013,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
type = this.parseType(tn);
|
type = this.parseType(tn);
|
||||||
if (!type) return null;
|
if (!type) return null;
|
||||||
}
|
}
|
||||||
var initializer: Expression | null = null;
|
let initializer: Expression | null = null;
|
||||||
if (tn.skip(Token.EQUALS)) {
|
if (tn.skip(Token.EQUALS)) {
|
||||||
if (isRest) {
|
if (isRest) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1315,12 +1317,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
|
|
||||||
var identifier = Node.createIdentifierExpression(
|
let identifier = Node.createIdentifierExpression(
|
||||||
tn.readIdentifier(),
|
tn.readIdentifier(),
|
||||||
tn.range()
|
tn.range()
|
||||||
);
|
);
|
||||||
|
|
||||||
var typeParameters: TypeParameterNode[] | null;
|
let typeParameters: TypeParameterNode[] | null;
|
||||||
if (tn.skip(Token.LESSTHAN)) {
|
if (tn.skip(Token.LESSTHAN)) {
|
||||||
typeParameters = this.parseTypeParameters(tn);
|
typeParameters = this.parseTypeParameters(tn);
|
||||||
if (!typeParameters) return null;
|
if (!typeParameters) return null;
|
||||||
@ -1328,7 +1330,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
typeParameters = [];
|
typeParameters = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var extendsType: TypeNode | null = null;
|
let extendsType: TypeNode | null = null;
|
||||||
if (tn.skip(Token.EXTENDS)) {
|
if (tn.skip(Token.EXTENDS)) {
|
||||||
let t = this.parseType(tn);
|
let t = this.parseType(tn);
|
||||||
if (!t) return null;
|
if (!t) return null;
|
||||||
@ -1342,10 +1344,10 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
extendsType = <TypeNode>t;
|
extendsType = <TypeNode>t;
|
||||||
}
|
}
|
||||||
|
|
||||||
var implementsTypes = new Array<TypeNode>();
|
let implementsTypes = new Array<TypeNode>();
|
||||||
if (tn.skip(Token.IMPLEMENTS)) {
|
if (tn.skip(Token.IMPLEMENTS)) {
|
||||||
do {
|
do {
|
||||||
var type = this.parseType(tn);
|
let type = this.parseType(tn);
|
||||||
if (!type) return null;
|
if (!type) return null;
|
||||||
implementsTypes.push(<TypeNode>type);
|
implementsTypes.push(<TypeNode>type);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -1353,11 +1355,11 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
|
|
||||||
var members = new Array<DeclarationStatement>();
|
let members = new Array<DeclarationStatement>();
|
||||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
var isDeclare = hasModifier(ModifierKind.DECLARE, modifiers);
|
let isDeclare = hasModifier(ModifierKind.DECLARE, modifiers);
|
||||||
do {
|
do {
|
||||||
var member = this.parseClassMember(tn, isDeclare);
|
let member = this.parseClassMember(tn, isDeclare);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(<DeclarationStatement>member);
|
members.push(<DeclarationStatement>member);
|
||||||
} while (!tn.skip(Token.CLOSEBRACE));
|
} while (!tn.skip(Token.CLOSEBRACE));
|
||||||
@ -1403,7 +1405,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var decorators = new Array<DecoratorNode>();
|
var decorators = new Array<DecoratorNode>();
|
||||||
while (tn.skip(Token.AT)) {
|
while (tn.skip(Token.AT)) {
|
||||||
var decorator = this.parseDecorator(tn);
|
let decorator = this.parseDecorator(tn);
|
||||||
if (!decorator) break;
|
if (!decorator) break;
|
||||||
decorators.push(<DecoratorNode>decorator);
|
decorators.push(<DecoratorNode>decorator);
|
||||||
}
|
}
|
||||||
@ -1454,11 +1456,11 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var isConstructor = tn.skip(Token.CONSTRUCTOR);
|
var isConstructor = tn.skip(Token.CONSTRUCTOR);
|
||||||
if (isConstructor || tn.skip(Token.IDENTIFIER)) {
|
if (isConstructor || tn.skip(Token.IDENTIFIER)) {
|
||||||
|
|
||||||
var name = isConstructor
|
let name = isConstructor
|
||||||
? Node.createConstructorExpression(tn.range())
|
? Node.createConstructorExpression(tn.range())
|
||||||
: Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
: Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
|
|
||||||
var typeParameters: TypeParameterNode[] | null = null;
|
let typeParameters: TypeParameterNode[] | null = null;
|
||||||
if (tn.skip(Token.LESSTHAN)) {
|
if (tn.skip(Token.LESSTHAN)) {
|
||||||
if (isConstructor) {
|
if (isConstructor) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1472,8 +1474,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
|
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
var signatureStart = tn.tokenPos;
|
let signatureStart = tn.tokenPos;
|
||||||
var parameters = this.parseParameters(tn);
|
let parameters = this.parseParameters(tn);
|
||||||
if (!parameters) return null;
|
if (!parameters) return null;
|
||||||
|
|
||||||
if (isGetter && parameters.length) {
|
if (isGetter && parameters.length) {
|
||||||
@ -1498,7 +1500,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnType: CommonTypeNode | null = null;
|
let returnType: CommonTypeNode | null = null;
|
||||||
if (tn.skip(Token.COLON)) {
|
if (tn.skip(Token.COLON)) {
|
||||||
if (name.kind == NodeKind.CONSTRUCTOR) {
|
if (name.kind == NodeKind.CONSTRUCTOR) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1523,7 +1525,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var signature = Node.createSignature(
|
let signature = Node.createSignature(
|
||||||
parameters,
|
parameters,
|
||||||
returnType,
|
returnType,
|
||||||
null,
|
null,
|
||||||
@ -1531,7 +1533,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
tn.range(signatureStart, tn.pos)
|
tn.range(signatureStart, tn.pos)
|
||||||
);
|
);
|
||||||
|
|
||||||
var body: Statement | null = null;
|
let body: Statement | null = null;
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
if (parentIsDeclare) {
|
if (parentIsDeclare) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1548,7 +1550,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
); // recoverable
|
); // recoverable
|
||||||
}
|
}
|
||||||
|
|
||||||
var retMethod = Node.createMethodDeclaration(
|
let retMethod = Node.createMethodDeclaration(
|
||||||
name,
|
name,
|
||||||
typeParameters,
|
typeParameters,
|
||||||
signature,
|
signature,
|
||||||
@ -1574,7 +1576,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// field: (':' Type)? ('=' Expression)? ';'?
|
// field: (':' Type)? ('=' Expression)? ';'?
|
||||||
} else {
|
} else {
|
||||||
var modifier: ModifierNode | null;
|
let modifier: ModifierNode | null;
|
||||||
|
|
||||||
if (modifier = getModifier(ModifierKind.ABSTRACT, modifiers)) {
|
if (modifier = getModifier(ModifierKind.ABSTRACT, modifiers)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1597,7 +1599,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
); // recoverable
|
); // recoverable
|
||||||
}
|
}
|
||||||
|
|
||||||
var type: CommonTypeNode | null = null;
|
let type: CommonTypeNode | null = null;
|
||||||
if (tn.skip(Token.COLON)) {
|
if (tn.skip(Token.COLON)) {
|
||||||
type = this.parseType(tn);
|
type = this.parseType(tn);
|
||||||
if (!type) return null;
|
if (!type) return null;
|
||||||
@ -1607,12 +1609,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
tn.range()
|
tn.range()
|
||||||
); // recoverable
|
); // recoverable
|
||||||
}
|
}
|
||||||
var initializer: Expression | null = null;
|
let initializer: Expression | null = null;
|
||||||
if (tn.skip(Token.EQUALS)) {
|
if (tn.skip(Token.EQUALS)) {
|
||||||
initializer = this.parseExpression(tn);
|
initializer = this.parseExpression(tn);
|
||||||
if (!initializer) return null;
|
if (!initializer) return null;
|
||||||
}
|
}
|
||||||
var retField = Node.createFieldDeclaration(
|
let retField = Node.createFieldDeclaration(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
initializer,
|
initializer,
|
||||||
@ -1642,15 +1644,15 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var startPos = modifiers && modifiers.length ? modifiers[0].range.start : tn.tokenPos;
|
var startPos = modifiers && modifiers.length ? modifiers[0].range.start : tn.tokenPos;
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
var members = new Array<Statement>();
|
let members = new Array<Statement>();
|
||||||
while (!tn.skip(Token.CLOSEBRACE)) {
|
while (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
var member = this.parseTopLevelStatement(tn, true);
|
let member = this.parseTopLevelStatement(tn, true);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(member);
|
members.push(member);
|
||||||
}
|
}
|
||||||
var ret = Node.createNamespaceDeclaration(
|
let ret = Node.createNamespaceDeclaration(
|
||||||
identifier,
|
identifier,
|
||||||
members,
|
members,
|
||||||
modifiers,
|
modifiers,
|
||||||
@ -1684,10 +1686,10 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var startPos = modifiers && modifiers.length ? modifiers[0].range.start : tn.tokenPos;
|
var startPos = modifiers && modifiers.length ? modifiers[0].range.start : tn.tokenPos;
|
||||||
|
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
var members = new Array<ExportMember>();
|
let members = new Array<ExportMember>();
|
||||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
do {
|
do {
|
||||||
var member = this.parseExportMember(tn);
|
let member = this.parseExportMember(tn);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(member);
|
members.push(member);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -1699,7 +1701,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path: StringLiteralExpression | null = null;
|
let path: StringLiteralExpression | null = null;
|
||||||
if (tn.skip(Token.FROM)) {
|
if (tn.skip(Token.FROM)) {
|
||||||
if (tn.skip(Token.STRINGLITERAL)) {
|
if (tn.skip(Token.STRINGLITERAL)) {
|
||||||
path = Node.createStringLiteralExpression(tn.readString(), tn.range());
|
path = Node.createStringLiteralExpression(tn.readString(), tn.range());
|
||||||
@ -1711,7 +1713,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ret = Node.createExportStatement(members, path, modifiers, tn.range(startPos, tn.pos));
|
let ret = Node.createExportStatement(members, path, modifiers, tn.range(startPos, tn.pos));
|
||||||
if (ret.normalizedPath && !this.seenlog.has(<string>ret.normalizedPath)) {
|
if (ret.normalizedPath && !this.seenlog.has(<string>ret.normalizedPath)) {
|
||||||
this.backlog.push(<string>ret.normalizedPath);
|
this.backlog.push(<string>ret.normalizedPath);
|
||||||
this.seenlog.add(<string>ret.normalizedPath);
|
this.seenlog.add(<string>ret.normalizedPath);
|
||||||
@ -1734,8 +1736,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// before: Identifier ('as' Identifier)?
|
// before: Identifier ('as' Identifier)?
|
||||||
|
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var asIdentifier: IdentifierExpression | null = null;
|
let asIdentifier: IdentifierExpression | null = null;
|
||||||
if (tn.skip(Token.AS)) {
|
if (tn.skip(Token.AS)) {
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
@ -1779,7 +1781,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
members = new Array();
|
members = new Array();
|
||||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
do {
|
do {
|
||||||
var member = this.parseImportDeclaration(tn);
|
let member = this.parseImportDeclaration(tn);
|
||||||
if (!member) return null;
|
if (!member) return null;
|
||||||
members.push(member);
|
members.push(member);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -1815,8 +1817,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (skipFrom || tn.skip(Token.FROM)) {
|
if (skipFrom || tn.skip(Token.FROM)) {
|
||||||
if (tn.skip(Token.STRINGLITERAL)) {
|
if (tn.skip(Token.STRINGLITERAL)) {
|
||||||
var path = Node.createStringLiteralExpression(tn.readString(), tn.range());
|
let path = Node.createStringLiteralExpression(tn.readString(), tn.range());
|
||||||
var ret: ImportStatement;
|
let ret: ImportStatement;
|
||||||
if (namespaceName) {
|
if (namespaceName) {
|
||||||
assert(!members);
|
assert(!members);
|
||||||
ret = Node.createImportStatementWithWildcard(namespaceName, path, tn.range(startPos, tn.pos));
|
ret = Node.createImportStatementWithWildcard(namespaceName, path, tn.range(startPos, tn.pos));
|
||||||
@ -1851,8 +1853,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// before: Identifier ('as' Identifier)?
|
// before: Identifier ('as' Identifier)?
|
||||||
|
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var asIdentifier: IdentifierExpression | null = null;
|
let asIdentifier: IdentifierExpression | null = null;
|
||||||
if (tn.skip(Token.AS)) {
|
if (tn.skip(Token.AS)) {
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
@ -1888,11 +1890,11 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// at 'export' 'import': Identifier ('=' Identifier)? ';'?
|
// at 'export' 'import': Identifier ('=' Identifier)? ';'?
|
||||||
|
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let asIdentifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
if (tn.skip(Token.EQUALS)) {
|
if (tn.skip(Token.EQUALS)) {
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var ret = Node.createExportImportStatement(identifier, asIdentifier, Range.join(startRange, tn.range()));
|
let ret = Node.createExportImportStatement(identifier, asIdentifier, Range.join(startRange, tn.range()));
|
||||||
tn.skip(Token.SEMICOLON);
|
tn.skip(Token.SEMICOLON);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
@ -2004,7 +2006,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
var statements = new Array<Statement>();
|
var statements = new Array<Statement>();
|
||||||
while (!tn.skip(Token.CLOSEBRACE)) {
|
while (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
var statement = this.parseStatement(tn, topLevel);
|
let statement = this.parseStatement(tn, topLevel);
|
||||||
if (!statement) return null;
|
if (!statement) return null;
|
||||||
statements.push(statement);
|
statements.push(statement);
|
||||||
}
|
}
|
||||||
@ -2058,11 +2060,11 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
if (tn.skip(Token.WHILE)) {
|
if (tn.skip(Token.WHILE)) {
|
||||||
|
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
var condition = this.parseExpression(tn);
|
let condition = this.parseExpression(tn);
|
||||||
if (!condition) return null;
|
if (!condition) return null;
|
||||||
|
|
||||||
if (tn.skip(Token.CLOSEPAREN)) {
|
if (tn.skip(Token.CLOSEPAREN)) {
|
||||||
var ret = Node.createDoStatement(<Statement>statement, <Expression>condition, tn.range(startPos, tn.pos));
|
let ret = Node.createDoStatement(<Statement>statement, <Expression>condition, tn.range(startPos, tn.pos));
|
||||||
tn.skip(Token.SEMICOLON);
|
tn.skip(Token.SEMICOLON);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
@ -2110,7 +2112,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
|
|
||||||
var initializer: Statement | null = null;
|
let initializer: Statement | null = null;
|
||||||
|
|
||||||
if (tn.skip(Token.LET) || tn.skip(Token.CONST) || tn.skip(Token.VAR)) {
|
if (tn.skip(Token.LET) || tn.skip(Token.CONST) || tn.skip(Token.VAR)) {
|
||||||
initializer = this.parseVariable(tn, null, null);
|
initializer = this.parseVariable(tn, null, null);
|
||||||
@ -2121,14 +2123,14 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tn.token == Token.SEMICOLON) {
|
if (tn.token == Token.SEMICOLON) {
|
||||||
var condition: ExpressionStatement | null = null;
|
let condition: ExpressionStatement | null = null;
|
||||||
if (!tn.skip(Token.SEMICOLON)) {
|
if (!tn.skip(Token.SEMICOLON)) {
|
||||||
condition = this.parseExpressionStatement(tn);
|
condition = this.parseExpressionStatement(tn);
|
||||||
if (!condition) return null;
|
if (!condition) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tn.token == Token.SEMICOLON) {
|
if (tn.token == Token.SEMICOLON) {
|
||||||
var incrementor: Expression | null = null;
|
let incrementor: Expression | null = null;
|
||||||
if (!tn.skip(Token.CLOSEPAREN)) {
|
if (!tn.skip(Token.CLOSEPAREN)) {
|
||||||
incrementor = this.parseExpression(tn);
|
incrementor = this.parseExpression(tn);
|
||||||
if (!incrementor) return null;
|
if (!incrementor) return null;
|
||||||
@ -2142,7 +2144,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var statement = this.parseStatement(tn);
|
let statement = this.parseStatement(tn);
|
||||||
if (!statement) return null;
|
if (!statement) return null;
|
||||||
|
|
||||||
return Node.createForStatement(
|
return Node.createForStatement(
|
||||||
@ -2184,12 +2186,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
var condition = this.parseExpression(tn);
|
let condition = this.parseExpression(tn);
|
||||||
if (!condition) return null;
|
if (!condition) return null;
|
||||||
if (tn.skip(Token.CLOSEPAREN)) {
|
if (tn.skip(Token.CLOSEPAREN)) {
|
||||||
var statement = this.parseStatement(tn);
|
let statement = this.parseStatement(tn);
|
||||||
if (!statement) return null;
|
if (!statement) return null;
|
||||||
var elseStatement: Statement | null = null;
|
let elseStatement: Statement | null = null;
|
||||||
if (tn.skip(Token.ELSE)) {
|
if (tn.skip(Token.ELSE)) {
|
||||||
elseStatement = this.parseStatement(tn);
|
elseStatement = this.parseStatement(tn);
|
||||||
if (!elseStatement) return null;
|
if (!elseStatement) return null;
|
||||||
@ -2223,17 +2225,17 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
var condition = this.parseExpression(tn);
|
let condition = this.parseExpression(tn);
|
||||||
if (!condition) return null;
|
if (!condition) return null;
|
||||||
if (tn.skip(Token.CLOSEPAREN)) {
|
if (tn.skip(Token.CLOSEPAREN)) {
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
var cases = new Array<SwitchCase>();
|
let cases = new Array<SwitchCase>();
|
||||||
while (!tn.skip(Token.CLOSEBRACE)) {
|
while (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
var case_ = this.parseSwitchCase(tn);
|
let case_ = this.parseSwitchCase(tn);
|
||||||
if (!case_) return null;
|
if (!case_) return null;
|
||||||
cases.push(<SwitchCase>case_);
|
cases.push(<SwitchCase>case_);
|
||||||
}
|
}
|
||||||
var ret = Node.createSwitchStatement(condition, cases, tn.range(startPos, tn.pos));
|
let ret = Node.createSwitchStatement(condition, cases, tn.range(startPos, tn.pos));
|
||||||
tn.skip(Token.SEMICOLON);
|
tn.skip(Token.SEMICOLON);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
@ -2268,7 +2270,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// 'case' Expression ':' Statement*
|
// 'case' Expression ':' Statement*
|
||||||
|
|
||||||
if (tn.skip(Token.CASE)) {
|
if (tn.skip(Token.CASE)) {
|
||||||
var label = this.parseExpression(tn);
|
let label = this.parseExpression(tn);
|
||||||
if (!label) return null;
|
if (!label) return null;
|
||||||
if (tn.skip(Token.COLON)) {
|
if (tn.skip(Token.COLON)) {
|
||||||
statements = new Array<Statement>();
|
statements = new Array<Statement>();
|
||||||
@ -2337,15 +2339,15 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
var stmt: Statement | null;
|
var stmt: Statement | null;
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
var statements = new Array<Statement>();
|
let statements = new Array<Statement>();
|
||||||
while (!tn.skip(Token.CLOSEBRACE)) {
|
while (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
stmt = this.parseStatement(tn);
|
stmt = this.parseStatement(tn);
|
||||||
if (!stmt) return null;
|
if (!stmt) return null;
|
||||||
statements.push(<Statement>stmt);
|
statements.push(<Statement>stmt);
|
||||||
}
|
}
|
||||||
var catchVariable: IdentifierExpression | null = null;
|
let catchVariable: IdentifierExpression | null = null;
|
||||||
var catchStatements: Statement[] | null = null;
|
let catchStatements: Statement[] | null = null;
|
||||||
var finallyStatements: Statement[] | null = null;
|
let finallyStatements: Statement[] | null = null;
|
||||||
if (tn.skip(Token.CATCH)) {
|
if (tn.skip(Token.CATCH)) {
|
||||||
if (!tn.skip(Token.OPENPAREN)) {
|
if (!tn.skip(Token.OPENPAREN)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -2405,7 +2407,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var ret = Node.createTryStatement(
|
let ret = Node.createTryStatement(
|
||||||
statements,
|
statements,
|
||||||
catchVariable,
|
catchVariable,
|
||||||
catchStatements,
|
catchStatements,
|
||||||
@ -2435,16 +2437,16 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
: modifiers && modifiers.length ? modifiers[0].range.start
|
: modifiers && modifiers.length ? modifiers[0].range.start
|
||||||
: tn.tokenPos;
|
: tn.tokenPos;
|
||||||
if (tn.skip(Token.IDENTIFIER)) {
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
var name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
let name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
|
||||||
var typeParameters: TypeParameterNode[] | null = null;
|
let typeParameters: TypeParameterNode[] | null = null;
|
||||||
if (tn.skip(Token.LESSTHAN)) {
|
if (tn.skip(Token.LESSTHAN)) {
|
||||||
typeParameters = this.parseTypeParameters(tn);
|
typeParameters = this.parseTypeParameters(tn);
|
||||||
if (!typeParameters) return null;
|
if (!typeParameters) return null;
|
||||||
}
|
}
|
||||||
if (tn.skip(Token.EQUALS)) {
|
if (tn.skip(Token.EQUALS)) {
|
||||||
var type = this.parseType(tn);
|
let type = this.parseType(tn);
|
||||||
if (!type) return null;
|
if (!type) return null;
|
||||||
var ret = Node.createTypeDeclaration(
|
let ret = Node.createTypeDeclaration(
|
||||||
name,
|
name,
|
||||||
typeParameters,
|
typeParameters,
|
||||||
type,
|
type,
|
||||||
@ -2491,12 +2493,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var startPos = tn.tokenPos;
|
var startPos = tn.tokenPos;
|
||||||
if (tn.skip(Token.OPENPAREN)) {
|
if (tn.skip(Token.OPENPAREN)) {
|
||||||
var expression = this.parseExpression(tn);
|
let expression = this.parseExpression(tn);
|
||||||
if (!expression) return null;
|
if (!expression) return null;
|
||||||
if (tn.skip(Token.CLOSEPAREN)) {
|
if (tn.skip(Token.CLOSEPAREN)) {
|
||||||
var statement = this.parseStatement(tn);
|
let statement = this.parseStatement(tn);
|
||||||
if (!statement) return null;
|
if (!statement) return null;
|
||||||
var ret = Node.createWhileStatement(expression, statement, tn.range(startPos, tn.pos));
|
let ret = Node.createWhileStatement(expression, statement, tn.range(startPos, tn.pos));
|
||||||
tn.skip(Token.SEMICOLON);
|
tn.skip(Token.SEMICOLON);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
@ -2537,7 +2539,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
var p = determinePrecedenceStart(token);
|
var p = determinePrecedenceStart(token);
|
||||||
if (p != Precedence.INVALID) {
|
if (p != Precedence.INVALID) {
|
||||||
var operand: Expression | null;
|
let operand: Expression | null;
|
||||||
|
|
||||||
// TODO: SpreadExpression, YieldExpression (currently become unsupported UnaryPrefixExpressions)
|
// TODO: SpreadExpression, YieldExpression (currently become unsupported UnaryPrefixExpressions)
|
||||||
|
|
||||||
@ -2595,8 +2597,8 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var state = tn.mark();
|
let state = tn.mark();
|
||||||
var again = true;
|
let again = true;
|
||||||
do {
|
do {
|
||||||
switch (tn.next(true)) {
|
switch (tn.next(true)) {
|
||||||
|
|
||||||
@ -2660,7 +2662,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
// ArrayLiteralExpression
|
// ArrayLiteralExpression
|
||||||
case Token.OPENBRACKET: {
|
case Token.OPENBRACKET: {
|
||||||
var elementExpressions = new Array<Expression | null>();
|
let elementExpressions = new Array<Expression | null>();
|
||||||
if (!tn.skip(Token.CLOSEBRACKET)) {
|
if (!tn.skip(Token.CLOSEBRACKET)) {
|
||||||
do {
|
do {
|
||||||
if (tn.peek() == Token.COMMA) {
|
if (tn.peek() == Token.COMMA) {
|
||||||
@ -2684,7 +2686,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
// AssertionExpression (unary prefix)
|
// AssertionExpression (unary prefix)
|
||||||
case Token.LESSTHAN: {
|
case Token.LESSTHAN: {
|
||||||
var toType = this.parseType(tn);
|
let toType = this.parseType(tn);
|
||||||
if (!toType) return null;
|
if (!toType) return null;
|
||||||
if (!tn.skip(Token.GREATERTHAN)) {
|
if (!tn.skip(Token.GREATERTHAN)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -2726,7 +2728,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// RegexpLiteralExpression
|
// RegexpLiteralExpression
|
||||||
// note that this also continues on invalid ones so the surrounding AST remains intact
|
// note that this also continues on invalid ones so the surrounding AST remains intact
|
||||||
case Token.SLASH: {
|
case Token.SLASH: {
|
||||||
var regexpPattern = tn.readRegexpPattern(); // also reports
|
let regexpPattern = tn.readRegexpPattern(); // also reports
|
||||||
if (!tn.skip(Token.SLASH)) {
|
if (!tn.skip(Token.SLASH)) {
|
||||||
this.error(
|
this.error(
|
||||||
DiagnosticCode._0_expected,
|
DiagnosticCode._0_expected,
|
||||||
@ -2763,7 +2765,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
if (!tn.skip(Token.LESSTHAN)) return null;
|
if (!tn.skip(Token.LESSTHAN)) return null;
|
||||||
var typeArguments = new Array<CommonTypeNode>();
|
var typeArguments = new Array<CommonTypeNode>();
|
||||||
do {
|
do {
|
||||||
var type = this.parseType(tn, true, true);
|
let type = this.parseType(tn, true, true);
|
||||||
if (!type) {
|
if (!type) {
|
||||||
tn.reset(state);
|
tn.reset(state);
|
||||||
return null;
|
return null;
|
||||||
@ -2786,7 +2788,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
var args = new Array<Expression>();
|
var args = new Array<Expression>();
|
||||||
if (!tn.skip(Token.CLOSEPAREN)) {
|
if (!tn.skip(Token.CLOSEPAREN)) {
|
||||||
do {
|
do {
|
||||||
var expr = this.parseExpression(tn, Precedence.COMMA + 1);
|
let expr = this.parseExpression(tn, Precedence.COMMA + 1);
|
||||||
if (!expr) return null;
|
if (!expr) return null;
|
||||||
args.push(expr);
|
args.push(expr);
|
||||||
} while (tn.skip(Token.COMMA));
|
} while (tn.skip(Token.COMMA));
|
||||||
@ -2832,7 +2834,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
switch (token) {
|
switch (token) {
|
||||||
// AssertionExpression
|
// AssertionExpression
|
||||||
case Token.AS: {
|
case Token.AS: {
|
||||||
var toType = this.parseType(tn);
|
let toType = this.parseType(tn);
|
||||||
if (!toType) return null;
|
if (!toType) return null;
|
||||||
expr = Node.createAssertionExpression(
|
expr = Node.createAssertionExpression(
|
||||||
AssertionKind.AS,
|
AssertionKind.AS,
|
||||||
@ -2882,7 +2884,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
// TernaryExpression
|
// TernaryExpression
|
||||||
case Token.QUESTION: {
|
case Token.QUESTION: {
|
||||||
var ifThen = this.parseExpression(tn);
|
let ifThen = this.parseExpression(tn);
|
||||||
if (!ifThen) return null;
|
if (!ifThen) return null;
|
||||||
if (!tn.skip(Token.COLON)) {
|
if (!tn.skip(Token.COLON)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -2891,7 +2893,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var ifElse = this.parseExpression(tn);
|
let ifElse = this.parseExpression(tn);
|
||||||
if (!ifElse) return null;
|
if (!ifElse) return null;
|
||||||
expr = Node.createTernaryExpression(
|
expr = Node.createTernaryExpression(
|
||||||
expr,
|
expr,
|
||||||
@ -2903,7 +2905,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
// CommaExpression
|
// CommaExpression
|
||||||
case Token.COMMA: {
|
case Token.COMMA: {
|
||||||
var commaExprs: Expression[] = [ expr ];
|
let commaExprs: Expression[] = [ expr ];
|
||||||
do {
|
do {
|
||||||
expr = this.parseExpression(tn, Precedence.COMMA + 1);
|
expr = this.parseExpression(tn, Precedence.COMMA + 1);
|
||||||
if (!expr) return null;
|
if (!expr) return null;
|
||||||
@ -2929,7 +2931,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
tn.range(startPos, tn.pos)
|
tn.range(startPos, tn.pos)
|
||||||
);
|
);
|
||||||
} else if (next.kind == NodeKind.CALL) { // join
|
} else if (next.kind == NodeKind.CALL) { // join
|
||||||
var propertyCall = <CallExpression>next;
|
let propertyCall = <CallExpression>next;
|
||||||
if (propertyCall.expression.kind == NodeKind.IDENTIFIER) {
|
if (propertyCall.expression.kind == NodeKind.IDENTIFIER) {
|
||||||
propertyCall.expression = Node.createPropertyAccessExpression(
|
propertyCall.expression = Node.createPropertyAccessExpression(
|
||||||
expr,
|
expr,
|
||||||
|
162
src/program.ts
162
src/program.ts
@ -304,7 +304,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
var element: Element | null;
|
var element: Element | null;
|
||||||
do {
|
do {
|
||||||
if (element = this.exports.get(referencedName)) return element;
|
if (element = this.exports.get(referencedName)) return element;
|
||||||
var queuedExport = queuedExports.get(referencedName);
|
let queuedExport = queuedExports.get(referencedName);
|
||||||
if (!queuedExport) return null;
|
if (!queuedExport) return null;
|
||||||
if (queuedExport.isReExport) {
|
if (queuedExport.isReExport) {
|
||||||
referencedName = queuedExport.referencedName;
|
referencedName = queuedExport.referencedName;
|
||||||
@ -501,7 +501,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
} else {
|
} else {
|
||||||
classPrototype.members = new Map();
|
classPrototype.members = new Map();
|
||||||
}
|
}
|
||||||
var staticField = new Global(
|
let staticField = new Global(
|
||||||
this, name, internalName, declaration, Type.void
|
this, name, internalName, declaration, Type.void
|
||||||
);
|
);
|
||||||
classPrototype.members.set(name, staticField);
|
classPrototype.members.set(name, staticField);
|
||||||
@ -520,7 +520,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
} else {
|
} else {
|
||||||
classPrototype.instanceMembers = new Map();
|
classPrototype.instanceMembers = new Map();
|
||||||
}
|
}
|
||||||
var instanceField = new FieldPrototype(
|
let instanceField = new FieldPrototype(
|
||||||
classPrototype,
|
classPrototype,
|
||||||
name, internalName,
|
name, internalName,
|
||||||
declaration
|
declaration
|
||||||
@ -618,8 +618,8 @@ export class Program extends DiagnosticEmitter {
|
|||||||
// arguments of the instance's type. return values vary depending on the
|
// arguments of the instance's type. return values vary depending on the
|
||||||
// operation.
|
// operation.
|
||||||
if (decorators) {
|
if (decorators) {
|
||||||
for (var i = 0, k = decorators.length; i < k; ++i) {
|
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||||
var decorator = decorators[i];
|
let decorator = decorators[i];
|
||||||
if (decorator.decoratorKind == DecoratorKind.OPERATOR) {
|
if (decorator.decoratorKind == DecoratorKind.OPERATOR) {
|
||||||
if (!prototype) {
|
if (!prototype) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -628,9 +628,9 @@ export class Program extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var numArgs = decorator.arguments && decorator.arguments.length || 0;
|
let numArgs = decorator.arguments && decorator.arguments.length || 0;
|
||||||
if (numArgs == 1) {
|
if (numArgs == 1) {
|
||||||
var firstArg = (<Expression[]>decorator.arguments)[0];
|
let firstArg = (<Expression[]>decorator.arguments)[0];
|
||||||
if (
|
if (
|
||||||
firstArg.kind == NodeKind.LITERAL &&
|
firstArg.kind == NodeKind.LITERAL &&
|
||||||
(<LiteralExpression>firstArg).literalKind == LiteralKind.STRING
|
(<LiteralExpression>firstArg).literalKind == LiteralKind.STRING
|
||||||
@ -717,7 +717,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// static accessors become global functions
|
// static accessors become global functions
|
||||||
if (hasModifier(ModifierKind.STATIC, declaration.modifiers)) {
|
if (hasModifier(ModifierKind.STATIC, declaration.modifiers)) {
|
||||||
var staticName = classPrototype.internalName + STATIC_DELIMITER + name;
|
let staticName = classPrototype.internalName + STATIC_DELIMITER + name;
|
||||||
if (this.elements.has(staticName)) {
|
if (this.elements.has(staticName)) {
|
||||||
this.error(
|
this.error(
|
||||||
DiagnosticCode.Duplicate_identifier_0,
|
DiagnosticCode.Duplicate_identifier_0,
|
||||||
@ -725,7 +725,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var staticPrototype = new FunctionPrototype(
|
let staticPrototype = new FunctionPrototype(
|
||||||
this,
|
this,
|
||||||
name, staticName,
|
name, staticName,
|
||||||
declaration,
|
declaration,
|
||||||
@ -744,7 +744,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// instance accessors are remembered until resolved
|
// instance accessors are remembered until resolved
|
||||||
} else {
|
} else {
|
||||||
var instanceName = classPrototype.internalName + INSTANCE_DELIMITER + name;
|
let instanceName = classPrototype.internalName + INSTANCE_DELIMITER + name;
|
||||||
if (classPrototype.instanceMembers) {
|
if (classPrototype.instanceMembers) {
|
||||||
if (classPrototype.instanceMembers.has(name)) {
|
if (classPrototype.instanceMembers.has(name)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -756,7 +756,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
} else {
|
} else {
|
||||||
classPrototype.instanceMembers = new Map();
|
classPrototype.instanceMembers = new Map();
|
||||||
}
|
}
|
||||||
var instancePrototype = new FunctionPrototype(
|
let instancePrototype = new FunctionPrototype(
|
||||||
this,
|
this,
|
||||||
name, instanceName,
|
name, instanceName,
|
||||||
declaration,
|
declaration,
|
||||||
@ -815,7 +815,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var values = declaration.values;
|
var values = declaration.values;
|
||||||
for (var i = 0, k = values.length; i < k; ++i) {
|
for (let i = 0, k = values.length; i < k; ++i) {
|
||||||
this.initializeEnumValue(values[i], enm);
|
this.initializeEnumValue(values[i], enm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -846,7 +846,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
queuedExports: Map<string,QueuedExport>
|
queuedExports: Map<string,QueuedExport>
|
||||||
): void {
|
): void {
|
||||||
var members = statement.members;
|
var members = statement.members;
|
||||||
for (var i = 0, k = members.length; i < k; ++i) {
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
this.initializeExport(members[i], statement.internalPath, queuedExports);
|
this.initializeExport(members[i], statement.internalPath, queuedExports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -931,7 +931,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// walk already known queued exports
|
// walk already known queued exports
|
||||||
var seen = new Set<QueuedExport>();
|
let seen = new Set<QueuedExport>();
|
||||||
while (queuedExport = queuedExports.get(referencedName)) {
|
while (queuedExport = queuedExports.get(referencedName)) {
|
||||||
if (queuedExport.isReExport) {
|
if (queuedExport.isReExport) {
|
||||||
referencedElement = this.exports.get(queuedExport.referencedName);
|
referencedElement = this.exports.get(queuedExport.referencedName);
|
||||||
@ -1031,7 +1031,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
): void {
|
): void {
|
||||||
var declarations = statement.declarations;
|
var declarations = statement.declarations;
|
||||||
if (declarations) {
|
if (declarations) {
|
||||||
for (var i = 0, k = declarations.length; i < k; ++i) {
|
for (let i = 0, k = declarations.length; i < k; ++i) {
|
||||||
this.initializeImport(
|
this.initializeImport(
|
||||||
declarations[i],
|
declarations[i],
|
||||||
statement.internalPath,
|
statement.internalPath,
|
||||||
@ -1039,7 +1039,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (statement.namespaceName) {
|
} else if (statement.namespaceName) {
|
||||||
var internalName = (
|
let internalName = (
|
||||||
statement.range.source.internalPath +
|
statement.range.source.internalPath +
|
||||||
PATH_DELIMITER +
|
PATH_DELIMITER +
|
||||||
statement.namespaceName.text
|
statement.namespaceName.text
|
||||||
@ -1146,8 +1146,8 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var memberDeclarations = declaration.members;
|
var memberDeclarations = declaration.members;
|
||||||
for (var i = 0, k = memberDeclarations.length; i < k; ++i) {
|
for (let i = 0, k = memberDeclarations.length; i < k; ++i) {
|
||||||
var memberDeclaration = memberDeclarations[i];
|
let memberDeclaration = memberDeclarations[i];
|
||||||
switch (memberDeclaration.kind) {
|
switch (memberDeclaration.kind) {
|
||||||
|
|
||||||
case NodeKind.FIELDDECLARATION: {
|
case NodeKind.FIELDDECLARATION: {
|
||||||
@ -1155,7 +1155,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NodeKind.METHODDECLARATION: {
|
case NodeKind.METHODDECLARATION: {
|
||||||
var isGetter = hasModifier(ModifierKind.GET, memberDeclaration.modifiers);
|
let isGetter = hasModifier(ModifierKind.GET, memberDeclaration.modifiers);
|
||||||
if (isGetter || hasModifier(ModifierKind.SET, memberDeclaration.modifiers)) {
|
if (isGetter || hasModifier(ModifierKind.SET, memberDeclaration.modifiers)) {
|
||||||
this.initializeAccessor(<MethodDeclaration>memberDeclaration, prototype, isGetter);
|
this.initializeAccessor(<MethodDeclaration>memberDeclaration, prototype, isGetter);
|
||||||
} else {
|
} else {
|
||||||
@ -1210,7 +1210,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var members = declaration.members;
|
var members = declaration.members;
|
||||||
for (var i = 0, k = members.length; i < k; ++i) {
|
for (let i = 0, k = members.length; i < k; ++i) {
|
||||||
switch (members[i].kind) {
|
switch (members[i].kind) {
|
||||||
case NodeKind.CLASSDECLARATION: {
|
case NodeKind.CLASSDECLARATION: {
|
||||||
this.initializeClass(<ClassDeclaration>members[i], queuedExtendingClasses, namespace);
|
this.initializeClass(<ClassDeclaration>members[i], queuedExtendingClasses, namespace);
|
||||||
@ -1271,9 +1271,9 @@ export class Program extends DiagnosticEmitter {
|
|||||||
|
|
||||||
private initializeVariables(statement: VariableStatement, namespace: Element | null = null): void {
|
private initializeVariables(statement: VariableStatement, namespace: Element | null = null): void {
|
||||||
var declarations = statement.declarations;
|
var declarations = statement.declarations;
|
||||||
for (var i = 0, k = declarations.length; i < k; ++i) {
|
for (let i = 0, k = declarations.length; i < k; ++i) {
|
||||||
var declaration = declarations[i];
|
let declaration = declarations[i];
|
||||||
var internalName = declaration.fileLevelInternalName;
|
let internalName = declaration.fileLevelInternalName;
|
||||||
if (this.elements.has(internalName)) {
|
if (this.elements.has(internalName)) {
|
||||||
this.error(
|
this.error(
|
||||||
DiagnosticCode.Duplicate_identifier_0,
|
DiagnosticCode.Duplicate_identifier_0,
|
||||||
@ -1282,7 +1282,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var global = new Global(
|
let global = new Global(
|
||||||
this,
|
this,
|
||||||
declaration.name.text,
|
declaration.name.text,
|
||||||
internalName,
|
internalName,
|
||||||
@ -1405,7 +1405,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
if ((element = this.elements.get(localName)) || (element = this.elements.get(globalName))) {
|
if ((element = this.elements.get(localName)) || (element = this.elements.get(globalName))) {
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
case ElementKind.CLASS_PROTOTYPE: {
|
case ElementKind.CLASS_PROTOTYPE: {
|
||||||
var instance = (<ClassPrototype>element).resolveUsingTypeArguments(
|
let instance = (<ClassPrototype>element).resolveUsingTypeArguments(
|
||||||
typeNode.typeArguments,
|
typeNode.typeArguments,
|
||||||
contextualTypeArguments,
|
contextualTypeArguments,
|
||||||
null
|
null
|
||||||
@ -1421,10 +1421,10 @@ export class Program extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// resolve parameters
|
// resolve parameters
|
||||||
if (typeNode.typeArguments) {
|
if (typeNode.typeArguments) {
|
||||||
var k = typeNode.typeArguments.length;
|
let k = typeNode.typeArguments.length;
|
||||||
var paramTypes = new Array<Type>(k);
|
let paramTypes = new Array<Type>(k);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < k; ++i) {
|
||||||
var paramType = this.resolveType( // reports
|
let paramType = this.resolveType( // reports
|
||||||
typeNode.typeArguments[i],
|
typeNode.typeArguments[i],
|
||||||
contextualTypeArguments,
|
contextualTypeArguments,
|
||||||
reportNotFound
|
reportNotFound
|
||||||
@ -1434,13 +1434,13 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (k) { // can't be a placeholder if it has parameters
|
if (k) { // can't be a placeholder if it has parameters
|
||||||
var instanceKey = typesToString(paramTypes);
|
let instanceKey = typesToString(paramTypes);
|
||||||
if (instanceKey.length) {
|
if (instanceKey.length) {
|
||||||
localName += "<" + instanceKey + ">";
|
localName += "<" + instanceKey + ">";
|
||||||
globalName += "<" + instanceKey + ">";
|
globalName += "<" + instanceKey + ">";
|
||||||
}
|
}
|
||||||
} else if (contextualTypeArguments) {
|
} else if (contextualTypeArguments) {
|
||||||
var placeholderType = contextualTypeArguments.get(globalName);
|
let placeholderType = contextualTypeArguments.get(globalName);
|
||||||
if (placeholderType) return placeholderType;
|
if (placeholderType) return placeholderType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1489,8 +1489,8 @@ export class Program extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var typeArguments = new Array<Type>(parameterCount);
|
var typeArguments = new Array<Type>(parameterCount);
|
||||||
for (var i = 0; i < parameterCount; ++i) {
|
for (let i = 0; i < parameterCount; ++i) {
|
||||||
var type = this.resolveType( // reports
|
let type = this.resolveType( // reports
|
||||||
(<TypeNode[]>typeArgumentNodes)[i],
|
(<TypeNode[]>typeArgumentNodes)[i],
|
||||||
contextualTypeArguments,
|
contextualTypeArguments,
|
||||||
true
|
true
|
||||||
@ -1598,7 +1598,7 @@ export class Program extends DiagnosticEmitter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ElementKind.PROPERTY: {
|
case ElementKind.PROPERTY: {
|
||||||
var getter = assert((<Property>target).getterPrototype).resolve(); // reports
|
let getter = assert((<Property>target).getterPrototype).resolve(); // reports
|
||||||
if (!getter) return null;
|
if (!getter) return null;
|
||||||
if (!(targetType = getter.signature.returnType).classType) {
|
if (!(targetType = getter.signature.returnType).classType) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1670,10 +1670,10 @@ export class Program extends DiagnosticEmitter {
|
|||||||
case ElementKind.GLOBAL:
|
case ElementKind.GLOBAL:
|
||||||
case ElementKind.LOCAL:
|
case ElementKind.LOCAL:
|
||||||
case ElementKind.FIELD: {
|
case ElementKind.FIELD: {
|
||||||
var type = (<VariableLikeElement>target).type;
|
let type = (<VariableLikeElement>target).type;
|
||||||
if (type.classType) {
|
if (type.classType) {
|
||||||
var indexedGetName = (target = type.classType).prototype.fnIndexedGet;
|
let indexedGetName = (target = type.classType).prototype.fnIndexedGet;
|
||||||
var indexedGet: Element | null;
|
let indexedGet: Element | null;
|
||||||
if (
|
if (
|
||||||
indexedGetName != null &&
|
indexedGetName != null &&
|
||||||
target.members &&
|
target.members &&
|
||||||
@ -1969,9 +1969,10 @@ export class Namespace extends Element {
|
|||||||
) {
|
) {
|
||||||
super(program, simpleName, internalName);
|
super(program, simpleName, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.IMPORT: {
|
case ModifierKind.IMPORT: {
|
||||||
this.set(ElementFlags.IMPORTED);
|
this.set(ElementFlags.IMPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2008,9 +2009,10 @@ export class Enum extends Element {
|
|||||||
) {
|
) {
|
||||||
super(program, simpleName, internalName);
|
super(program, simpleName, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.EXPORT: {
|
case ModifierKind.EXPORT: {
|
||||||
this.set(ElementFlags.EXPORTED);
|
this.set(ElementFlags.EXPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2109,9 +2111,10 @@ export class Global extends VariableLikeElement {
|
|||||||
) {
|
) {
|
||||||
super(program, simpleName, internalName);
|
super(program, simpleName, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.IMPORT: {
|
case ModifierKind.IMPORT: {
|
||||||
this.set(ElementFlags.IMPORTED);
|
this.set(ElementFlags.IMPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2210,9 +2213,10 @@ export class FunctionPrototype extends Element {
|
|||||||
) {
|
) {
|
||||||
super(program, simpleName, internalName);
|
super(program, simpleName, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.IMPORT: {
|
case ModifierKind.IMPORT: {
|
||||||
this.set(ElementFlags.IMPORTED);
|
this.set(ElementFlags.IMPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2365,7 +2369,7 @@ export class FunctionPrototype extends Element {
|
|||||||
throw new Error("partially resolved instance method must reference its class prototype");
|
throw new Error("partially resolved instance method must reference its class prototype");
|
||||||
}
|
}
|
||||||
if (classTypeArguments && classTypeArguments.length) {
|
if (classTypeArguments && classTypeArguments.length) {
|
||||||
var partialPrototype = new FunctionPrototype(
|
let partialPrototype = new FunctionPrototype(
|
||||||
this.program,
|
this.program,
|
||||||
this.simpleName,
|
this.simpleName,
|
||||||
this.internalName,
|
this.internalName,
|
||||||
@ -2407,10 +2411,10 @@ export class FunctionPrototype extends Element {
|
|||||||
assert(this.is(ElementFlags.BUILTIN));
|
assert(this.is(ElementFlags.BUILTIN));
|
||||||
var resolvedTypeArguments: Type[] | null = null;
|
var resolvedTypeArguments: Type[] | null = null;
|
||||||
if (typeArgumentNodes) {
|
if (typeArgumentNodes) {
|
||||||
var k = typeArgumentNodes.length;
|
let k = typeArgumentNodes.length;
|
||||||
resolvedTypeArguments = new Array<Type>(k);
|
resolvedTypeArguments = new Array<Type>(k);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < k; ++i) {
|
||||||
var resolvedType = this.program.resolveType( // reports
|
let resolvedType = this.program.resolveType( // reports
|
||||||
typeArgumentNodes[i],
|
typeArgumentNodes[i],
|
||||||
contextualTypeArguments,
|
contextualTypeArguments,
|
||||||
true
|
true
|
||||||
@ -2561,7 +2565,7 @@ export class Function extends Element {
|
|||||||
default: throw new Error("concrete type expected");
|
default: throw new Error("concrete type expected");
|
||||||
}
|
}
|
||||||
if (temps && temps.length) {
|
if (temps && temps.length) {
|
||||||
var ret = temps.pop();
|
let ret = temps.pop();
|
||||||
ret.type = type;
|
ret.type = type;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2657,10 +2661,10 @@ export class Function extends Element {
|
|||||||
this.breakContext = null;
|
this.breakContext = null;
|
||||||
this.tempI32s = this.tempI64s = this.tempF32s = this.tempF64s = null;
|
this.tempI32s = this.tempI64s = this.tempF32s = this.tempF64s = null;
|
||||||
if (this.program.options.sourceMap) {
|
if (this.program.options.sourceMap) {
|
||||||
var debugLocations = this.debugLocations;
|
let debugLocations = this.debugLocations;
|
||||||
if (debugLocations) {
|
if (debugLocations) {
|
||||||
for (var i = 0, k = debugLocations.length; i < k; ++i) {
|
for (let i = 0, k = debugLocations.length; i < k; ++i) {
|
||||||
var debugLocation = debugLocations[i];
|
let debugLocation = debugLocations[i];
|
||||||
module.setDebugLocation(
|
module.setDebugLocation(
|
||||||
ref,
|
ref,
|
||||||
debugLocation.debugInfoRef,
|
debugLocation.debugInfoRef,
|
||||||
@ -2678,7 +2682,7 @@ export class Function extends Element {
|
|||||||
toString(): string { return this.prototype.simpleName; }
|
toString(): string { return this.prototype.simpleName; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A resolved function table entry, that is an function called by an index and signature. */
|
/** A resolved function target, that is a function called indirectly by an index and signature. */
|
||||||
export class FunctionTarget extends Element {
|
export class FunctionTarget extends Element {
|
||||||
|
|
||||||
kind = ElementKind.FUNCTION_TARGET;
|
kind = ElementKind.FUNCTION_TARGET;
|
||||||
@ -2719,9 +2723,10 @@ export class FieldPrototype extends Element {
|
|||||||
super(classPrototype.program, simpleName, internalName);
|
super(classPrototype.program, simpleName, internalName);
|
||||||
this.classPrototype = classPrototype;
|
this.classPrototype = classPrototype;
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.EXPORT: {
|
case ModifierKind.EXPORT: {
|
||||||
this.set(ElementFlags.EXPORTED);
|
this.set(ElementFlags.EXPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2829,9 +2834,10 @@ export class ClassPrototype extends Element {
|
|||||||
) {
|
) {
|
||||||
super(program, simpleName, internalName);
|
super(program, simpleName, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
if (this.declaration.modifiers) {
|
var modifiers = declaration.modifiers;
|
||||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
if (modifiers) {
|
||||||
switch (this.declaration.modifiers[i].modifierKind) {
|
for (let i = 0, k = modifiers.length; i < k; ++i) {
|
||||||
|
switch (modifiers[i].modifierKind) {
|
||||||
case ModifierKind.IMPORT: {
|
case ModifierKind.IMPORT: {
|
||||||
this.set(ElementFlags.IMPORTED);
|
this.set(ElementFlags.IMPORTED);
|
||||||
break;
|
break;
|
||||||
@ -2848,7 +2854,7 @@ export class ClassPrototype extends Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.declaration.typeParameters.length) {
|
if (declaration.typeParameters.length) {
|
||||||
this.set(ElementFlags.GENERIC);
|
this.set(ElementFlags.GENERIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2878,7 +2884,7 @@ export class ClassPrototype extends Element {
|
|||||||
var inheritedTypeArguments = contextualTypeArguments;
|
var inheritedTypeArguments = contextualTypeArguments;
|
||||||
contextualTypeArguments = new Map();
|
contextualTypeArguments = new Map();
|
||||||
if (inheritedTypeArguments) {
|
if (inheritedTypeArguments) {
|
||||||
for (var [inheritedName, inheritedType] of inheritedTypeArguments) {
|
for (let [inheritedName, inheritedType] of inheritedTypeArguments) {
|
||||||
contextualTypeArguments.set(inheritedName, inheritedType);
|
contextualTypeArguments.set(inheritedName, inheritedType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2886,7 +2892,7 @@ export class ClassPrototype extends Element {
|
|||||||
var declaration = this.declaration;
|
var declaration = this.declaration;
|
||||||
var baseClass: Class | null = null;
|
var baseClass: Class | null = null;
|
||||||
if (declaration.extendsType) {
|
if (declaration.extendsType) {
|
||||||
var baseClassType = this.program.resolveType(declaration.extendsType, null); // reports
|
let baseClassType = this.program.resolveType(declaration.extendsType, null); // reports
|
||||||
if (!baseClassType) return null;
|
if (!baseClassType) return null;
|
||||||
if (!(baseClass = baseClassType.classType)) {
|
if (!(baseClass = baseClassType.classType)) {
|
||||||
this.program.error(
|
this.program.error(
|
||||||
@ -2930,14 +2936,14 @@ export class ClassPrototype extends Element {
|
|||||||
memoryOffset = baseClass.currentMemoryOffset;
|
memoryOffset = baseClass.currentMemoryOffset;
|
||||||
if (baseClass.members) {
|
if (baseClass.members) {
|
||||||
if (!instance.members) instance.members = new Map();
|
if (!instance.members) instance.members = new Map();
|
||||||
for (var inheritedMember of baseClass.members.values()) {
|
for (let inheritedMember of baseClass.members.values()) {
|
||||||
instance.members.set(inheritedMember.simpleName, inheritedMember);
|
instance.members.set(inheritedMember.simpleName, inheritedMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.constructorPrototype) {
|
if (this.constructorPrototype) {
|
||||||
var partialConstructor = this.constructorPrototype.resolvePartial(typeArguments); // reports
|
let partialConstructor = this.constructorPrototype.resolvePartial(typeArguments); // reports
|
||||||
if (partialConstructor) {
|
if (partialConstructor) {
|
||||||
instance.constructorInstance = partialConstructor.resolve(); // reports
|
instance.constructorInstance = partialConstructor.resolve(); // reports
|
||||||
}
|
}
|
||||||
@ -2945,20 +2951,20 @@ export class ClassPrototype extends Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.instanceMembers) {
|
if (this.instanceMembers) {
|
||||||
for (var member of this.instanceMembers.values()) {
|
for (let member of this.instanceMembers.values()) {
|
||||||
switch (member.kind) {
|
switch (member.kind) {
|
||||||
case ElementKind.FIELD_PROTOTYPE: { // fields are layed out in advance
|
case ElementKind.FIELD_PROTOTYPE: { // fields are layed out in advance
|
||||||
if (!instance.members) instance.members = new Map();
|
if (!instance.members) instance.members = new Map();
|
||||||
var fieldDeclaration = (<FieldPrototype>member).declaration;
|
let fieldDeclaration = (<FieldPrototype>member).declaration;
|
||||||
if (!fieldDeclaration.type) {
|
if (!fieldDeclaration.type) {
|
||||||
throw new Error("type expected"); // TODO: check if parent class defines a type
|
throw new Error("type expected"); // TODO: check if parent class defines a type
|
||||||
}
|
}
|
||||||
var fieldType = this.program.resolveType( // reports
|
let fieldType = this.program.resolveType( // reports
|
||||||
fieldDeclaration.type,
|
fieldDeclaration.type,
|
||||||
instance.contextualTypeArguments
|
instance.contextualTypeArguments
|
||||||
);
|
);
|
||||||
if (fieldType) {
|
if (fieldType) {
|
||||||
var fieldInstance = new Field(<FieldPrototype>member, (<FieldPrototype>member).internalName, fieldType);
|
let fieldInstance = new Field(<FieldPrototype>member, (<FieldPrototype>member).internalName, fieldType);
|
||||||
switch (fieldType.byteSize) { // align
|
switch (fieldType.byteSize) { // align
|
||||||
case 1: break;
|
case 1: break;
|
||||||
case 2: {
|
case 2: {
|
||||||
@ -2983,7 +2989,7 @@ export class ClassPrototype extends Element {
|
|||||||
}
|
}
|
||||||
case ElementKind.FUNCTION_PROTOTYPE: { // instance methods remain partially resolved prototypes until compiled
|
case ElementKind.FUNCTION_PROTOTYPE: { // instance methods remain partially resolved prototypes until compiled
|
||||||
if (!instance.members) instance.members = new Map();
|
if (!instance.members) instance.members = new Map();
|
||||||
var methodPrototype = (<FunctionPrototype>member).resolvePartial(typeArguments); // reports
|
let methodPrototype = (<FunctionPrototype>member).resolvePartial(typeArguments); // reports
|
||||||
if (methodPrototype) {
|
if (methodPrototype) {
|
||||||
instance.members.set(member.simpleName, methodPrototype);
|
instance.members.set(member.simpleName, methodPrototype);
|
||||||
}
|
}
|
||||||
@ -2992,7 +2998,7 @@ export class ClassPrototype extends Element {
|
|||||||
case ElementKind.PROPERTY: { // instance properties are cloned with partially resolved getters and setters
|
case ElementKind.PROPERTY: { // instance properties are cloned with partially resolved getters and setters
|
||||||
if (!instance.members) instance.members = new Map();
|
if (!instance.members) instance.members = new Map();
|
||||||
assert((<Property>member).getterPrototype);
|
assert((<Property>member).getterPrototype);
|
||||||
var instanceProperty = new Property(this.program, member.simpleName, member.internalName, this);
|
let instanceProperty = new Property(this.program, member.simpleName, member.internalName, this);
|
||||||
instanceProperty.getterPrototype = (
|
instanceProperty.getterPrototype = (
|
||||||
(<FunctionPrototype>(<Property>member).getterPrototype).resolvePartial(
|
(<FunctionPrototype>(<Property>member).getterPrototype).resolvePartial(
|
||||||
typeArguments
|
typeArguments
|
||||||
@ -3081,7 +3087,7 @@ export class Class extends Element {
|
|||||||
if (base) {
|
if (base) {
|
||||||
if (base.contextualTypeArguments) {
|
if (base.contextualTypeArguments) {
|
||||||
if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map();
|
if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map();
|
||||||
for (var [baseName, baseType] of base.contextualTypeArguments) {
|
for (let [baseName, baseType] of base.contextualTypeArguments) {
|
||||||
this.contextualTypeArguments.set(baseName, baseType);
|
this.contextualTypeArguments.set(baseName, baseType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3091,7 +3097,7 @@ export class Class extends Element {
|
|||||||
var declaration = this.prototype.declaration;
|
var declaration = this.prototype.declaration;
|
||||||
var i: i32, k: i32;
|
var i: i32, k: i32;
|
||||||
if (declaration) { // irrelevant for built-ins
|
if (declaration) { // irrelevant for built-ins
|
||||||
var typeParameters = declaration.typeParameters;
|
let typeParameters = declaration.typeParameters;
|
||||||
if (typeArguments) {
|
if (typeArguments) {
|
||||||
if ((k = typeArguments.length) != typeParameters.length) {
|
if ((k = typeArguments.length) != typeParameters.length) {
|
||||||
throw new Error("type argument count mismatch");
|
throw new Error("type argument count mismatch");
|
||||||
@ -3230,7 +3236,7 @@ export class Flow {
|
|||||||
|
|
||||||
// Free block-scoped locals
|
// Free block-scoped locals
|
||||||
if (this.scopedLocals) {
|
if (this.scopedLocals) {
|
||||||
for (var scopedLocal of this.scopedLocals.values()) {
|
for (let scopedLocal of this.scopedLocals.values()) {
|
||||||
this.currentFunction.freeTempLocal(scopedLocal);
|
this.currentFunction.freeTempLocal(scopedLocal);
|
||||||
}
|
}
|
||||||
this.scopedLocals = null;
|
this.scopedLocals = null;
|
||||||
|
@ -441,7 +441,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var text = this.source.text;
|
var text = this.source.text;
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
this.tokenPos = this.pos;
|
this.tokenPos = this.pos;
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case CharCode.CARRIAGERETURN: {
|
case CharCode.CARRIAGERETURN: {
|
||||||
if (
|
if (
|
||||||
@ -603,7 +603,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (text.charCodeAt(this.pos) == CharCode.ASTERISK) { // multi-line
|
if (text.charCodeAt(this.pos) == CharCode.ASTERISK) { // multi-line
|
||||||
var closed = false;
|
let closed = false;
|
||||||
while (++this.pos < this.end) {
|
while (++this.pos < this.end) {
|
||||||
c = text.charCodeAt(this.pos);
|
c = text.charCodeAt(this.pos);
|
||||||
if (
|
if (
|
||||||
@ -784,7 +784,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
default: {
|
default: {
|
||||||
if (isIdentifierStart(c)) {
|
if (isIdentifierStart(c)) {
|
||||||
if (isKeywordCharacter(c)) {
|
if (isKeywordCharacter(c)) {
|
||||||
var posBefore = this.pos;
|
let posBefore = this.pos;
|
||||||
while (
|
while (
|
||||||
++this.pos < this.end &&
|
++this.pos < this.end &&
|
||||||
isIdentifierPart(c = text.charCodeAt(this.pos))
|
isIdentifierPart(c = text.charCodeAt(this.pos))
|
||||||
@ -794,8 +794,8 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
return Token.IDENTIFIER;
|
return Token.IDENTIFIER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var keywordText = text.substring(posBefore, this.pos);
|
let keywordText = text.substring(posBefore, this.pos);
|
||||||
var keywordToken = Token.fromKeyword(keywordText);
|
let keywordToken = Token.fromKeyword(keywordText);
|
||||||
if (
|
if (
|
||||||
keywordToken != Token.INVALID &&
|
keywordToken != Token.INVALID &&
|
||||||
!(preferIdentifier && Token.isAlsoIdentifier(keywordToken))
|
!(preferIdentifier && Token.isAlsoIdentifier(keywordToken))
|
||||||
@ -828,9 +828,9 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
): Token {
|
): Token {
|
||||||
var text = this.source.text;
|
var text = this.source.text;
|
||||||
if (this.nextToken < 0) {
|
if (this.nextToken < 0) {
|
||||||
var posBefore = this.pos;
|
let posBefore = this.pos;
|
||||||
var tokenBefore = this.token;
|
let tokenBefore = this.token;
|
||||||
var tokenPosBefore = this.tokenPos;
|
let tokenPosBefore = this.tokenPos;
|
||||||
this.nextToken = this.unsafeNext(preferIdentifier, maxCompoundLength);
|
this.nextToken = this.unsafeNext(preferIdentifier, maxCompoundLength);
|
||||||
if (checkOnNewLine) {
|
if (checkOnNewLine) {
|
||||||
this.nextTokenOnNewLine = false;
|
this.nextTokenOnNewLine = false;
|
||||||
@ -942,7 +942,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c == quote) {
|
if (c == quote) {
|
||||||
result += text.substring(start, this.pos++);
|
result += text.substring(start, this.pos++);
|
||||||
break;
|
break;
|
||||||
@ -1030,7 +1030,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
escaped = true;
|
escaped = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c == CharCode.SLASH && !escaped) break;
|
if (c == CharCode.SLASH && !escaped) break;
|
||||||
if (isLineBreak(c)) {
|
if (isLineBreak(c)) {
|
||||||
this.error(
|
this.error(
|
||||||
@ -1050,7 +1050,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var start = this.pos;
|
var start = this.pos;
|
||||||
var flags = 0;
|
var flags = 0;
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c: i32 = text.charCodeAt(this.pos);
|
let c: i32 = text.charCodeAt(this.pos);
|
||||||
if (!isIdentifierPart(c)) break;
|
if (!isIdentifierPart(c)) break;
|
||||||
++this.pos;
|
++this.pos;
|
||||||
|
|
||||||
@ -1097,7 +1097,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (pos < this.end) {
|
while (pos < this.end) {
|
||||||
var c = text.charCodeAt(pos);
|
let c = text.charCodeAt(pos);
|
||||||
if (c == CharCode.DOT || c == CharCode.E || c == CharCode.e) {
|
if (c == CharCode.DOT || c == CharCode.E || c == CharCode.e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1128,9 +1128,9 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isOctalDigit(text.charCodeAt(this.pos + 1))) {
|
if (isOctalDigit(text.charCodeAt(this.pos + 1))) {
|
||||||
var start = this.pos;
|
let start = this.pos;
|
||||||
++this.pos;
|
++this.pos;
|
||||||
var value = this.readOctalInteger();
|
let value = this.readOctalInteger();
|
||||||
this.error(
|
this.error(
|
||||||
DiagnosticCode.Octal_literals_are_not_allowed_in_strict_mode,
|
DiagnosticCode.Octal_literals_are_not_allowed_in_strict_mode,
|
||||||
this.range(start, this.pos)
|
this.range(start, this.pos)
|
||||||
@ -1147,7 +1147,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var value = i64_new(0, 0);
|
var value = i64_new(0, 0);
|
||||||
var i64_16 = i64_new(16, 0);
|
var i64_16 = i64_new(16, 0);
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c >= CharCode._0 && c <= CharCode._9) {
|
if (c >= CharCode._0 && c <= CharCode._9) {
|
||||||
// value = value * 16 + c - CharCode._0;
|
// value = value * 16 + c - CharCode._0;
|
||||||
value = i64_add(
|
value = i64_add(
|
||||||
@ -1186,7 +1186,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var value = i64_new(0, 0);
|
var value = i64_new(0, 0);
|
||||||
var i64_10 = i64_new(10, 0);
|
var i64_10 = i64_new(10, 0);
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c >= CharCode._0 && c <= CharCode._9) {
|
if (c >= CharCode._0 && c <= CharCode._9) {
|
||||||
// value = value * 10 + c - CharCode._0;
|
// value = value * 10 + c - CharCode._0;
|
||||||
value = i64_add(
|
value = i64_add(
|
||||||
@ -1213,7 +1213,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var value = i64_new(0, 0);
|
var value = i64_new(0, 0);
|
||||||
var i64_8 = i64_new(8, 0);
|
var i64_8 = i64_new(8, 0);
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c >= CharCode._0 && c <= CharCode._7) {
|
if (c >= CharCode._0 && c <= CharCode._7) {
|
||||||
// value = value * 8 + c - CharCode._0;
|
// value = value * 8 + c - CharCode._0;
|
||||||
value = i64_add(
|
value = i64_add(
|
||||||
@ -1241,7 +1241,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var i64_2 = i64_new(2, 0);
|
var i64_2 = i64_new(2, 0);
|
||||||
var i64_1 = i64_new(1, 0);
|
var i64_1 = i64_new(1, 0);
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c == CharCode._0) {
|
if (c == CharCode._0) {
|
||||||
// value = value * 2;
|
// value = value * 2;
|
||||||
value = i64_mul(
|
value = i64_mul(
|
||||||
@ -1281,7 +1281,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.pos < this.end) {
|
if (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos);
|
let c = text.charCodeAt(this.pos);
|
||||||
if (c == CharCode.E || c == CharCode.e) {
|
if (c == CharCode.E || c == CharCode.e) {
|
||||||
if (
|
if (
|
||||||
++this.pos < this.end && (
|
++this.pos < this.end && (
|
||||||
@ -1305,7 +1305,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
var value = 0;
|
var value = 0;
|
||||||
var text = this.source.text;
|
var text = this.source.text;
|
||||||
while (this.pos < this.end) {
|
while (this.pos < this.end) {
|
||||||
var c = text.charCodeAt(this.pos++);
|
let c = text.charCodeAt(this.pos++);
|
||||||
if (c >= CharCode._0 && c <= CharCode._9) {
|
if (c >= CharCode._0 && c <= CharCode._9) {
|
||||||
value = value * 16 + c - CharCode._0;
|
value = value * 16 + c - CharCode._0;
|
||||||
} else if (c >= CharCode.A && c <= CharCode.F) {
|
} else if (c >= CharCode.A && c <= CharCode.F) {
|
||||||
|
16
src/types.ts
16
src/types.ts
@ -419,9 +419,9 @@ export class Type {
|
|||||||
|
|
||||||
/** Converts an array of types to an array of native types. */
|
/** Converts an array of types to an array of native types. */
|
||||||
export function typesToNativeTypes(types: Type[]): NativeType[] {
|
export function typesToNativeTypes(types: Type[]): NativeType[] {
|
||||||
var k = types.length;
|
var numTypes = types.length;
|
||||||
var ret = new Array<NativeType>(k);
|
var ret = new Array<NativeType>(numTypes);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numTypes; ++i) {
|
||||||
ret[i] = types[i].toNativeType();
|
ret[i] = types[i].toNativeType();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -429,10 +429,10 @@ export function typesToNativeTypes(types: Type[]): NativeType[] {
|
|||||||
|
|
||||||
/** Converts an array of types to its combined string representation. */
|
/** Converts an array of types to its combined string representation. */
|
||||||
export function typesToString(types: Type[]): string {
|
export function typesToString(types: Type[]): string {
|
||||||
var k = types.length;
|
var numTypes = types.length;
|
||||||
if (!k) return "";
|
if (!numTypes) return "";
|
||||||
var sb = new Array<string>(k);
|
var sb = new Array<string>(numTypes);
|
||||||
for (var i = 0; i < k; ++i) {
|
for (let i = 0; i < numTypes; ++i) {
|
||||||
sb[i] = types[i].toString();
|
sb[i] = types[i].toString();
|
||||||
}
|
}
|
||||||
return sb.join(", ");
|
return sb.join(", ");
|
||||||
@ -580,7 +580,7 @@ var cachedGenericParameterNames: string[] | null = null;
|
|||||||
/** Gets the cached generic parameter name for the specified index. */
|
/** Gets the cached generic parameter name for the specified index. */
|
||||||
export function getGenericParameterName(index: i32): string {
|
export function getGenericParameterName(index: i32): string {
|
||||||
if (!cachedGenericParameterNames) cachedGenericParameterNames = [];
|
if (!cachedGenericParameterNames) cachedGenericParameterNames = [];
|
||||||
for (var i = cachedGenericParameterNames.length; i < index; ++i) {
|
for (let i = cachedGenericParameterNames.length; i < index; ++i) {
|
||||||
cachedGenericParameterNames.push("arg$" + i.toString(10));
|
cachedGenericParameterNames.push("arg$" + i.toString(10));
|
||||||
}
|
}
|
||||||
return cachedGenericParameterNames[index];
|
return cachedGenericParameterNames[index];
|
||||||
|
@ -56,7 +56,7 @@ export function normalize(path: string): string {
|
|||||||
path.charCodeAt(pos + 3) == separator
|
path.charCodeAt(pos + 3) == separator
|
||||||
) {
|
) {
|
||||||
// find preceeding '/'
|
// find preceeding '/'
|
||||||
var ipos = pos;
|
let ipos = pos;
|
||||||
while (--ipos >= 0) {
|
while (--ipos >= 0) {
|
||||||
if (path.charCodeAt(ipos) == separator) {
|
if (path.charCodeAt(ipos) == separator) {
|
||||||
if (pos - ipos != 3 ||
|
if (pos - ipos != 3 ||
|
||||||
|
@ -16,8 +16,8 @@ export function allocate_memory(size: usize): usize {
|
|||||||
var newPtr = (ptr + size + AL_MASK) & ~AL_MASK;
|
var newPtr = (ptr + size + AL_MASK) & ~AL_MASK;
|
||||||
var pagesBefore = current_memory();
|
var pagesBefore = current_memory();
|
||||||
if (newPtr > <usize>pagesBefore << 16) {
|
if (newPtr > <usize>pagesBefore << 16) {
|
||||||
var pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;
|
let pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;
|
||||||
var pagesWanted = max(pagesBefore, pagesNeeded); // double memory
|
let pagesWanted = max(pagesBefore, pagesNeeded); // double memory
|
||||||
if (grow_memory(pagesWanted) < 0) {
|
if (grow_memory(pagesWanted) < 0) {
|
||||||
if (grow_memory(pagesNeeded) < 0) {
|
if (grow_memory(pagesNeeded) < 0) {
|
||||||
unreachable(); // out of memory
|
unreachable(); // out of memory
|
||||||
|
@ -175,8 +175,8 @@ function update_max_ptr(new_value: usize): i32 {
|
|||||||
// if (brk(new_value)) {
|
// if (brk(new_value)) {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
var oldPages = <u32>current_memory();
|
let oldPages = <u32>current_memory();
|
||||||
var newPages = <u32>(((new_value + 0xffff) & ~0xffff) >> 16);
|
let newPages = <u32>(((new_value + 0xffff) & ~0xffff) >> 16);
|
||||||
assert(newPages > oldPages);
|
assert(newPages > oldPages);
|
||||||
if (grow_memory(newPages - oldPages) < 0) {
|
if (grow_memory(newPages - oldPages) < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -293,8 +293,8 @@ function bucket_for_request(request: usize): usize {
|
|||||||
*/
|
*/
|
||||||
function lower_bucket_limit(bucket: usize): u32 {
|
function lower_bucket_limit(bucket: usize): u32 {
|
||||||
while (bucket < bucket_limit) {
|
while (bucket < bucket_limit) {
|
||||||
var root = node_for_ptr(base_ptr, bucket_limit);
|
let root = node_for_ptr(base_ptr, bucket_limit);
|
||||||
var right_child: usize;
|
let right_child: usize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the parent isn't SPLIT, that means the node at the current bucket
|
* If the parent isn't SPLIT, that means the node at the current bucket
|
||||||
@ -380,8 +380,8 @@ export function allocate_memory(request: usize): usize {
|
|||||||
* larger one to get a match.
|
* larger one to get a match.
|
||||||
*/
|
*/
|
||||||
while (bucket + 1 != 0) {
|
while (bucket + 1 != 0) {
|
||||||
var size: usize, bytes_needed: usize, i: usize;
|
let size: usize, bytes_needed: usize, i: usize;
|
||||||
var ptr: usize;
|
let ptr: usize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We may need to grow the tree to be able to fit an allocation of this
|
* We may need to grow the tree to be able to fit an allocation of this
|
||||||
|
@ -206,8 +206,8 @@ class Root {
|
|||||||
|
|
||||||
// merge with left block if also free
|
// merge with left block if also free
|
||||||
if (blockInfo & LEFT_FREE) {
|
if (blockInfo & LEFT_FREE) {
|
||||||
var left: Block = assert(block.left); // can't be null
|
let left: Block = assert(block.left); // can't be null
|
||||||
var leftInfo = left.info;
|
let leftInfo = left.info;
|
||||||
assert(leftInfo & FREE); // must be free according to tags
|
assert(leftInfo & FREE); // must be free according to tags
|
||||||
this.remove(left);
|
this.remove(left);
|
||||||
left.info = (leftInfo += Block.INFO + (blockInfo & ~TAGS));
|
left.info = (leftInfo += Block.INFO + (blockInfo & ~TAGS));
|
||||||
@ -280,7 +280,7 @@ class Root {
|
|||||||
|
|
||||||
// clear second level map if head is empty now
|
// clear second level map if head is empty now
|
||||||
if (!next) {
|
if (!next) {
|
||||||
var slMap = this.getSLMap(fl);
|
let slMap = this.getSLMap(fl);
|
||||||
this.setSLMap(fl, slMap &= ~(1 << sl));
|
this.setSLMap(fl, slMap &= ~(1 << sl));
|
||||||
|
|
||||||
// clear first level map if second level is empty now
|
// clear first level map if second level is empty now
|
||||||
@ -313,7 +313,7 @@ class Root {
|
|||||||
var head: Block | null;
|
var head: Block | null;
|
||||||
if (!slMap) {
|
if (!slMap) {
|
||||||
// search next larger first level
|
// search next larger first level
|
||||||
var flMap = this.flMap & (~0 << (fl + 1));
|
let flMap = this.flMap & (~0 << (fl + 1));
|
||||||
if (!flMap) {
|
if (!flMap) {
|
||||||
head = null;
|
head = null;
|
||||||
} else {
|
} else {
|
||||||
@ -354,7 +354,7 @@ class Root {
|
|||||||
if (remaining >= Block.INFO + Block.MIN_SIZE) {
|
if (remaining >= Block.INFO + Block.MIN_SIZE) {
|
||||||
block.info = size | (blockInfo & LEFT_FREE); // also discards FREE
|
block.info = size | (blockInfo & LEFT_FREE); // also discards FREE
|
||||||
|
|
||||||
var spare = changetype<Block>(
|
let spare = changetype<Block>(
|
||||||
changetype<usize>(block) + Block.INFO + size
|
changetype<usize>(block) + Block.INFO + size
|
||||||
);
|
);
|
||||||
spare.info = (remaining - Block.INFO) | FREE; // not LEFT_FREE
|
spare.info = (remaining - Block.INFO) | FREE; // not LEFT_FREE
|
||||||
@ -363,7 +363,7 @@ class Root {
|
|||||||
// otherwise tag block as no longer FREE and right as no longer LEFT_FREE
|
// otherwise tag block as no longer FREE and right as no longer LEFT_FREE
|
||||||
} else {
|
} else {
|
||||||
block.info = blockInfo & ~FREE;
|
block.info = blockInfo & ~FREE;
|
||||||
var right: Block = assert(block.right); // can't be null (tail)
|
let right: Block = assert(block.right); // can't be null (tail)
|
||||||
right.info &= ~LEFT_FREE;
|
right.info &= ~LEFT_FREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,13 +440,13 @@ export function allocate_memory(size: usize): usize {
|
|||||||
// initialize if necessary
|
// initialize if necessary
|
||||||
var root = ROOT;
|
var root = ROOT;
|
||||||
if (!root) {
|
if (!root) {
|
||||||
var rootOffset = (HEAP_BASE + AL_MASK) & ~AL_MASK;
|
let rootOffset = (HEAP_BASE + AL_MASK) & ~AL_MASK;
|
||||||
ROOT = root = changetype<Root>(rootOffset);
|
ROOT = root = changetype<Root>(rootOffset);
|
||||||
root.tailRef = 0;
|
root.tailRef = 0;
|
||||||
root.flMap = 0;
|
root.flMap = 0;
|
||||||
for (var fl: usize = 0; fl < FL_BITS; ++fl) {
|
for (let fl: usize = 0; fl < FL_BITS; ++fl) {
|
||||||
root.setSLMap(fl, 0);
|
root.setSLMap(fl, 0);
|
||||||
for (var sl: u32 = 0; sl < SL_SIZE; ++sl) {
|
for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {
|
||||||
root.setHead(fl, sl, null);
|
root.setHead(fl, sl, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,19 +458,19 @@ export function allocate_memory(size: usize): usize {
|
|||||||
if (size && size < Block.MAX_SIZE) {
|
if (size && size < Block.MAX_SIZE) {
|
||||||
size = max<usize>((size + AL_MASK) & ~AL_MASK, Block.MIN_SIZE);
|
size = max<usize>((size + AL_MASK) & ~AL_MASK, Block.MIN_SIZE);
|
||||||
|
|
||||||
var block = root.search(size);
|
let block = root.search(size);
|
||||||
if (!block) {
|
if (!block) {
|
||||||
|
|
||||||
// request more memory
|
// request more memory
|
||||||
var pagesBefore = current_memory();
|
let pagesBefore = current_memory();
|
||||||
var pagesNeeded = ((size + 0xffff) & ~0xffff) >>> 16;
|
let pagesNeeded = ((size + 0xffff) & ~0xffff) >>> 16;
|
||||||
var pagesWanted = max(pagesBefore, pagesNeeded); // double memory
|
let pagesWanted = max(pagesBefore, pagesNeeded); // double memory
|
||||||
if (grow_memory(pagesWanted) < 0) {
|
if (grow_memory(pagesWanted) < 0) {
|
||||||
if (grow_memory(pagesNeeded) < 0) {
|
if (grow_memory(pagesNeeded) < 0) {
|
||||||
unreachable(); // out of memory
|
unreachable(); // out of memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var pagesAfter = current_memory();
|
let pagesAfter = current_memory();
|
||||||
root.addMemory(<usize>pagesBefore << 16, <usize>pagesAfter << 16);
|
root.addMemory(<usize>pagesBefore << 16, <usize>pagesAfter << 16);
|
||||||
block = assert(root.search(size)); // must be found now
|
block = assert(root.search(size)); // must be found now
|
||||||
}
|
}
|
||||||
@ -486,10 +486,10 @@ export function allocate_memory(size: usize): usize {
|
|||||||
@global
|
@global
|
||||||
export function free_memory(data: usize): void {
|
export function free_memory(data: usize): void {
|
||||||
if (data) {
|
if (data) {
|
||||||
var root = ROOT;
|
let root = ROOT;
|
||||||
if (root) {
|
if (root) {
|
||||||
var block = changetype<Block>(data - Block.INFO);
|
let block = changetype<Block>(data - Block.INFO);
|
||||||
var blockInfo = block.info;
|
let blockInfo = block.info;
|
||||||
assert(!(blockInfo & FREE)); // must be used
|
assert(!(blockInfo & FREE)); // must be used
|
||||||
block.info = blockInfo | FREE;
|
block.info = blockInfo | FREE;
|
||||||
root.insert(changetype<Block>(data - Block.INFO));
|
root.insert(changetype<Block>(data - Block.INFO));
|
||||||
|
@ -124,9 +124,9 @@ export class Array<T> {
|
|||||||
var oldCapacity = this.__capacity;
|
var oldCapacity = this.__capacity;
|
||||||
if (this.__length == oldCapacity) {
|
if (this.__length == oldCapacity) {
|
||||||
// inlined __grow (avoids moving twice)
|
// inlined __grow (avoids moving twice)
|
||||||
var newCapacity: i32 = oldCapacity ? oldCapacity << 1 : 1;
|
let newCapacity: i32 = oldCapacity ? oldCapacity << 1 : 1;
|
||||||
assert(newCapacity > this.__capacity);
|
assert(newCapacity > this.__capacity);
|
||||||
var newMemory = allocate_memory(<usize>newCapacity * sizeof<T>());
|
let newMemory = allocate_memory(<usize>newCapacity * sizeof<T>());
|
||||||
if (this.__memory) {
|
if (this.__memory) {
|
||||||
move_memory(
|
move_memory(
|
||||||
newMemory + sizeof<T>(),
|
newMemory + sizeof<T>(),
|
||||||
@ -202,8 +202,8 @@ export class Array<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reverse(): Array<T> {
|
reverse(): Array<T> {
|
||||||
for (var front: usize = 0, back: usize = <usize>this.__length - 1; front < back; ++front, --back) {
|
for (let front: usize = 0, back: usize = <usize>this.__length - 1; front < back; ++front, --back) {
|
||||||
var temp = load<T>(this.__memory + front * sizeof<T>());
|
let temp = load<T>(this.__memory + front * sizeof<T>());
|
||||||
store<T>(this.__memory + front * sizeof<T>(), load<T>(this.__memory + back * sizeof<T>()));
|
store<T>(this.__memory + front * sizeof<T>(), load<T>(this.__memory + back * sizeof<T>()));
|
||||||
store<T>(this.__memory + back * sizeof<T>(), temp);
|
store<T>(this.__memory + back * sizeof<T>(), temp);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export class Map<K,V> {
|
|||||||
|
|
||||||
get(key: K): V | null {
|
get(key: K): V | null {
|
||||||
var keys = this.__keys;
|
var keys = this.__keys;
|
||||||
for (var i = 0, k = keys.length; i < k; ++i) {
|
for (let i = 0, k = keys.length; i < k; ++i) {
|
||||||
if (keys[i] == key) {
|
if (keys[i] == key) {
|
||||||
return this.__values[i];
|
return this.__values[i];
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export class Map<K,V> {
|
|||||||
|
|
||||||
has(key: K): bool {
|
has(key: K): bool {
|
||||||
var keys = this.__keys;
|
var keys = this.__keys;
|
||||||
for (var i = 0, k = keys.length; i < k; ++i) {
|
for (let i = 0, k = keys.length; i < k; ++i) {
|
||||||
if (keys[i] == key) {
|
if (keys[i] == key) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ export function bswap<T>(value: T): T {
|
|||||||
rotr<u32>(<u32>value & 0x00FF00FF, 8)
|
rotr<u32>(<u32>value & 0x00FF00FF, 8)
|
||||||
);
|
);
|
||||||
} else if (sizeof<T>() == 8) {
|
} else if (sizeof<T>() == 8) {
|
||||||
var a: u64 = (<u64>value >> 8) & 0x00FF00FF00FF00FF;
|
let a: u64 = (<u64>value >> 8) & 0x00FF00FF00FF00FF;
|
||||||
var b: u64 = (<u64>value & 0x00FF00FF00FF00FF) << 8;
|
let b: u64 = (<u64>value & 0x00FF00FF00FF00FF) << 8;
|
||||||
var v: u64 = a | b;
|
let v: u64 = a | b;
|
||||||
|
|
||||||
a = (v >> 16) & 0x0000FFFF0000FFFF;
|
a = (v >> 16) & 0x0000FFFF0000FFFF;
|
||||||
b = (v & 0x0000FFFF0000FFFF) << 16;
|
b = (v & 0x0000FFFF0000FFFF) << 16;
|
||||||
|
@ -21,7 +21,7 @@ export class Set<T> {
|
|||||||
has(value: T): bool {
|
has(value: T): bool {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
|
|
||||||
for (var index: usize = 0, limit: usize = this.__size; index < limit; ++index) {
|
for (let index: usize = 0, limit: usize = this.__size; index < limit; ++index) {
|
||||||
if (load<T>(this.__memory + index * sizeof<T>()) == value) {
|
if (load<T>(this.__memory + index * sizeof<T>()) == value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -33,8 +33,8 @@ export class Set<T> {
|
|||||||
assert(this != null);
|
assert(this != null);
|
||||||
|
|
||||||
if (this.__size >= this.__capacity) {
|
if (this.__size >= this.__capacity) {
|
||||||
var newCapacity = max(this.__capacity << 1, 8);
|
let newCapacity = max(this.__capacity << 1, 8);
|
||||||
var newMemory = allocate_memory(<usize>newCapacity * sizeof<T>());
|
let newMemory = allocate_memory(<usize>newCapacity * sizeof<T>());
|
||||||
if (this.__memory) {
|
if (this.__memory) {
|
||||||
move_memory(newMemory, this.__memory, <usize>this.__capacity * sizeof<T>());
|
move_memory(newMemory, this.__memory, <usize>this.__capacity * sizeof<T>());
|
||||||
free_memory(this.__memory);
|
free_memory(this.__memory);
|
||||||
@ -50,7 +50,7 @@ export class Set<T> {
|
|||||||
delete(value: T): bool {
|
delete(value: T): bool {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
|
|
||||||
for (var index: usize = 0, limit: usize = this.__size; index < limit; ++index) {
|
for (let index: usize = 0, limit: usize = this.__size; index < limit; ++index) {
|
||||||
if (load<T>(this.__memory + index * sizeof<T>()) == value) {
|
if (load<T>(this.__memory + index * sizeof<T>()) == value) {
|
||||||
if (index + 1 < limit) {
|
if (index + 1 < limit) {
|
||||||
move_memory(
|
move_memory(
|
||||||
|
@ -152,7 +152,7 @@ export class String {
|
|||||||
var searchLen: isize = <isize>searchString.length;
|
var searchLen: isize = <isize>searchString.length;
|
||||||
|
|
||||||
// TODO: two-way, multiple char codes
|
// TODO: two-way, multiple char codes
|
||||||
for (var k: usize = start; <isize>k + searchLen <= len; ++k) {
|
for (let k: usize = start; <isize>k + searchLen <= len; ++k) {
|
||||||
if (!compare_memory(
|
if (!compare_memory(
|
||||||
changetype<usize>(this) + HEAD + (k << 1),
|
changetype<usize>(this) + HEAD + (k << 1),
|
||||||
changetype<usize>(searchString) + HEAD,
|
changetype<usize>(searchString) + HEAD,
|
||||||
@ -486,7 +486,7 @@ export function parseFloat(str: String): f64 {
|
|||||||
code = <i32>load<u16>(ptr, HEAD);
|
code = <i32>load<u16>(ptr, HEAD);
|
||||||
if (code == CharCode.DOT) {
|
if (code == CharCode.DOT) {
|
||||||
ptr += 2;
|
ptr += 2;
|
||||||
var fac: f64 = 0.1; // precision :(
|
let fac: f64 = 0.1; // precision :(
|
||||||
while (len--) {
|
while (len--) {
|
||||||
code = <i32>load<u16>(ptr, HEAD);
|
code = <i32>load<u16>(ptr, HEAD);
|
||||||
if (code == CharCode.E || code == CharCode.e) {
|
if (code == CharCode.E || code == CharCode.e) {
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
(local $4 i32)
|
(local $4 i32)
|
||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(local $7 i32)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -84,7 +83,7 @@
|
|||||||
(i32.const 16)
|
(i32.const 16)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $7
|
(set_local $5
|
||||||
(select
|
(select
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
@ -101,7 +100,7 @@
|
|||||||
(if
|
(if
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(grow_memory
|
(grow_memory
|
||||||
(get_local $7)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
|
@ -2164,7 +2164,7 @@
|
|||||||
(block
|
(block
|
||||||
(if
|
(if
|
||||||
(i32.le_s
|
(i32.le_s
|
||||||
(tee_local $3
|
(tee_local $4
|
||||||
(select
|
(select
|
||||||
(i32.shl
|
(i32.shl
|
||||||
(get_local $2)
|
(get_local $2)
|
||||||
@ -2188,10 +2188,10 @@
|
|||||||
(unreachable)
|
(unreachable)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $4
|
(set_local $3
|
||||||
(call "$(lib)/allocator/arena/allocate_memory"
|
(call "$(lib)/allocator/arena/allocate_memory"
|
||||||
(i32.shl
|
(i32.shl
|
||||||
(get_local $3)
|
(get_local $4)
|
||||||
(i32.const 2)
|
(i32.const 2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -2203,7 +2203,7 @@
|
|||||||
(block
|
(block
|
||||||
(call "$(lib)/memory/move_memory"
|
(call "$(lib)/memory/move_memory"
|
||||||
(i32.add
|
(i32.add
|
||||||
(get_local $4)
|
(get_local $3)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(i32.load
|
(i32.load
|
||||||
@ -2223,11 +2223,11 @@
|
|||||||
)
|
)
|
||||||
(i32.store
|
(i32.store
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(get_local $4)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
(i32.store offset=4
|
(i32.store offset=4
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(get_local $3)
|
(get_local $4)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(call "$(lib)/memory/move_memory"
|
(call "$(lib)/memory/move_memory"
|
||||||
@ -2254,7 +2254,7 @@
|
|||||||
)
|
)
|
||||||
(i32.store offset=8
|
(i32.store offset=8
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(tee_local $0
|
(tee_local $3
|
||||||
(i32.add
|
(i32.add
|
||||||
(i32.load offset=8
|
(i32.load offset=8
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -2263,7 +2263,7 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(get_local $0)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
(func "$(lib)/memory/set_memory" (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
|
(func "$(lib)/memory/set_memory" (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
|
||||||
(local $3 i64)
|
(local $3 i64)
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
(local $4 i32)
|
(local $4 i32)
|
||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(local $7 i32)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -86,7 +85,7 @@
|
|||||||
(i32.const 16)
|
(i32.const 16)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $7
|
(set_local $5
|
||||||
(select
|
(select
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
@ -103,7 +102,7 @@
|
|||||||
(if
|
(if
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(grow_memory
|
(grow_memory
|
||||||
(get_local $7)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
@ -2449,7 +2448,6 @@
|
|||||||
(local $2 i32)
|
(local $2 i32)
|
||||||
(local $3 i32)
|
(local $3 i32)
|
||||||
(local $4 i32)
|
(local $4 i32)
|
||||||
(local $5 i32)
|
|
||||||
(set_local $2
|
(set_local $2
|
||||||
(i32.load offset=4
|
(i32.load offset=4
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -2558,7 +2556,7 @@
|
|||||||
)
|
)
|
||||||
(return
|
(return
|
||||||
(block (result i32)
|
(block (result i32)
|
||||||
(set_local $5
|
(set_local $4
|
||||||
(i32.add
|
(i32.add
|
||||||
(i32.load offset=8
|
(i32.load offset=8
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -2568,9 +2566,9 @@
|
|||||||
)
|
)
|
||||||
(i32.store offset=8
|
(i32.store offset=8
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(get_local $5)
|
(get_local $4)
|
||||||
)
|
)
|
||||||
(get_local $5)
|
(get_local $4)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
(local $4 i32)
|
(local $4 i32)
|
||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(local $7 i32)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -76,7 +75,7 @@
|
|||||||
(i32.const 16)
|
(i32.const 16)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $7
|
(set_local $5
|
||||||
(select
|
(select
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
@ -93,7 +92,7 @@
|
|||||||
(if
|
(if
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(grow_memory
|
(grow_memory
|
||||||
(get_local $7)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
|
@ -2002,7 +2002,7 @@
|
|||||||
(i32.shl
|
(i32.shl
|
||||||
(tee_local $3
|
(tee_local $3
|
||||||
(select
|
(select
|
||||||
(tee_local $2
|
(tee_local $3
|
||||||
(i32.shl
|
(i32.shl
|
||||||
(i32.load offset=4
|
(i32.load offset=4
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -2010,12 +2010,12 @@
|
|||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(tee_local $3
|
(tee_local $2
|
||||||
(i32.const 8)
|
(i32.const 8)
|
||||||
)
|
)
|
||||||
(i32.gt_u
|
(i32.gt_u
|
||||||
(get_local $2)
|
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
|
(get_local $2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
(local $4 i32)
|
(local $4 i32)
|
||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(local $7 i32)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
@ -82,7 +81,7 @@
|
|||||||
(i32.const 16)
|
(i32.const 16)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $7
|
(set_local $5
|
||||||
(select
|
(select
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
@ -99,7 +98,7 @@
|
|||||||
(if
|
(if
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(grow_memory
|
(grow_memory
|
||||||
(get_local $7)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
@ -2260,8 +2259,6 @@
|
|||||||
(func "$(lib)/set/Set#add" (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
(func "$(lib)/set/Set#add" (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
||||||
(local $2 i32)
|
(local $2 i32)
|
||||||
(local $3 i32)
|
(local $3 i32)
|
||||||
(local $4 i32)
|
|
||||||
(local $5 i32)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(i32.ne
|
(i32.ne
|
||||||
@ -2289,7 +2286,7 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
(block
|
(block
|
||||||
(set_local $4
|
(set_local $2
|
||||||
(select
|
(select
|
||||||
(tee_local $2
|
(tee_local $2
|
||||||
(i32.shl
|
(i32.shl
|
||||||
@ -2308,10 +2305,10 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $5
|
(set_local $3
|
||||||
(call "$(lib)/allocator/arena/allocate_memory"
|
(call "$(lib)/allocator/arena/allocate_memory"
|
||||||
(i32.mul
|
(i32.mul
|
||||||
(get_local $4)
|
(get_local $2)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -2322,7 +2319,7 @@
|
|||||||
)
|
)
|
||||||
(block
|
(block
|
||||||
(call "$(lib)/memory/move_memory"
|
(call "$(lib)/memory/move_memory"
|
||||||
(get_local $5)
|
(get_local $3)
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
@ -2342,11 +2339,11 @@
|
|||||||
)
|
)
|
||||||
(i32.store offset=4
|
(i32.store offset=4
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(get_local $4)
|
(get_local $2)
|
||||||
)
|
)
|
||||||
(i32.store
|
(i32.store
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
(get_local $5)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -6,8 +6,11 @@
|
|||||||
"defaultSeverity": "warning",
|
"defaultSeverity": "warning",
|
||||||
"rules": {
|
"rules": {
|
||||||
"as-types": { "severity": "error" },
|
"as-types": { "severity": "error" },
|
||||||
|
"as-variables": true,
|
||||||
|
|
||||||
"as-internal-case": true,
|
"as-internal-case": true,
|
||||||
"as-internal-diagnostics": true,
|
"as-internal-diagnostics": true,
|
||||||
|
|
||||||
"adjacent-overload-signatures": true,
|
"adjacent-overload-signatures": true,
|
||||||
"ban-types": [ true, ["Object"], ["any"], ["undefined"], ["never"] ],
|
"ban-types": [ true, ["Object"], ["any"], ["undefined"], ["never"] ],
|
||||||
"curly": [true, "ignore-same-line"],
|
"curly": [true, "ignore-same-line"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user