Commit b3a6a8f3 by Geoff Lang

Error when encountering non-preprocessor tokens before #extension in ESSL3.

BUG=angleproject:1047 Change-Id: I4a548270f651e35b2c8d1ab5d0f46185230c5f74 Reviewed-on: https://chromium-review.googlesource.com/281216Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 87bef77c
...@@ -117,6 +117,8 @@ std::string Diagnostics::message(ID id) ...@@ -117,6 +117,8 @@ std::string Diagnostics::message(ID id)
return "invalid pragma"; return "invalid pragma";
case PP_INVALID_PRAGMA_VALUE: case PP_INVALID_PRAGMA_VALUE:
return "invalid pragma value, must be 'on' or 'off'"; return "invalid pragma value, must be 'on' or 'off'";
case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3:
return "extension directive must occur before any non-preprocessor tokens in ESSL3";
// Errors end. // Errors end.
// Warnings begin. // Warnings begin.
case PP_EOF_IN_DIRECTIVE: case PP_EOF_IN_DIRECTIVE:
...@@ -125,8 +127,8 @@ std::string Diagnostics::message(ID id) ...@@ -125,8 +127,8 @@ std::string Diagnostics::message(ID id)
return "unexpected token after conditional expression"; return "unexpected token after conditional expression";
case PP_UNRECOGNIZED_PRAGMA: case PP_UNRECOGNIZED_PRAGMA:
return "unrecognized pragma"; return "unrecognized pragma";
case PP_NON_PP_TOKEN_BEFORE_EXTENSION: case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
return "extension directive must occur before any non-preprocessor tokens"; return "extension directive should occur before any non-preprocessor tokens";
// Warnings end. // Warnings end.
default: default:
assert(false); assert(false);
......
...@@ -66,12 +66,13 @@ class Diagnostics ...@@ -66,12 +66,13 @@ class Diagnostics
PP_INVALID_LINE_DIRECTIVE, PP_INVALID_LINE_DIRECTIVE,
PP_INVALID_PRAGMA, PP_INVALID_PRAGMA,
PP_INVALID_PRAGMA_VALUE, PP_INVALID_PRAGMA_VALUE,
PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3,
PP_ERROR_END, PP_ERROR_END,
PP_WARNING_BEGIN, PP_WARNING_BEGIN,
PP_EOF_IN_DIRECTIVE, PP_EOF_IN_DIRECTIVE,
PP_UNRECOGNIZED_PRAGMA, PP_UNRECOGNIZED_PRAGMA,
PP_NON_PP_TOKEN_BEFORE_EXTENSION, PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
PP_WARNING_END PP_WARNING_END
}; };
......
...@@ -215,7 +215,8 @@ DirectiveParser::DirectiveParser(Tokenizer *tokenizer, ...@@ -215,7 +215,8 @@ DirectiveParser::DirectiveParser(Tokenizer *tokenizer,
mTokenizer(tokenizer), mTokenizer(tokenizer),
mMacroSet(macroSet), mMacroSet(macroSet),
mDiagnostics(diagnostics), mDiagnostics(diagnostics),
mDirectiveHandler(directiveHandler) mDirectiveHandler(directiveHandler),
mShaderVersion(100)
{ {
} }
...@@ -722,8 +723,17 @@ void DirectiveParser::parseExtension(Token *token) ...@@ -722,8 +723,17 @@ void DirectiveParser::parseExtension(Token *token)
} }
if (valid && mSeenNonPreprocessorToken) if (valid && mSeenNonPreprocessorToken)
{ {
mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION, if (mShaderVersion >= 300)
token->location, token->text); {
mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3,
token->location, token->text);
valid = false;
}
else
{
mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
token->location, token->text);
}
} }
if (valid) if (valid)
mDirectiveHandler->handleExtension(token->location, name, behavior); mDirectiveHandler->handleExtension(token->location, name, behavior);
...@@ -811,6 +821,7 @@ void DirectiveParser::parseVersion(Token *token) ...@@ -811,6 +821,7 @@ void DirectiveParser::parseVersion(Token *token)
if (valid) if (valid)
{ {
mDirectiveHandler->handleVersion(token->location, version); mDirectiveHandler->handleVersion(token->location, version);
mShaderVersion = version;
} }
} }
......
...@@ -77,6 +77,7 @@ class DirectiveParser : public Lexer ...@@ -77,6 +77,7 @@ class DirectiveParser : public Lexer
MacroSet *mMacroSet; MacroSet *mMacroSet;
Diagnostics *mDiagnostics; Diagnostics *mDiagnostics;
DirectiveHandler *mDirectiveHandler; DirectiveHandler *mDirectiveHandler;
int mShaderVersion;
}; };
} // namespace pp } // namespace pp
......
...@@ -66,6 +66,39 @@ TEST_F(ExtensionTest, MissingNewline) ...@@ -66,6 +66,39 @@ TEST_F(ExtensionTest, MissingNewline)
preprocess(str, expected); preprocess(str, expected);
} }
TEST_F(ExtensionTest, ExtensionAfterNonPreProcessorTokenESSL1)
{
const char *str = "int baz = 1;\n"
"#extension foo : bar\n";
const char *expected = "int baz = 1;\n\n";
using testing::_;
// Directive successfully parsed.
EXPECT_CALL(mDirectiveHandler,
handleExtension(pp::SourceLocation(0, 2), "foo", "bar"));
// Expect a warning about extension pragmas after non-preprocessor tokens.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1, _, _));
preprocess(str, expected);
}
TEST_F(ExtensionTest, ExtensionAfterNonPreProcessorTokenESSL3)
{
const char *str = "#version 300 es\n"
"int baz = 1;\n"
"#extension foo : bar\n";
const char *expected = "\nint baz = 1;\n\n";
using testing::_;
// Directive successfully parsed.
EXPECT_CALL(mDirectiveHandler,
handleVersion(pp::SourceLocation(0, 1), 300));
// Expect a error about extension pragmas after non-preprocessor tokens.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3, _, _));
preprocess(str, expected);
}
struct ExtensionTestParam struct ExtensionTestParam
{ {
const char* str; const char* str;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment