Compile time shader stage information in GLSL

As far as I know there currently is no way to retrieve the stage for which the GLSL compiler is generating code.
Such a feature could ease the development of GLSL libraries whose functions can be evaluated accross multiple stages.
Here’s an example of source code which could be included at any stage and is safe to use:

// check GLSL compiler version
#if (__VERSION__ < 150)
#error Unsupported GLSL version
#endif

// some function (shading function for example)
vec3 shade(...) {
#if (__STAGE__ == GL_vertex_stage)
    perform per-vertex operations
#elif (__STAGE__ == GL_fragment_stage)
   per-fragment operations
#else
// either halt compilation...
   #error Invalid stage 
// ... or return something
   return vec3(0);
#endif
}

On the client side, one would simply use

const GLchar * files[] = {"library.glsl", "main_function.glsl"};
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 2, load_strings(2, files), NULL);

Granted, this can already be accomplished by including a string in glShaderSource, but having the compiler doing it would save some time and ease the development of safer and more portable GLSL libraries… What do you think ?

It’s already been discussed. In the future, you should look around a bit to see if something you want to proposed has already been proposed.

[QUOTE=Alfonse Reinheart;1248489]It’s already been discussed. In the future, you should look around a bit to see if something you want to proposed has already been proposed.[/QUOTE]I should have linked this in my post as it is indeed related to what I am asking for. I guess I am adding another argument in favour of this proposal: users can still use multiple strings, compile time stage improves shader library code portability. There already are some great GLSL libraries available which are easy to share since they do not use built-in functions whose behaviour vary depending on the shader stage (texture, dFdx, etc.). Adding such a feature could allow richer libraries to emerge without forcing users to print strings for each library they use.