Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing rename case for function prototypes #41

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "5.4.0",
"version": "5.4.1",
"type": "module",
"description": "A GLSL ES 1.0 and 3.0 parser and preprocessor that can preserve whitespace and comments",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions src/parser/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,18 @@ void main() {
const a = Object.values(ast.scopes[0].functions.a)[0];
expect(a.references).toHaveLength(3);
});

test('rename function prototypes', () => {
const ast = c.parseSrc(
`vec3 hash3(vec3 p3);
vec3 hash3(vec3 p3) {}`
);

ast.scopes[0].functions = renameFunctions(
ast.scopes[0].functions,
(name) => `${name}_FUNCTION`
);

expect(generate(ast)).toBe(`vec3 hash3_FUNCTION(vec3 p3);
vec3 hash3_FUNCTION(vec3 p3) {}`);
});
2 changes: 2 additions & 0 deletions src/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export const renameFunction = (
node.identifier.type === 'identifier'
) {
node.identifier.identifier = newName;
} else if (node.type === 'function_prototype') {
node.header.name.identifier = newName;
} else {
console.warn('Unknown function node to rename', node);
throw new Error(`Function for type ${node.type} not recognized`);
Expand Down
Loading