MCPcopy Create free account
hub / github.com/processing/p5.js / structConstructorNode

Function structConstructorNode

src/strands/ir_builders.js:347–383  ·  view source on GitHub ↗
(strandsContext, structTypeInfo, rawUserArgs)

Source from the content-addressed store, hash-verified

345}
346
347export function structConstructorNode(strandsContext, structTypeInfo, rawUserArgs) {
348 const { cfg, dag } = strandsContext;
349 const { identifer, properties } = structTypeInfo;
350
351 if (!(rawUserArgs.length === properties.length)) {
352 FES.userError('type error',
353 `You've tried to construct a ${structTypeInfo.typeName} struct with ${rawUserArgs.length} properties, but it expects ${properties.length} properties.\n` +
354 `The properties it expects are:\n` +
355 `${properties.map(prop => prop.name + ' ' + prop.DataType.baseType + prop.DataType.dimension)}`
356 );
357 }
358
359 const dependsOn = [];
360 for (let i = 0; i < properties.length; i++) {
361 const expectedProperty = properties[i];
362 const { originalNodeID, mappedDependencies } = mapPrimitiveDepsToIDs(strandsContext, expectedProperty.dataType, rawUserArgs[i]);
363 if (originalNodeID) {
364 dependsOn.push(originalNodeID);
365 }
366 else {
367 dependsOn.push(
368 constructTypeFromIDs(strandsContext, expectedProperty.dataType, mappedDependencies)
369 );
370 }
371 }
372
373 const nodeData = DAG.createNodeData({
374 nodeType: NodeType.OPERATION,
375 opCode: OpCode.Nary.CONSTRUCTOR,
376 dimension: properties.length,
377 baseType: structTypeInfo.typeName ,
378 dependsOn
379 });
380 const id = DAG.getOrCreateNode(dag, nodeData);
381 CFG.recordInBasicBlock(cfg, cfg.currentBlock, id);
382 return { id, dimension: properties.length, components: structTypeInfo.components };
383}
384
385export function functionCallNode(
386 strandsContext,

Callers

nothing calls this directly

Calls 3

mapPrimitiveDepsToIDsFunction · 0.85
constructTypeFromIDsFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected