Commit 06e24a7e by Geoff Lang

Track if a non-preprocessor token has been seen and validate #extension with it.

Reland: Only report a warning instead of an error. BUG=angleproject:989 BUG=483252 Change-Id: Ife3e7759cdef6bc0f41cae3c58c307682b608279 Reviewed-on: https://chromium-review.googlesource.com/269404Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 5adf8182
......@@ -123,6 +123,8 @@ std::string Diagnostics::message(ID id)
return "unexpected token after conditional expression";
case PP_UNRECOGNIZED_PRAGMA:
return "unrecognized pragma";
case PP_NON_PP_TOKEN_BEFORE_EXTENSION:
return "extension directive must occur before any non-preprocessor tokens";
// Warnings end.
default:
assert(false);
......
......@@ -70,6 +70,7 @@ class Diagnostics
PP_WARNING_BEGIN,
PP_EOF_IN_DIRECTIVE,
PP_UNRECOGNIZED_PRAGMA,
PP_NON_PP_TOKEN_BEFORE_EXTENSION,
PP_WARNING_END
};
......
......@@ -211,6 +211,7 @@ DirectiveParser::DirectiveParser(Tokenizer *tokenizer,
Diagnostics *diagnostics,
DirectiveHandler *directiveHandler)
: mPastFirstStatement(false),
mSeenNonPreprocessorToken(false),
mTokenizer(tokenizer),
mMacroSet(macroSet),
mDiagnostics(diagnostics),
......@@ -229,6 +230,10 @@ void DirectiveParser::lex(Token *token)
parseDirective(token);
mPastFirstStatement = true;
}
else if (!isEOD(token))
{
mSeenNonPreprocessorToken = true;
}
if (token->type == Token::LAST)
{
......@@ -715,6 +720,11 @@ void DirectiveParser::parseExtension(Token *token)
token->location, token->text);
valid = false;
}
if (valid && mSeenNonPreprocessorToken)
{
mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION,
token->location, token->text);
}
if (valid)
mDirectiveHandler->handleExtension(token->location, name, behavior);
}
......
......@@ -70,6 +70,8 @@ class DirectiveParser : public Lexer
}
};
bool mPastFirstStatement;
bool mSeenNonPreprocessorToken; // Tracks if a non-preprocessor token has been seen yet. Some macros, such as
// #extension must be declared before all shader code.
std::vector<ConditionalBlock> mConditionalStack;
Tokenizer *mTokenizer;
MacroSet *mMacroSet;
......
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