MCPcopy Create free account
hub / github.com/charto/nbind / typeModule

Function typeModule

src/Type.ts:118–378  ·  view source on GitHub ↗
(self: any)

Source from the content-addressed store, hash-verified

116
117/* tslint:disable:no-shadowed-variable */
118export function typeModule(self: any) {
119
120 // Parameter count and printable name of each StructureType.
121
122 type Structure = [TypeFlags, number, string];
123 const structureList: Structure[] = [
124 [0, 1, 'X'],
125 [TypeFlags.isConst, 1, 'const X'],
126 [TypeFlags.isPointer, 1, 'X *'],
127 [TypeFlags.isReference, 1, 'X &'],
128 [TypeFlags.isRvalueRef, 1, 'X &&'],
129 [TypeFlags.isSharedPtr, 1, 'std::shared_ptr<X>'],
130 [TypeFlags.isUniquePtr, 1, 'std::unique_ptr<X>'],
131 [TypeFlags.isVector, 1, 'std::vector<X>'],
132 [TypeFlags.isArray, 2, 'std::array<X, Y>'],
133 [TypeFlags.isCallback, -1, 'std::function<X (Y)>']
134 ];
135
136 function applyStructure(
137 outerName: string,
138 outerFlags: TypeFlags,
139 innerName: string,
140 innerFlags: TypeFlags,
141 param: string,
142 flip?: boolean
143 ) {
144 if(outerFlags == TypeFlags.isConst) {
145 const ref = innerFlags & TypeFlags.refMask;
146 if(
147 ref == TypeFlags.isPointer ||
148 ref == TypeFlags.isReference ||
149 ref == TypeFlags.isRvalueRef
150 ) outerName = 'X const';
151 }
152
153 let name: string;
154
155 if(flip) {
156 name = innerName.replace('X', outerName).replace('Y', param);
157 } else {
158 name = outerName.replace('X', innerName).replace('Y', param);
159 }
160
161 // Remove spaces between consecutive * and & characters.
162 return(name.replace(/([*&]) (?=[*&])/g, '$1'));
163 }
164
165 function reportProblem(
166 problem: string,
167 id: number,
168 kind: string,
169 structureType: StructureType,
170 place: string
171 ) {
172 throw(new Error(
173 problem + ' type ' +
174 kind.replace('X', id + '?') +
175 (structureType ? ' with flag ' + structureType : '') +

Callers 2

reflect.tsFile · 0.90
Type.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected