MCPcopy Index your code
hub / github.com/gpujs/gpu.js / getVariableSignature

Method getVariableSignature

src/backend/function-node.js:800–871  ·  view source on GitHub ↗
(ast, returnRawValue)

Source from the content-addressed store, hash-verified

798 }
799
800 getVariableSignature(ast, returnRawValue) {
801 if (!this.isAstVariable(ast)) {
802 throw new Error(`ast of type "${ ast.type }" is not a variable signature`);
803 }
804 if (ast.type === 'Identifier') {
805 return 'value';
806 }
807 const signature = [];
808 while (true) {
809 if (!ast) break;
810 if (ast.computed) {
811 signature.push('[]');
812 } else if (ast.type === 'ThisExpression') {
813 signature.unshift('this');
814 } else if (ast.property && ast.property.name) {
815 if (
816 ast.property.name === 'x' ||
817 ast.property.name === 'y' ||
818 ast.property.name === 'z'
819 ) {
820 signature.unshift(returnRawValue ? '.' + ast.property.name : '.value');
821 } else if (
822 ast.property.name === 'constants' ||
823 ast.property.name === 'thread' ||
824 ast.property.name === 'output'
825 ) {
826 signature.unshift('.' + ast.property.name);
827 } else {
828 signature.unshift(returnRawValue ? '.' + ast.property.name : '.value');
829 }
830 } else if (ast.name) {
831 signature.unshift(returnRawValue ? ast.name : 'value');
832 } else if (ast.callee && ast.callee.name) {
833 signature.unshift(returnRawValue ? ast.callee.name + '()' : 'fn()');
834 } else if (ast.elements) {
835 signature.unshift('[]');
836 } else {
837 signature.unshift('unknown');
838 }
839 ast = ast.object;
840 }
841
842 const signatureString = signature.join('');
843 if (returnRawValue) {
844 return signatureString;
845 }
846
847 const allowedExpressions = [
848 'value',
849 'value[]',
850 'value[][]',
851 'value[][][]',
852 'value[][][][]',
853 'value.value',
854 'value.thread.value',
855 'this.thread.value',
856 'this.output.value',
857 'this.constants.value',

Callers 2

getTypeMethod · 0.95

Calls 1

isAstVariableMethod · 0.95

Tested by

no test coverage detected