MCPcopy Create free account
hub / github.com/ShaderFrog/glsl-parser / renameFunction

Function renameFunction

src/parser/utils.ts:70–110  ·  view source on GitHub ↗
(
  overloadIndex: FunctionOverloadIndex,
  newName: string
)

Source from the content-addressed store, hash-verified

68 }, {});
69
70export const renameFunction = (
71 overloadIndex: FunctionOverloadIndex,
72 newName: string
73) => {
74 Object.entries(overloadIndex).forEach(([signature, overload]) => {
75 overload.references.forEach((node) => {
76 if (node.type === 'function') {
77 node['prototype'].header.name.identifier = newName;
78 } else if (
79 node.type === 'function_call' &&
80 node.identifier.type === 'postfix'
81 ) {
82 // @ts-ignore
83 const specifier = node.identifier.expression.identifier.specifier;
84 if (specifier) {
85 specifier.identifier = newName;
86 } else {
87 console.warn('Unknown function node to rename', node);
88 throw new Error(
89 `Function specifier type ${node.type} not recognized`
90 );
91 }
92 } else if (
93 node.type === 'function_call' &&
94 'specifier' in node.identifier &&
95 'identifier' in node.identifier.specifier
96 ) {
97 node.identifier.specifier.identifier = newName;
98 } else if (
99 node.type === 'function_call' &&
100 node.identifier.type === 'identifier'
101 ) {
102 node.identifier.identifier = newName;
103 } else {
104 console.warn('Unknown function node to rename', node);
105 throw new Error(`Function for type ${node.type} not recognized`);
106 }
107 });
108 });
109 return overloadIndex;
110};
111
112export const renameFunctions = (
113 functions: FunctionScopeIndex,

Callers 1

renameFunctionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected