PP: Non-functional: clean up, simplify, completely identical operation.

This commit is contained in:
John Kessenich 2016-12-20 11:10:09 -07:00
parent 3c264ce8f3
commit 1fbb9c1430
10 changed files with 63 additions and 90 deletions

View file

@ -868,7 +868,7 @@ struct DoPreprocessing {
// This is a list of tokens that do not require a space before or after.
static const std::string unNeededSpaceTokens = ";()[]";
static const std::string noSpaceBeforeTokens = ",";
glslang::TPpToken token;
glslang::TPpToken ppToken;
parseContext.setScanner(&input);
ppContext.setInput(input, versionWillBeError);
@ -931,27 +931,27 @@ struct DoPreprocessing {
});
int lastToken = EndOfInput; // lastToken records the last token processed.
while (const char* tok = ppContext.tokenize(&token)) {
while (const char* tok = ppContext.tokenize(ppToken)) {
bool isNewString = lineSync.syncToMostRecentString();
bool isNewLine = lineSync.syncToLine(token.loc.line);
bool isNewLine = lineSync.syncToLine(ppToken.loc.line);
if (isNewLine) {
// Don't emit whitespace onto empty lines.
// Copy any whitespace characters at the start of a line
// from the input to the output.
outputStream << std::string(token.loc.column - 1, ' ');
outputStream << std::string(ppToken.loc.column - 1, ' ');
}
// Output a space in between tokens, but not at the start of a line,
// and also not around special tokens. This helps with readability
// and consistency.
if (!isNewString && !isNewLine && lastToken != EndOfInput &&
(unNeededSpaceTokens.find((char)token.token) == std::string::npos) &&
(unNeededSpaceTokens.find((char)ppToken.token) == std::string::npos) &&
(unNeededSpaceTokens.find((char)lastToken) == std::string::npos) &&
(noSpaceBeforeTokens.find((char)token.token) == std::string::npos)) {
(noSpaceBeforeTokens.find((char)ppToken.token) == std::string::npos)) {
outputStream << " ";
}
lastToken = token.token;
lastToken = ppToken.token;
outputStream << tok;
}
outputStream << std::endl;