MCPcopy Create free account
hub / github.com/dharmaprotocol/dharmaOS / deriveTypedArrayElementTotals

Method deriveTypedArrayElementTotals

src/encoder.js:366–477  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

364 }
365
366 deriveTypedArrayElementTotals() {
367 const { definitions } = this.actionScript;
368
369 // find the argument index of all typed arrays for each defined function
370 const typedArrayIndicesByFunction = definitions
371 .filter(definition => definition.startsWith("Function "))
372 .map(definition => {
373 const functionName = definition.split(' ')[1].split(':')[0];
374 const callArgumentTypes = Encoder.parseCallArgumentTypes(definition);
375 const typedArrayArgumentsByIndex = callArgumentTypes
376 .map((e, i) => e.endsWith('[]') ? i : null)
377 .filter(e => e !== null);
378
379 const callReturnTypes = Encoder.parseCallReturnTypes(definition);
380 const typedArrayReturnsByIndex = callReturnTypes
381 .map((e, i) => e.endsWith('[]') ? i : null)
382 .filter(e => e !== null);
383
384 return [
385 functionName,
386 {
387 typedArrayArgumentsByIndex,
388 typedArrayReturnsByIndex,
389 }
390 ];
391 }).reduce(
392 (result, [key, value]) => Object.assign({}, result, {[key]: value}),
393 {}
394 );
395
396 this.typedArrayElementTotals = this.actions
397 .filter(action => (
398 action.split(' ')[1].split(':')[0] in typedArrayIndicesByFunction
399 )).map(action => {
400 const argumentElementTotals = {};
401 const returnElementTotals = {};
402
403 const functionName = action.split(' ')[1].split(':')[0];
404
405 let givenArgumentsString = action.split(" => ")[0].split(" ").slice(2).join(" ");
406
407 let givenArguments = [];
408
409 while (givenArgumentsString) {
410 if (givenArgumentsString.startsWith("(")) {
411 givenArguments.push(
412 givenArgumentsString.slice(
413 1,
414 givenArgumentsString.indexOf(")")
415 ).split(" ")
416 );
417
418 givenArgumentsString = givenArgumentsString
419 .slice(givenArgumentsString.indexOf(")") + 1)
420 .trim();
421 } else if (givenArgumentsString.indexOf(" ") !== -1) {
422 givenArguments.push(
423 givenArgumentsString.slice(

Callers 1

Calls 2

parseCallReturnTypesMethod · 0.80

Tested by

no test coverage detected