UNPKG

@neo-one/smart-contract-compiler-esnext-esm

Version:

NEO•ONE TypeScript smart contract compiler.

379 lines (377 loc) 15.4 kB
import { utils } from '@neo-one/utils-esnext-esm'; import { getForwardedValueType } from '../../../utils'; import { Types } from '../../constants'; import { Helper } from '../Helper'; import { hasAccount } from './account'; import { hasArray } from './array'; import { hasArrayStorage } from './arrayStorage'; import { hasAsset } from './asset'; import { hasAttribute } from './attribute'; import { hasBlock } from './block'; import { hasBoolean } from './boolean'; import { hasBuffer } from './buffer'; import { hasContract } from './contract'; import { hasError } from './error'; import { hasForwardValue } from './forwardValue'; import { hasHeader } from './header'; import { hasInput } from './input'; import { hasIterable } from './iterable'; import { hasIterableIterator } from './iterableIterator'; import { hasIteratorResult } from './iteratorResult'; import { hasMap } from './map'; import { hasMapStorage } from './mapStorage'; import { hasNull } from './null'; import { hasNumber } from './number'; import { hasObject } from './object'; import { hasOutput } from './output'; import { hasSet } from './set'; import { hasSetStorage } from './setStorage'; import { hasString } from './string'; import { hasSymbol } from './symbol'; import { hasTransaction } from './transaction'; import { hasUndefined } from './undefined'; export class ForBuiltinTypeHelper extends Helper { constructor({ type, knownType, single, singleUndefined, singleFalse, optional, array, map, set, boolean: processBoolean, buffer, null: processNull, number: processNumber, object, string: processString, symbol, undefined: processUndefined, arrayStorage, mapStorage, setStorage, error, iteratorResult, iterable, iterableIterator, transaction, output, attribute, input, account, asset, contract, header, block, forwardValue, }) { super(); this.type = type; this.knownType = knownType; this.single = single; this.singleUndefined = singleUndefined; this.singleFalse = singleFalse; this.optional = optional; this.array = array; this.map = map; this.set = set; this.boolean = processBoolean; this.buffer = buffer; this.null = processNull; this.number = processNumber; this.object = object; this.string = processString; this.symbol = symbol; this.undefined = processUndefined; this.arrayStorage = arrayStorage; this.mapStorage = mapStorage; this.setStorage = setStorage; this.error = error; this.iteratorResult = iteratorResult; this.iterable = iterable; this.iterableIterator = iterableIterator; this.transaction = transaction; this.output = output; this.attribute = attribute; this.input = input; this.account = account; this.asset = asset; this.contract = contract; this.header = header; this.block = block; this.forwardValue = forwardValue; } emit(sb, node, options) { if (this.knownType !== undefined) { this.processKnownType(this.knownType, options); return; } let tpe = this.type; if (tpe !== undefined && sb.context.builtins.isType(node, tpe, 'ForwardedValue')) { tpe = getForwardedValueType(tpe); } sb.emitHelper(node, options, sb.helpers.forType({ type: tpe, single: this.single, singleUndefined: this.singleUndefined, singleFalse: this.singleFalse, optional: this.optional, types: [ { hasType: (type) => hasUndefined(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isUndefined); }, process: this.undefined, }, { hasType: (type) => hasNull(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isNull); }, process: this.null, }, { hasType: (type) => hasBoolean(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isBoolean); }, process: this.boolean, }, { hasType: (type) => hasNumber(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isNumber); }, process: this.number, }, { hasType: (type) => hasString(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isString); }, process: this.string, }, { hasType: (type) => hasSymbol(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isSymbol); }, process: this.symbol, }, { hasType: (type) => hasBuffer(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isBuffer); }, process: this.buffer, }, { hasType: (type) => hasArray(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isArray); }, process: this.array, }, { hasType: (type) => hasArrayStorage(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isArrayStorage); }, process: this.arrayStorage, }, { hasType: (type) => hasMap(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isMap); }, process: this.map, }, { hasType: (type) => hasMapStorage(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isMapStorage); }, process: this.mapStorage, }, { hasType: (type) => hasSet(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isSet); }, process: this.set, }, { hasType: (type) => hasSetStorage(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isSetStorage); }, process: this.setStorage, }, { hasType: (type) => hasError(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isError); }, process: this.error, }, { hasType: (type) => hasIteratorResult(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isIteratorResult); }, process: this.iteratorResult, }, { hasType: (type) => hasIterableIterator(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isIterableIterator); }, process: this.iterableIterator, }, { hasType: (type) => hasForwardValue(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isForwardValue); }, process: this.forwardValue, }, { hasType: (type) => hasTransaction(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isTransaction); }, process: this.transaction, }, { hasType: (type) => hasOutput(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isOutput); }, process: this.output, }, { hasType: (type) => hasAttribute(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isAttribute); }, process: this.attribute, }, { hasType: (type) => hasInput(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isInput); }, process: this.input, }, { hasType: (type) => hasAccount(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isAccount); }, process: this.account, }, { hasType: (type) => hasAsset(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isAsset); }, process: this.asset, }, { hasType: (type) => hasContract(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isContract); }, process: this.contract, }, { hasType: (type) => hasHeader(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isHeader); }, process: this.header, }, { hasType: (type) => hasBlock(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isBlock); }, process: this.block, }, { hasType: (type) => hasIterable(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isIterable); }, process: this.iterable, }, { hasType: (type) => hasObject(sb.context, node, type), isRuntimeType: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.isObject); }, process: this.object, }, ], })); } processKnownType(knownType, options) { switch (knownType) { case Types.Array: this.array(options); break; case Types.ArrayStorage: this.arrayStorage(options); break; case Types.Map: this.map(options); break; case Types.MapStorage: this.mapStorage(options); break; case Types.Set: this.set(options); break; case Types.SetStorage: this.setStorage(options); break; case Types.Error: this.error(options); break; case Types.IteratorResult: this.iteratorResult(options); break; case Types.Iterable: this.iterable(options); break; case Types.IterableIterator: this.iterableIterator(options); break; case Types.Boolean: this.boolean(options); break; case Types.Buffer: this.buffer(options); break; case Types.ForwardValue: this.forwardValue(options); break; case Types.Null: this.null(options); break; case Types.Number: this.number(options); break; case Types.Object: this.object(options); break; case Types.String: this.string(options); break; case Types.Symbol: this.symbol(options); break; case Types.Undefined: this.undefined(options); break; case Types.Transaction: this.transaction(options); break; case Types.Output: this.output(options); break; case Types.Attribute: this.attribute(options); break; case Types.Input: this.input(options); break; case Types.Account: this.account(options); break; case Types.Asset: this.asset(options); break; case Types.Contract: this.contract(options); break; case Types.Header: this.header(options); break; case Types.Block: this.block(options); break; default: utils.assertNever(knownType); } } } //# sourceMappingURL=ForBuiltinTypeHelper.js.map