PP: don't give errors on some tokens under #if 0 (or similar).

Fixes #1295.

Tokens that are accepted by any version of HLSL or GLSL should be
allowed when #ifdef'd off, such that errors are not reported.
This commit is contained in:
John Kessenich 2018-03-19 00:43:18 -06:00
parent 56e8056582
commit e7e081bda9
5 changed files with 71 additions and 31 deletions

View File

@ -0,0 +1,14 @@
cppRelaxSkipTokensErrors.vert
Shader version: 110
0:? Sequence
0:? Linker Objects
Linked vertex stage:
ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point
Shader version: 110
0:? Sequence
0:? Linker Objects

View File

@ -1,5 +1,5 @@
#define m#0# #define m#0#
#if m #if m
#endif
#define n() #define n()
int n" int n"

View File

@ -0,0 +1,14 @@
#version 110
#if 0
3.5L
3.5h
2034h
1.#INF
0x1234567812345L
12323394203923879234L
0123s;
123s;
0123456712345671234L
"string"
#endif

View File

@ -118,7 +118,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
ch = getChar(); ch = getChar();
// 1.#INF or -1.#INF // 1.#INF or -1.#INF
if (parseContext.intermediate.getSource() == EShSourceHlsl && ch == '#') { if (ch == '#' && (ifdepth > 0 || parseContext.intermediate.getSource() == EShSourceHlsl)) {
if ((len < 2) || if ((len < 2) ||
(len == 2 && ppToken->name[0] != '1') || (len == 2 && ppToken->name[0] != '1') ||
(len == 3 && ppToken->name[1] != '1' && !(ppToken->name[0] == '-' || ppToken->name[0] == '+')) || (len == 3 && ppToken->name[1] != '1' && !(ppToken->name[0] == '-' || ppToken->name[0] == '+')) ||
@ -174,9 +174,9 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
// Suffix: // Suffix:
bool isFloat16 = false; bool isFloat16 = false;
if (ch == 'l' || ch == 'L') { if (ch == 'l' || ch == 'L') {
if (parseContext.intermediate.getSource() == EShSourceGlsl) if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl)
parseContext.doubleCheck(ppToken->loc, "double floating-point suffix"); parseContext.doubleCheck(ppToken->loc, "double floating-point suffix");
if (! HasDecimalOrExponent) if (ifdepth == 0 && !HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (parseContext.intermediate.getSource() == EShSourceGlsl) { if (parseContext.intermediate.getSource() == EShSourceGlsl) {
int ch2 = getChar(); int ch2 = getChar();
@ -193,9 +193,9 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
isDouble = 1; isDouble = 1;
} }
} else if (ch == 'h' || ch == 'H') { } else if (ch == 'h' || ch == 'H') {
if (parseContext.intermediate.getSource() == EShSourceGlsl) if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl)
parseContext.float16Check(ppToken->loc, "half floating-point suffix"); parseContext.float16Check(ppToken->loc, "half floating-point suffix");
if (!HasDecimalOrExponent) if (ifdepth == 0 && !HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (parseContext.intermediate.getSource() == EShSourceGlsl) { if (parseContext.intermediate.getSource() == EShSourceGlsl) {
int ch2 = getChar(); int ch2 = getChar();
@ -212,10 +212,11 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
isFloat16 = true; isFloat16 = true;
} }
} else if (ch == 'f' || ch == 'F') { } else if (ch == 'f' || ch == 'F') {
parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix"); if (ifdepth == 0)
if (! parseContext.relaxedErrors()) parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix");
if (ifdepth == 0 && !parseContext.relaxedErrors())
parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix"); parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix");
if (! HasDecimalOrExponent) if (ifdepth == 0 && !HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
saveName(ch); saveName(ch);
} else } else
@ -483,18 +484,22 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
ppToken->name[len] = '\0'; ppToken->name[len] = '\0';
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit hexadecimal literal"); "64-bit hexadecimal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit hexadecimal literal"); Num_Int64_Extensions, Int64_Extensions, "64-bit hexadecimal literal");
}
ppToken->i64val = ival; ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) { } else if (isInt16) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
"16-bit hexadecimal literal"); pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, "16-bit hexadecimal literal");
Num_Int16_Extensions, Int16_Extensions, "16-bit hexadecimal literal"); pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit hexadecimal literal");
}
} }
ppToken->ival = (int)ival; ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16; return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
@ -595,18 +600,22 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
pp->parseContext.ppError(ppToken->loc, "octal literal too big", "", ""); pp->parseContext.ppError(ppToken->loc, "octal literal too big", "", "");
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit octal literal"); "64-bit octal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit octal literal"); Num_Int64_Extensions, Int64_Extensions, "64-bit octal literal");
}
ppToken->i64val = ival; ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) { } else if (isInt16) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
"16-bit octal literal"); pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, "16-bit octal literal");
Num_Int16_Extensions, Int16_Extensions, "16-bit octal literal"); pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit octal literal");
}
} }
ppToken->ival = (int)ival; ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16; return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
@ -700,16 +709,18 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
} }
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit literal"); "64-bit literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit literal"); Num_Int64_Extensions, Int64_Extensions, "64-bit literal");
}
ppToken->i64val = ival; ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) { } else if (isInt16) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { if (pp->ifdepth == 0 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"16-bit literal"); "16-bit literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit literal"); Num_Int16_Extensions, Int16_Extensions, "16-bit literal");
} }
@ -972,7 +983,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
continue; continue;
break; break;
case PpAtomConstString: case PpAtomConstString:
if (parseContext.intermediate.getSource() != EShSourceHlsl) { if (ifdepth == 0 && parseContext.intermediate.getSource() != EShSourceHlsl) {
// HLSL allows string literals. // HLSL allows string literals.
parseContext.ppError(ppToken.loc, "string literals not supported", "\"\"", ""); parseContext.ppError(ppToken.loc, "string literals not supported", "\"\"", "");
continue; continue;

View File

@ -99,6 +99,7 @@ INSTANTIATE_TEST_CASE_P(
"cppComplexExpr.vert", "cppComplexExpr.vert",
"cppDeepNest.frag", "cppDeepNest.frag",
"cppPassMacroName.frag", "cppPassMacroName.frag",
"cppRelaxSkipTokensErrors.vert",
"badChars.frag", "badChars.frag",
"pointCoord.frag", "pointCoord.frag",
"array.frag", "array.frag",