Use extension framework to enable #include directive.

This patch introduces a new extension, GL_GOOGLE_include_directive,
to enable support #include directives. It depends on the extension
GL_GOOGLE_cpp_style_line_directive.
This commit is contained in:
Lei Zhang 2015-07-16 17:33:10 -04:00
parent 7be4b8282d
commit 9c1280b225
11 changed files with 51 additions and 13 deletions

View File

@ -0,0 +1,13 @@
ERROR: 0:8000: '#include' : required extension not requested: GL_GOOGLE_include_directive
ERROR: 0:8000: '#include' : must be followed by a file designation
ERROR: 0:8001: '#include' : required extension not requested: GL_GOOGLE_include_directive
ERROR: 0:8001: '#include' : must be followed by a file designation
ERROR: 0:8002: '#include' : required extension not requested: GL_GOOGLE_include_directive
ERROR: 0:8002: '#error' : unexpected include directive
ERROR: 0:8003: '#include' : required extension not requested: GL_GOOGLE_include_directive
ERROR: 0:8003: '#include' : extra content after file designation
ERROR: 0:8004: '#include' : required extension not requested: GL_GOOGLE_include_directive
ERROR: 0:8004: '#error' : unexpected include directive
ERROR: 10 compilation errors. No code generated.

View File

@ -1,6 +1,7 @@
#line 8000
#include
#include 123
#include "foo"
#include "foo" garbage
#include "no-eol"
#line 8000
#include
#include 123
#include "foo"
#include "foo" garbage
#include "no-eol"

View File

@ -0,0 +1,7 @@
#extension GL_GOOGLE_include_directive : enable
#line 8000
#include
#include 123
#include "foo"
#include "foo" garbage
#include "no-eol"

View File

@ -4,7 +4,8 @@ preprocessor.edge_cases.vert
preprocessor.errors.vert
preprocessor.extensions.vert
preprocessor.function_macro.vert
preprocessor.include.vert
preprocessor.include.enabled.vert
preprocessor.include.disabled.vert
preprocessor.line.vert
preprocessor.line.frag
preprocessor.pragma.vert

View File

@ -235,7 +235,7 @@ public:
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc, bool requiredByPreprocessor = false);
TExtensionBehavior getExtensionBehavior(const char*);
bool extensionTurnedOn(const char* const extension);
bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);

View File

@ -174,7 +174,9 @@ void TParseContext::initializeExtensionBehavior()
extensionBehavior[E_GL_ARB_viewport_array] = EBhDisable;
// extensionBehavior[E_GL_ARB_cull_distance] = EBhDisable; // present for 4.5, but need extension control over block members
// #line and #include
extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhDisable;
extensionBehavior[E_GL_GOOGLE_include_directive] = EBhDisable;
// AEP
extensionBehavior[E_GL_ANDROID_extension_pack_es31a] = EBhDisablePartial;
@ -219,7 +221,9 @@ const char* TParseContext::getPreamble()
"#define GL_OES_EGL_image_external 1\n"
"#define GL_EXT_shader_texture_lod 1\n"
// #line and #include
"#define GL_GOOGLE_cpp_style_line_directive 1\n"
"#define GL_GOOGLE_include_directive 1\n"
// AEP
"#define GL_ANDROID_extension_pack_es31a 1\n"
@ -270,6 +274,7 @@ const char* TParseContext::getPreamble()
"#define GL_ARB_viewport_array 1\n"
"#define GL_GOOGLE_cpp_style_line_directive 1\n"
"#define GL_GOOGLE_include_directive 1\n"
// "#define GL_ARB_cull_distance 1\n" // present for 4.5, but need extension control over block members
;
}
@ -410,7 +415,7 @@ void TParseContext::requireNotRemoved(const TSourceLoc& loc, int profileMask, in
// Use when there are no profile/version to check, it's just an error if one of the
// extensions is not present.
//
void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc, bool requiredByPreprocessor)
{
// First, see if any of the extensions are enabled
for (int i = 0; i < numExtensions; ++i) {
@ -437,9 +442,15 @@ void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions,
// If we get this far, give errors explaining what extensions are needed
if (numExtensions == 1)
error(loc, "required extension not requested:", featureDesc, extensions[0]);
if (requiredByPreprocessor)
ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
else
error(loc, "required extension not requested:", featureDesc, extensions[0]);
else {
error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
if (requiredByPreprocessor)
ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
else
error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
for (int i = 0; i < numExtensions; ++i)
infoSink.info.message(EPrefixNone, extensions[i]);
}
@ -525,6 +536,8 @@ void TParseContext::updateExtensionBehavior(int line, const char* extension, con
updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
else if (strcmp(extension, "GL_OES_tessellation_shader") == 0)
updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
else if (strcmp(extension, "GL_GOOGLE_include_directive") == 0)
updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
}
void TParseContext::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)

View File

@ -112,7 +112,9 @@ const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
//const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
// #line and #include
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
// AEP
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";

View File

@ -661,7 +661,7 @@ int TPpContext::CPPline(TPpToken* ppToken)
if (token != '\n') {
if (token == PpAtomConstString) {
parseContext.requireExtensions(directiveLoc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based #line");
parseContext.requireExtensions(directiveLoc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based #line", true);
// We need to save a copy of the string instead of pointing
// to the name field of the token since the name field
// will likely be overwritten by the next token scan.
@ -878,6 +878,7 @@ int TPpContext::readCPPline(TPpToken* ppToken)
token = CPPifdef(0, ppToken);
break;
case PpAtomInclude:
parseContext.requireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_include_directive, "#include", true);
token = CPPinclude(ppToken);
break;
case PpAtomLine:
@ -1002,7 +1003,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool
case PpAtomFileMacro: {
if (const char* current_file = parseContext.getCurrentLoc().name) {
parseContext.requireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based __FILE__");
parseContext.requireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based __FILE__", true);
sprintf(ppToken->name, "\"%s\"", current_file);
} else {
ppToken->ival = parseContext.getCurrentLoc().string;