Skip to content

fix(glsl-lang-pp): eval and expand #elif only if the last is none#61

Merged
alixinne merged 3 commits intoalixinne:masterfrom
yorkie:fix/pp-elif
Sep 15, 2025
Merged

fix(glsl-lang-pp): eval and expand #elif only if the last is none#61
alixinne merged 3 commits intoalixinne:masterfrom
yorkie:fix/pp-elif

Conversation

@yorkie
Copy link
Contributor

@yorkie yorkie commented Aug 28, 2025

This pull request refines the handling of conditional preprocessing directives in the macro expansion logic, specifically improving how elif directives are evaluated based on the current state of the if stack.

For example:

#version 300 es
#define CS1
#define CS2
#define CS3

vec3 test() {
#if defined(CS1)
  return vec3(1.0, 0.0, 0.0);
#elif defined(CS2)
  return vec3(2.0, 0.0, 0.0);
#elif defined(CS3)
  return vec3(3.0, 1.0, 0.0);
#else
  return vec3(0.0, 0.0, 1.0);
#endif
}

Without this patch, it will be expanded to:

#version 300 es
vec3 test() {
  return vec3(1.0, 0.0, 0.0);
  return vec3(2.0, 0.0, 0.0);
  return vec3(3.0, 1.0, 0.0);
#endif
}

@yorkie yorkie requested a review from alixinne as a code owner August 28, 2025 19:19
@yorkie
Copy link
Contributor Author

yorkie commented Sep 15, 2025

/cc @alixinne

@alixinne
Copy link
Owner

Sorry about the delay, I was away from a keyboard these past few weeks and just came back. I'll look into it this week 👍

@alixinne alixinne changed the title pp: eval and expand #elif only if the last is none fix(glsl-lang-pp): eval and expand #elif only if the last is none Sep 15, 2025
Copy link
Owner

@alixinne alixinne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix 🚀

@alixinne alixinne merged commit c8a070b into alixinne:master Sep 15, 2025
2 of 3 checks passed
@yorkie yorkie deleted the fix/pp-elif branch September 16, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants