mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-15 22:30:06 +00:00
PP: #include: simplify the different paths out of #include.
- some paths didn't release 'res' - token is always '\n' after proper acceptance of the directive itself, so no need to test it, change it to '\n', etc. - assuming setCurrentColumn(0) is not needed unless there are header tokens, but not clear why it is ever needed Note: much of the simplified code read as if the included header tokens had actually been processed, versus queued up for processing; maybe that explains some things.
This commit is contained in:
parent
28d3133581
commit
1b1defd605
@ -593,38 +593,43 @@ int TPpContext::CPPinclude(TPpToken* ppToken)
|
||||
|
||||
// Make a copy of the name because it will be overwritten by the next token scan.
|
||||
const std::string filename = ppToken->name;
|
||||
|
||||
// See if the directive was well formed
|
||||
token = scanToken(ppToken);
|
||||
if (token != '\n') {
|
||||
if (token == EndOfInput)
|
||||
parseContext.ppError(ppToken->loc, "expected newline after header name:", "#include", "%s", filename.c_str());
|
||||
else
|
||||
parseContext.ppError(ppToken->loc, "extra content after header name:", "#include", "%s", filename.c_str());
|
||||
} else {
|
||||
TShader::Includer::IncludeResult* res = includer.include(filename.c_str(), includeType, currentSourceFile.c_str(), includeStack.size() + 1);
|
||||
return token;
|
||||
}
|
||||
|
||||
// Process well-formed directive
|
||||
TShader::Includer::IncludeResult* res = includer.include(filename.c_str(), includeType, currentSourceFile.c_str(),
|
||||
includeStack.size() + 1);
|
||||
if (res && !res->file_name.empty()) {
|
||||
if (res->file_data && res->file_length) {
|
||||
// path for processing one or more tokens from an included header, hand off 'res'
|
||||
const bool forNextLine = parseContext.lineDirectiveShouldSetNextLine();
|
||||
std::ostringstream prologue;
|
||||
std::ostringstream epilogue;
|
||||
prologue << "#line " << forNextLine << " " << "\"" << res->file_name << "\"\n";
|
||||
epilogue << (res->file_data[res->file_length - 1] == '\n'? "" : "\n") << "#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
|
||||
epilogue << (res->file_data[res->file_length - 1] == '\n'? "" : "\n") <<
|
||||
"#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
|
||||
pushInput(new TokenizableIncludeFile(directiveLoc, prologue.str(), res, epilogue.str(), this));
|
||||
}
|
||||
// At EOF, there's no "current" location anymore.
|
||||
if (token != EndOfInput)
|
||||
parseContext.setCurrentColumn(0);
|
||||
// Don't accidentally return EndOfInput, which will end all preprocessing.
|
||||
return '\n';
|
||||
} else {
|
||||
// things are okay, but there is nothing to process
|
||||
includer.releaseInclude(res);
|
||||
}
|
||||
} else {
|
||||
// error path, clean up
|
||||
std::string message =
|
||||
res ? std::string(res->file_data, res->file_length)
|
||||
: std::string("Could not process include directive");
|
||||
parseContext.ppError(directiveLoc, message.c_str(), "#include", "for header name: %s", filename.c_str());
|
||||
if (res) {
|
||||
includer.releaseInclude(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user