capnpc-ts
Version:
Cap'n Proto schema compiler for TypeScript.
192 lines (153 loc) • 4.27 kB
text/typescript
/**
* @author jdiaz5513
*/
import * as s from "capnp-ts/src/std/schema.capnp.js";
import initTrace from "debug";
import ts from "typescript";
const trace = initTrace("capnpc:constants");
trace("load");
/** undefined */
export const __ = undefined;
/** boolean */
export const BOOLEAN_TYPE = ts.createTypeReferenceNode("boolean", __);
/** capnp */
export const CAPNP = ts.createIdentifier("capnp");
/** A Mapping of various types to their list type constructor. */
export const ConcreteListType = {
[]: "capnp.AnyPointerList",
[]: "capnp.BoolList",
[]: "capnp.DataList",
[]: "capnp.Uint16List",
[]: "capnp.Float32List",
[]: "capnp.Float64List",
[]: "capnp.Int16List",
[]: "capnp.Int32List",
[]: "capnp.Int64List",
[]: "capnp.Int8List",
[]: "capnp.InterfaceList",
[]: "capnp.PointerList",
[]: "capnp.CompositeList",
[]: "capnp.TextList",
[]: "capnp.Uint16List",
[]: "capnp.Uint32List",
[]: "capnp.Uint64List",
[]: "capnp.Uint8List",
[]: "capnp.VoidList",
};
/** export */
export const EXPORT = ts.createToken(ts.SyntaxKind.ExportKeyword);
/** length */
export const LENGTH = ts.createIdentifier("length");
/** Some data used to help generate code for primitive struct fields. */
export const Primitive: { [t: number]: { byteLength: number; getter: string; mask: string; setter: string } } = {
[]: {
byteLength: 1,
getter: "getBit",
mask: "getBitMask",
setter: "setBit",
},
[]: {
byteLength: 2,
getter: "getUint16",
mask: "getUint16Mask",
setter: "setUint16",
},
[]: {
byteLength: 4,
getter: "getFloat32",
mask: "getFloat32Mask",
setter: "setFloat32",
},
[]: {
byteLength: 8,
getter: "getFloat64",
mask: "getFloat64Mask",
setter: "setFloat64",
},
[]: {
byteLength: 2,
getter: "getInt16",
mask: "getInt16Mask",
setter: "setInt16",
},
[]: {
byteLength: 4,
getter: "getInt32",
mask: "getInt32Mask",
setter: "setInt32",
},
[]: {
byteLength: 8,
getter: "getInt64",
mask: "getInt64Mask",
setter: "setInt64",
},
[]: {
byteLength: 1,
getter: "getInt8",
mask: "getInt8Mask",
setter: "setInt8",
},
[]: {
byteLength: 2,
getter: "getUint16",
mask: "getUint16Mask",
setter: "setUint16",
},
[]: {
byteLength: 4,
getter: "getUint32",
mask: "getUint32Mask",
setter: "setUint32",
},
[]: {
byteLength: 8,
getter: "getUint64",
mask: "getUint64Mask",
setter: "setUint64",
},
[]: {
byteLength: 1,
getter: "getUint8",
mask: "getUint8Mask",
setter: "setUint8",
},
[]: {
byteLength: 0,
getter: "getVoid",
mask: "getVoidMask",
setter: "setVoid",
},
};
/** number */
export const NUMBER_TYPE = ts.createTypeReferenceNode("number", __);
/** __O */
// This is referenced so frequently it gets a shorthand!
export const OBJECT_SIZE = ts.createIdentifier("__O");
/** readonly */
export const READONLY = ts.createToken(ts.SyntaxKind.ReadonlyKeyword);
/** No... comment? */
export const SOURCE_COMMENT = `/* tslint:disable */
/**
* This file has been automatically generated by the [capnpc-ts utility](https://github.com/jdiaz5513/capnp-ts).
*/
`;
/** static */
export const STATIC = ts.createToken(ts.SyntaxKind.StaticKeyword);
/** string */
export const STRING_TYPE = ts.createTypeReferenceNode("string", __);
/** __S */
// This is referenced so frequently it gets a shorthand!
export const STRUCT = ts.createIdentifier("__S");
/** this */
export const THIS = ts.createThis();
/**
* Used to look up the ts.capnp file by its ID.
*
* NOTE: The file ID should never change.
*/
export const TS_FILE_ID = "e37ded525a68a7c9";
/** value */
export const VALUE = ts.createIdentifier("value");
/** void */
export const VOID_TYPE = ts.createTypeReferenceNode("void", __);