Improve preprocessor ouput format
Modify preprocessor.simple.vert to test spaces before parenthesis.
This commit is contained in:
parent
4c57db1595
commit
2bfacdac91
@ -46,6 +46,8 @@ struct S {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void bar(int x) { }
|
||||||
|
|
||||||
void foo()
|
void foo()
|
||||||
{
|
{
|
||||||
S s;
|
S s;
|
||||||
@ -55,6 +57,9 @@ void foo()
|
|||||||
s.member2.yyz;
|
s.member2.yyz;
|
||||||
s.member2.xxyz();
|
s.member2.xxyz();
|
||||||
s.member2.yzy;
|
s.member2.yzy;
|
||||||
|
for (int i = 0; i < 100; i = i + 1) {
|
||||||
|
bar(i)
|
||||||
|
}
|
||||||
vec3 a = vec3(0); vec3 b = a.zxyz; vec3 b = a.xxyz; vec3 b = a.yyz; vec3 b = a.xxyz(); vec3 b = a.yzy; vec3 b = a.z;
|
vec3 a = vec3(0); vec3 b = a.zxyz; vec3 b = a.xxyz; vec3 b = a.yyz; vec3 b = a.xxyz(); vec3 b = a.yzy; vec3 b = a.z;
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ struct S {
|
|||||||
vec3 b = a.yzy; \
|
vec3 b = a.yzy; \
|
||||||
vec3 b = a.z;
|
vec3 b = a.z;
|
||||||
|
|
||||||
|
void bar(int x) {}
|
||||||
|
|
||||||
void foo()
|
void foo()
|
||||||
{
|
{
|
||||||
S s;
|
S s;
|
||||||
@ -55,6 +57,9 @@ void foo()
|
|||||||
s.member2.yzy();
|
s.member2.yzy();
|
||||||
s.member2.xyz();
|
s.member2.xyz();
|
||||||
s.member2.yzy;
|
s.member2.yzy;
|
||||||
|
for(int i = 0;i < 100; i = i + 1) {
|
||||||
|
bar (i)
|
||||||
|
}
|
||||||
FUN_MAC()
|
FUN_MAC()
|
||||||
yzy
|
yzy
|
||||||
|
|
||||||
|
@ -1068,8 +1068,8 @@ struct DoPreprocessing {
|
|||||||
EShOptimizationLevel, EShMessages)
|
EShOptimizationLevel, EShMessages)
|
||||||
{
|
{
|
||||||
// This is a list of tokens that do not require a space before or after.
|
// This is a list of tokens that do not require a space before or after.
|
||||||
static const std::string unNeededSpaceTokens = ";()[]";
|
static const std::string noNeededSpaceBeforeTokens = ";)[].,";
|
||||||
static const std::string noSpaceBeforeTokens = ",";
|
static const std::string noNeededSpaceAfterTokens = ".([";
|
||||||
glslang::TPpToken ppToken;
|
glslang::TPpToken ppToken;
|
||||||
|
|
||||||
parseContext.setScanner(&input);
|
parseContext.setScanner(&input);
|
||||||
@ -1142,6 +1142,7 @@ struct DoPreprocessing {
|
|||||||
});
|
});
|
||||||
|
|
||||||
int lastToken = EndOfInput; // lastToken records the last token processed.
|
int lastToken = EndOfInput; // lastToken records the last token processed.
|
||||||
|
std::string lastTokenName;
|
||||||
do {
|
do {
|
||||||
int token = ppContext.tokenize(ppToken);
|
int token = ppContext.tokenize(ppToken);
|
||||||
if (token == EndOfInput)
|
if (token == EndOfInput)
|
||||||
@ -1160,12 +1161,23 @@ struct DoPreprocessing {
|
|||||||
// Output a space in between tokens, but not at the start of a line,
|
// 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 also not around special tokens. This helps with readability
|
||||||
// and consistency.
|
// and consistency.
|
||||||
if (!isNewString && !isNewLine && lastToken != EndOfInput &&
|
if (!isNewString && !isNewLine && lastToken != EndOfInput) {
|
||||||
(unNeededSpaceTokens.find((char)token) == std::string::npos) &&
|
// left parenthesis need a leading space, except it is in a function-call-like context.
|
||||||
(unNeededSpaceTokens.find((char)lastToken) == std::string::npos) &&
|
// examples: `for (xxx)`, `a * (b + c)`, `vec(2.0)`, `foo(x, y, z)`
|
||||||
(noSpaceBeforeTokens.find((char)token) == std::string::npos)) {
|
if (token == '(') {
|
||||||
|
if (lastToken != PpAtomIdentifier ||
|
||||||
|
lastTokenName == "if" ||
|
||||||
|
lastTokenName == "for" ||
|
||||||
|
lastTokenName == "while" ||
|
||||||
|
lastTokenName == "switch")
|
||||||
|
outputBuffer += ' ';
|
||||||
|
} else if ((noNeededSpaceBeforeTokens.find((char)token) == std::string::npos) &&
|
||||||
|
(noNeededSpaceAfterTokens.find((char)lastToken) == std::string::npos)) {
|
||||||
outputBuffer += ' ';
|
outputBuffer += ' ';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (token == PpAtomIdentifier)
|
||||||
|
lastTokenName = ppToken.name;
|
||||||
lastToken = token;
|
lastToken = token;
|
||||||
if (token == PpAtomConstString)
|
if (token == PpAtomConstString)
|
||||||
outputBuffer += "\"";
|
outputBuffer += "\"";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user