Merge pull request #663 from KhronosGroup/full-include-semantics
Includer interface change to support full include semantics (requires downstream changes)
This commit is contained in:
commit
ce80197c22
@ -582,7 +582,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
|
|
||||||
if (Options & EOptionOutputPreprocessed) {
|
if (Options & EOptionOutputPreprocessed) {
|
||||||
std::string str;
|
std::string str;
|
||||||
glslang::TShader::ForbidInclude includer;
|
glslang::TShader::ForbidIncluder includer;
|
||||||
if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false,
|
if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false,
|
||||||
messages, &str, includer)) {
|
messages, &str, includer)) {
|
||||||
PutsIfNonEmpty(str.c_str());
|
PutsIfNonEmpty(str.c_str());
|
||||||
|
@ -3,7 +3,7 @@ ERROR: 0:8000: '#include' : must be followed by a header name
|
|||||||
ERROR: 0:8001: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
ERROR: 0:8001: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
||||||
ERROR: 0:8001: '#include' : must be followed by a header name
|
ERROR: 0:8001: '#include' : must be followed by a header name
|
||||||
ERROR: 0:8002: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
ERROR: 0:8002: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
||||||
ERROR: 0:8002: '#include' : unexpected include directive for header name: foo
|
ERROR: 0:8002: '#include' : Could not process include directive for header name: foo
|
||||||
ERROR: 0:8003: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
ERROR: 0:8003: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
||||||
ERROR: 0:8003: '#include' : extra content after header name: foo
|
ERROR: 0:8003: '#include' : extra content after header name: foo
|
||||||
ERROR: 0:8004: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
ERROR: 0:8004: '#include' : required extension not requested: GL_GOOGLE_include_directive
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
ERROR: 0:8000: '#include' : must be followed by a header name
|
ERROR: 0:8000: '#include' : must be followed by a header name
|
||||||
ERROR: 0:8001: '#include' : must be followed by a header name
|
ERROR: 0:8001: '#include' : must be followed by a header name
|
||||||
ERROR: 0:8002: '#include' : unexpected include directive for header name: foo.oeu
|
ERROR: 0:8002: '#include' : Could not process include directive for header name: foo.oeu
|
||||||
ERROR: 0:8003: '#include' : unexpected include directive for header name: foo.oeu/ao eu/ao.h
|
ERROR: 0:8003: '#include' : Could not process include directive for header name: foo.oeu/ao eu/ao.h
|
||||||
ERROR: 0:8004: '#include' : unexpected include directive for header name: foo<oeu
|
ERROR: 0:8004: '#include' : Could not process include directive for header name: foo<oeu
|
||||||
ERROR: 0:8005: '#include' : unexpected include directive for header name: foo.oe>
|
ERROR: 0:8005: '#include' : Could not process include directive for header name: foo.oe>
|
||||||
ERROR: 0:8006: '#include' : unexpected include directive for header name: foo.oe
|
ERROR: 0:8006: '#include' : Could not process include directive for header name: foo.oe
|
||||||
ERROR: 0:8007: '#include' : unexpected include directive for header name: foo"bar"
|
ERROR: 0:8007: '#include' : Could not process include directive for header name: foo"bar"
|
||||||
ERROR: 0:8008: '#include' : unexpected include directive for header name: foo\bar
|
ERROR: 0:8008: '#include' : Could not process include directive for header name: foo\bar
|
||||||
ERROR: 0:8009: '#include' : unexpected include directive for header name: foo.oe>
|
ERROR: 0:8009: '#include' : Could not process include directive for header name: foo.oe>
|
||||||
ERROR: 0:8010: '#include' : unexpected include directive for header name: foo
|
ERROR: 0:8010: '#include' : Could not process include directive for header name: foo
|
||||||
ERROR: 0:8011: '#include' : extra content after header name: foo2.h
|
ERROR: 0:8011: '#include' : extra content after header name: foo2.h
|
||||||
ERROR: 0:8012: '#include' : extra content after header name: foo.h
|
ERROR: 0:8012: '#include' : extra content after header name: foo.h
|
||||||
ERROR: 0:8014: '#include' : unexpected include directive for header name: ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789
|
ERROR: 0:8014: '#include' : Could not process include directive for header name: ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789
|
||||||
ERROR: 0:8016: '' : header name too long
|
ERROR: 0:8016: '' : header name too long
|
||||||
ERROR: 0:8016: '#include' : unexpected include directive for header name: ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789
|
ERROR: 0:8016: '#include' : Could not process include directive for header name: ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789
|
||||||
ERROR: 0:8017: '#include' : expected newline after header name: no-eol
|
ERROR: 0:8017: '#include' : expected newline after header name: no-eol
|
||||||
ERROR: 17 compilation errors. No code generated.
|
ERROR: 17 compilation errors. No code generated.
|
||||||
|
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
// For the version, it uses the latest git tag followed by the number of commits.
|
// For the version, it uses the latest git tag followed by the number of commits.
|
||||||
// For the date, it uses the current date (when then script is run).
|
// For the date, it uses the current date (when then script is run).
|
||||||
|
|
||||||
#define GLSLANG_REVISION "Overload400-PrecQual.1747"
|
#define GLSLANG_REVISION "Overload400-PrecQual.1750"
|
||||||
#define GLSLANG_DATE "06-Jan-2017"
|
#define GLSLANG_DATE "06-Jan-2017"
|
||||||
|
@ -232,7 +232,7 @@ bool InitializeSymbolTable(const TString& builtIns, int version, EProfile profil
|
|||||||
language, infoSink, spvVersion, true, EShMsgDefault,
|
language, infoSink, spvVersion, true, EShMsgDefault,
|
||||||
true));
|
true));
|
||||||
|
|
||||||
TShader::ForbidInclude includer;
|
TShader::ForbidIncluder includer;
|
||||||
TPpContext ppContext(*parseContext, "", includer);
|
TPpContext ppContext(*parseContext, "", includer);
|
||||||
TScanContext scanContext(*parseContext);
|
TScanContext scanContext(*parseContext);
|
||||||
parseContext->setScanContext(&scanContext);
|
parseContext->setScanContext(&scanContext);
|
||||||
@ -1232,7 +1232,7 @@ int ShCompile(
|
|||||||
compiler->infoSink.debug.erase();
|
compiler->infoSink.debug.erase();
|
||||||
|
|
||||||
TIntermediate intermediate(compiler->getLanguage());
|
TIntermediate intermediate(compiler->getLanguage());
|
||||||
TShader::ForbidInclude includer;
|
TShader::ForbidIncluder includer;
|
||||||
bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr,
|
bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr,
|
||||||
"", optLevel, resources, defaultVersion, ENoProfile, false,
|
"", optLevel, resources, defaultVersion, ENoProfile, false,
|
||||||
forwardCompatible, messages, intermediate, includer);
|
forwardCompatible, messages, intermediate, includer);
|
||||||
|
@ -576,12 +576,12 @@ int TPpContext::CPPifdef(int defined, TPpToken* ppToken)
|
|||||||
int TPpContext::CPPinclude(TPpToken* ppToken)
|
int TPpContext::CPPinclude(TPpToken* ppToken)
|
||||||
{
|
{
|
||||||
const TSourceLoc directiveLoc = ppToken->loc;
|
const TSourceLoc directiveLoc = ppToken->loc;
|
||||||
TShader::Includer::IncludeType includeType = TShader::Includer::EIncludeRelative;
|
bool startWithLocalSearch = true; // to additionally include the extra "" paths
|
||||||
int token = scanToken(ppToken);
|
int token = scanToken(ppToken);
|
||||||
|
|
||||||
// handle <header-name>-style #include
|
// handle <header-name>-style #include
|
||||||
if (token == '<') {
|
if (token == '<') {
|
||||||
includeType = TShader::Includer::EIncludeStandard;
|
startWithLocalSearch = false;
|
||||||
token = scanHeaderName(ppToken, '>');
|
token = scanHeaderName(ppToken, '>');
|
||||||
}
|
}
|
||||||
// otherwise ppToken already has the header name and it was "header-name" style
|
// otherwise ppToken already has the header name and it was "header-name" style
|
||||||
@ -605,16 +605,26 @@ int TPpContext::CPPinclude(TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process well-formed directive
|
// Process well-formed directive
|
||||||
TShader::Includer::IncludeResult* res = includer.include(filename.c_str(), includeType, currentSourceFile.c_str(),
|
|
||||||
includeStack.size() + 1);
|
// Find the inclusion, first look in "Local" ("") paths, if requested,
|
||||||
if (res && !res->file_name.empty()) {
|
// otherwise, only search the "System" (<>) paths.
|
||||||
if (res->file_data && res->file_length) {
|
TShader::Includer::IncludeResult* res = nullptr;
|
||||||
|
if (startWithLocalSearch)
|
||||||
|
res = includer.includeLocal(filename.c_str(), currentSourceFile.c_str(), includeStack.size() + 1);
|
||||||
|
if (! res || res->headerName.empty()) {
|
||||||
|
includer.releaseInclude(res);
|
||||||
|
res = includer.includeSystem(filename.c_str(), currentSourceFile.c_str(), includeStack.size() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the results
|
||||||
|
if (res && !res->headerName.empty()) {
|
||||||
|
if (res->headerData && res->headerLength) {
|
||||||
// path for processing one or more tokens from an included header, hand off 'res'
|
// path for processing one or more tokens from an included header, hand off 'res'
|
||||||
const bool forNextLine = parseContext.lineDirectiveShouldSetNextLine();
|
const bool forNextLine = parseContext.lineDirectiveShouldSetNextLine();
|
||||||
std::ostringstream prologue;
|
std::ostringstream prologue;
|
||||||
std::ostringstream epilogue;
|
std::ostringstream epilogue;
|
||||||
prologue << "#line " << forNextLine << " " << "\"" << res->file_name << "\"\n";
|
prologue << "#line " << forNextLine << " " << "\"" << res->headerName << "\"\n";
|
||||||
epilogue << (res->file_data[res->file_length - 1] == '\n'? "" : "\n") <<
|
epilogue << (res->headerData[res->headerLength - 1] == '\n'? "" : "\n") <<
|
||||||
"#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
|
"#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
|
||||||
pushInput(new TokenizableIncludeFile(directiveLoc, prologue.str(), res, epilogue.str(), this));
|
pushInput(new TokenizableIncludeFile(directiveLoc, prologue.str(), res, epilogue.str(), this));
|
||||||
// There's no "current" location anymore.
|
// There's no "current" location anymore.
|
||||||
@ -626,7 +636,7 @@ int TPpContext::CPPinclude(TPpToken* ppToken)
|
|||||||
} else {
|
} else {
|
||||||
// error path, clean up
|
// error path, clean up
|
||||||
std::string message =
|
std::string message =
|
||||||
res ? std::string(res->file_data, res->file_length)
|
res ? std::string(res->headerData, res->headerLength)
|
||||||
: std::string("Could not process include directive");
|
: std::string("Could not process include directive");
|
||||||
parseContext.ppError(directiveLoc, message.c_str(), "#include", "for header name: %s", filename.c_str());
|
parseContext.ppError(directiveLoc, message.c_str(), "#include", "for header name: %s", filename.c_str());
|
||||||
includer.releaseInclude(res);
|
includer.releaseInclude(res);
|
||||||
|
@ -507,11 +507,11 @@ protected:
|
|||||||
stringInput(pp, scanner)
|
stringInput(pp, scanner)
|
||||||
{
|
{
|
||||||
strings[0] = prologue_.data();
|
strings[0] = prologue_.data();
|
||||||
strings[1] = includedFile_->file_data;
|
strings[1] = includedFile_->headerData;
|
||||||
strings[2] = epilogue_.data();
|
strings[2] = epilogue_.data();
|
||||||
|
|
||||||
lengths[0] = prologue_.size();
|
lengths[0] = prologue_.size();
|
||||||
lengths[1] = includedFile_->file_length;
|
lengths[1] = includedFile_->headerLength;
|
||||||
lengths[2] = epilogue_.size();
|
lengths[2] = epilogue_.size();
|
||||||
|
|
||||||
scanner.setLine(startLoc.line);
|
scanner.setLine(startLoc.line);
|
||||||
@ -552,7 +552,7 @@ protected:
|
|||||||
// Points to the IncludeResult that this TokenizableIncludeFile represents.
|
// Points to the IncludeResult that this TokenizableIncludeFile represents.
|
||||||
TShader::Includer::IncludeResult* includedFile_;
|
TShader::Includer::IncludeResult* includedFile_;
|
||||||
|
|
||||||
// Will point to prologue_, includedFile_->file_data and epilogue_
|
// Will point to prologue_, includedFile_->headerData and epilogue_
|
||||||
// This is passed to scanner constructor.
|
// This is passed to scanner constructor.
|
||||||
// These do not own the storage and it must remain valid until this
|
// These do not own the storage and it must remain valid until this
|
||||||
// object has been destroyed.
|
// object has been destroyed.
|
||||||
@ -576,7 +576,7 @@ protected:
|
|||||||
|
|
||||||
void push_include(TShader::Includer::IncludeResult* result)
|
void push_include(TShader::Includer::IncludeResult* result)
|
||||||
{
|
{
|
||||||
currentSourceFile = result->file_name;
|
currentSourceFile = result->headerName;
|
||||||
includeStack.push(result);
|
includeStack.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,7 +588,7 @@ protected:
|
|||||||
if (includeStack.empty()) {
|
if (includeStack.empty()) {
|
||||||
currentSourceFile = rootFileName;
|
currentSourceFile = rootFileName;
|
||||||
} else {
|
} else {
|
||||||
currentSourceFile = includeStack.top()->file_name;
|
currentSourceFile = includeStack.top()->headerName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,72 +331,76 @@ public:
|
|||||||
// release the IncludeResult object.
|
// release the IncludeResult object.
|
||||||
class Includer {
|
class Includer {
|
||||||
public:
|
public:
|
||||||
typedef enum {
|
|
||||||
EIncludeRelative, // For #include "something"
|
|
||||||
EIncludeStandard // Reserved. For #include <something>
|
|
||||||
} IncludeType;
|
|
||||||
|
|
||||||
// An IncludeResult contains the resolved name and content of a source
|
// An IncludeResult contains the resolved name and content of a source
|
||||||
// inclusion.
|
// inclusion.
|
||||||
struct IncludeResult {
|
struct IncludeResult {
|
||||||
IncludeResult(const std::string& file_name, const char* const file_data, const size_t file_length, void* user_data) :
|
IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
|
||||||
file_name(file_name), file_data(file_data), file_length(file_length), user_data(user_data) { }
|
headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
|
||||||
// For a successful inclusion, the fully resolved name of the requested
|
// For a successful inclusion, the fully resolved name of the requested
|
||||||
// include. For example, in a file system-based includer, full resolution
|
// include. For example, in a file system-based includer, full resolution
|
||||||
// should convert a relative path name into an absolute path name.
|
// should convert a relative path name into an absolute path name.
|
||||||
// For a failed inclusion, this is an empty string.
|
// For a failed inclusion, this is an empty string.
|
||||||
const std::string file_name;
|
const std::string headerName;
|
||||||
// The content and byte length of the requested inclusion. The
|
// The content and byte length of the requested inclusion. The
|
||||||
// Includer producing this IncludeResult retains ownership of the
|
// Includer producing this IncludeResult retains ownership of the
|
||||||
// storage.
|
// storage.
|
||||||
// For a failed inclusion, the file_data
|
// For a failed inclusion, the header
|
||||||
// field points to a string containing error details.
|
// field points to a string containing error details.
|
||||||
const char* const file_data;
|
const char* const headerData;
|
||||||
const size_t file_length;
|
const size_t headerLength;
|
||||||
// Include resolver's context.
|
// Include resolver's context.
|
||||||
void* user_data;
|
void* userData;
|
||||||
protected:
|
protected:
|
||||||
IncludeResult& operator=(const IncludeResult&);
|
IncludeResult& operator=(const IncludeResult&);
|
||||||
IncludeResult();
|
IncludeResult();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Resolves an inclusion request by name, type, current source name,
|
// For both include methods below:
|
||||||
|
//
|
||||||
|
// Resolves an inclusion request by name, current source name,
|
||||||
// and include depth.
|
// and include depth.
|
||||||
// On success, returns an IncludeResult containing the resolved name
|
// On success, returns an IncludeResult containing the resolved name
|
||||||
// and content of the include. On failure, returns an IncludeResult
|
// and content of the include.
|
||||||
// with an empty string for the file_name and error details in the
|
// On failure, returns a nullptr, or an IncludeResult
|
||||||
// file_data field. The Includer retains ownership of the contents
|
// with an empty string for the headerName and error details in the
|
||||||
|
// header field.
|
||||||
|
// The Includer retains ownership of the contents
|
||||||
// of the returned IncludeResult value, and those contents must
|
// of the returned IncludeResult value, and those contents must
|
||||||
// remain valid until the releaseInclude method is called on that
|
// remain valid until the releaseInclude method is called on that
|
||||||
// IncludeResult object.
|
// IncludeResult object.
|
||||||
virtual IncludeResult* include(const char* requested_source,
|
//
|
||||||
IncludeType type,
|
// Note "local" vs. "system" is not an "either/or": "local" is an
|
||||||
const char* requesting_source,
|
// extra thing to do over "system". Both might get called, as per
|
||||||
size_t inclusion_depth) = 0;
|
// the C++ specification.
|
||||||
|
|
||||||
|
// For the "system" or <>-style includes; search the "system" paths.
|
||||||
|
virtual IncludeResult* includeSystem(const char* headerName,
|
||||||
|
const char* includerName,
|
||||||
|
size_t inclusionDepth) { return nullptr; }
|
||||||
|
|
||||||
|
// For the "local"-only aspect of a "" include. Should not search in the
|
||||||
|
// "system" paths, because on returning a failure, the parser will
|
||||||
|
// call includeSystem() to look in the "system" locations.
|
||||||
|
virtual IncludeResult* includeLocal(const char* headerName,
|
||||||
|
const char* includerName,
|
||||||
|
size_t inclusionDepth) { return nullptr; }
|
||||||
|
|
||||||
// Signals that the parser will no longer use the contents of the
|
// Signals that the parser will no longer use the contents of the
|
||||||
// specified IncludeResult.
|
// specified IncludeResult.
|
||||||
virtual void releaseInclude(IncludeResult* result) = 0;
|
virtual void releaseInclude(IncludeResult*) = 0;
|
||||||
virtual ~Includer() {}
|
virtual ~Includer() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns an error message for any #include directive.
|
// Fail all Includer searches
|
||||||
class ForbidInclude : public Includer {
|
class ForbidIncluder : public Includer {
|
||||||
public:
|
public:
|
||||||
IncludeResult* include(const char*, IncludeType, const char*, size_t) override
|
virtual void releaseInclude(IncludeResult*) override { }
|
||||||
{
|
|
||||||
const char* unexpected_include = "unexpected include directive";
|
|
||||||
return new IncludeResult(std::string(""), unexpected_include, strlen(unexpected_include), nullptr);
|
|
||||||
}
|
|
||||||
virtual void releaseInclude(IncludeResult* result) override
|
|
||||||
{
|
|
||||||
delete result;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||||
bool forwardCompatible, EShMessages messages)
|
bool forwardCompatible, EShMessages messages)
|
||||||
{
|
{
|
||||||
TShader::ForbidInclude includer;
|
TShader::ForbidIncluder includer;
|
||||||
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
|
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ public:
|
|||||||
glslang::TShader shader(EShLangVertex);
|
glslang::TShader shader(EShLangVertex);
|
||||||
shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
|
shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
|
||||||
std::string ppShader;
|
std::string ppShader;
|
||||||
glslang::TShader::ForbidInclude includer;
|
glslang::TShader::ForbidIncluder includer;
|
||||||
const bool success = shader.preprocess(
|
const bool success = shader.preprocess(
|
||||||
&glslang::DefaultTBuiltInResource, defaultVersion, defaultProfile,
|
&glslang::DefaultTBuiltInResource, defaultVersion, defaultProfile,
|
||||||
forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),
|
forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user