Implement optional type parameters (#360)

* Add a NATIVE<T> macro type to simplify use of a native WebAssembly type
* Add default type parameters for internal helpers for explicit loads and stores
* Unify loadUnsafe/loadUnsafeWithOffset etc. into one
* Renamed loadUnsafe etc. into just LOAD, like a macro
* Implement parsing of index signatures, but ignore them, for properly linting code
* Refactor TypedArray<T> to use macros
This commit is contained in:
Daniel Wirtz
2018-12-07 14:33:32 +01:00
committed by GitHub
parent d7f4874650
commit ebae7cbd73
39 changed files with 4698 additions and 4128 deletions

View File

@ -87,6 +87,7 @@ export enum NodeKind {
FIELDDECLARATION,
FUNCTIONDECLARATION,
IMPORTDECLARATION,
INDEXSIGNATUREDECLARATION,
INTERFACEDECLARATION,
METHODDECLARATION,
NAMESPACEDECLARATION,
@ -181,12 +182,14 @@ export abstract class Node {
static createTypeParameter(
name: IdentifierExpression,
extendsType: TypeNode | null,
defaultType: TypeNode | null,
range: Range
): TypeParameterNode {
var elem = new TypeParameterNode();
elem.range = range;
elem.name = name; name.parent = elem;
elem.extendsType = extendsType; if (extendsType) extendsType.parent = elem;
elem.defaultType = defaultType; if (defaultType) defaultType.parent = elem;
return elem;
}
@ -871,6 +874,18 @@ export abstract class Node {
return stmt;
}
static createIndexSignatureDeclaration(
keyType: TypeNode,
valueType: CommonTypeNode,
range: Range
): IndexSignatureDeclaration {
var elem = new IndexSignatureDeclaration();
elem.range = range;
elem.keyType = keyType; keyType.parent = elem;
elem.valueType = valueType; valueType.parent = elem;
return elem;
}
static createMethodDeclaration(
name: IdentifierExpression,
typeParameters: TypeParameterNode[] | null,
@ -1070,6 +1085,8 @@ export class TypeParameterNode extends Node {
name: IdentifierExpression;
/** Extended type reference, if any. */
extendsType: TypeNode | null; // can't be a function
/** Default type if omitted, if any. */
defaultType: TypeNode | null; // can't be a function
}
/** Represents the kind of a parameter. */
@ -1622,6 +1639,16 @@ export abstract class DeclarationStatement extends Statement {
}
}
/** Represents an index signature declaration. */
export class IndexSignatureDeclaration extends DeclarationStatement {
kind = NodeKind.INDEXSIGNATUREDECLARATION;
/** Key type. */
keyType: TypeNode;
/** Value type. */
valueType: CommonTypeNode;
}
/** Base class of all variable-like declaration statements. */
export abstract class VariableLikeDeclarationStatement extends DeclarationStatement {