emitType()

in src/langs/swift/combinator.js [229:271]


  emitType(type) {
    if (!is.type(type)) {
      debug.stack('Inavalid type', type);
    }
    let type_str = null;
    if (is.any(type)) {
      type_str = 'Any';
    } else if (is.decimal(type)) {
      type_str = 'Double';
    } else if (is.integer(type)) {
      type_str = !type.length ? 'Int' : type.length > 32 ? 'Int64' : 'Int32';
    } else if (is.number(type)) {
      type_str = 'Int';
    } else if (is.string(type)) {
      type_str = 'String';
    } else if (is.bytes(type)) {
      type_str = '[UInt8]';
    } else if (is.array(type)) {
      let subType = this.emitType(type.itemType);
      type_str = `[${subType}]`;
    } else if (is.bool(type)) {
      type_str = 'Bool';
    } else if (is.void(type)) {
      type_str = 'Void';
    } else if (is.map(type)) {
      type_str = `[${this.emitType(type.keyType)}: ${this.emitType(type.valType)}]`;
    } else if (is.inputStream(type)) {
      type_str = this.addInclude('$InputStream');
    } else if (is.outputStream(type)) {
      type_str = this.addInclude('$OutputStream');
    } else if (is.object(type)) {
      type_str = !type.objectName ? 'Void' : this.resolveName(type.objectName);
    } else if (is.null(type)) {
      type_str = 'nil';
    }
    if (type_str === null) {
      debug.stack('Unsupported Type', type);
    }
    if (typeof type_str === 'undefined') {
      debug.stack(type);
    }
    return type_str;
  }