MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / parseSignatures

Method parseSignatures

tools/ffi.js:341–390  ·  view source on GitHub ↗
(functions)

Source from the content-addressed store, hash-verified

339 return type;
340 }
341 parseSignatures(functions) {
342 const tool = this.tool;
343 const signatures = [];
344 if (!(typeof(functions) == "object")) {
345 tool.reportError(null, 0, `functions: not an object`);
346 }
347 else {
348 for (let name in functions) {
349 const signature = functions[name];
350 if (!(typeof(signature) == "object")) {
351 tool.reportError(null, 0, `functions.${ name }: not an object`);
352 signatures.push({ name });
353 }
354 else {
355 let resultType = signature.returns || "void";
356 let Constructor = ResultConstructors[this.normalizeType(resultType)];
357 if (!Constructor)
358 tool.reportError(null, 0, `functions.${ name }.returns: invalid type ${resultType}`);
359 else
360 resultType = new Constructor(resultType, this.count);
361
362 const argumentTypes = signature.arguments;
363 if (argumentTypes) {
364 if (!Array.isArray(argumentTypes)) {
365 tool.reportError(null, 0, `functions.${ name }.arguments: not an array`);
366 }
367 else {
368 for (let i = 0; i < argumentTypes.length; i++) {
369 let argumentType = argumentTypes[i];
370 let Constructor = ArgumentConstructors[this.normalizeType(argumentType)];
371 if (!Constructor)
372 tool.reportError(null, 0, `functions.${ name }.arguments[${ i }]: invalid type ${argumentType}`);
373 else
374 argumentTypes[i] = new Constructor(argumentType, this.count);
375 }
376 }
377 }
378 else
379 argumentTypes = [];
380 signatures.push({ name, resultType, argumentTypes });
381 }
382 }
383 if (signatures.length == 0)
384 tool.reportError(null, 0, `functions: empty object`);
385 }
386 if (tool.errorCount) {
387 throw new Error(`Invalid functions: ${ tool.errorCount } error(s)`);
388 }
389 return signatures;
390 }
391 generateCFile(file, signatures, mod, windows) {
392 file.line(`/* FFI GENERATED FILE; DO NOT EDIT! */`);
393 file.line();

Callers 2

mcConfigMethod · 0.95
mcRunMethod · 0.95

Calls 2

normalizeTypeMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected