Commit 942e3625 by Geoff Lang

Don't mark all macros with double underscores as reserved.

Only __FILE__, __LINE__, __VERSION__ and GL_ES are reserved but it is still not recommended to use a name with double underscores because it may be used by the "underlying software layers". Updated the tests to reflect that it is OK to define macros with double underscores but it is not valid to make assumptions about their values. Fixes: dEQP-GLES2.functional.shaders.preprocessor.basic.identifier_with_double_underscore_vertex dEQP-GLES2.functional.shaders.preprocessor.basic.identifier_with_double_underscore_fragment BUG=angleproject:898 Change-Id: I77054d04c9935eedcdbb7304dc0c3b60b53994f9 Reviewed-on: https://chromium-review.googlesource.com/268434Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 2dc8bf8b
...@@ -118,13 +118,28 @@ void skipUntilEOD(pp::Lexer *lexer, pp::Token *token) ...@@ -118,13 +118,28 @@ void skipUntilEOD(pp::Lexer *lexer, pp::Token *token)
bool isMacroNameReserved(const std::string &name) bool isMacroNameReserved(const std::string &name)
{ {
// Names prefixed with "GL_" are reserved. const char *kPredefinedMacros[] =
if (name.substr(0, 3) == "GL_") {
return true; "__LINE__",
"__FILE__",
"__VERSION__",
"GL_ES",
};
const size_t kPredefinedMacrosCount = sizeof(kPredefinedMacros) / sizeof(*kPredefinedMacros);
for (size_t i = 0; i < kPredefinedMacrosCount; i++)
{
if (name == kPredefinedMacros[i])
{
return true;
}
}
// Names containing two consecutive underscores are reserved. // Names prefixed with "GL_" are reserved.
if (name.find("__") != std::string::npos) if (name.compare(0, 3, "GL_") == 0)
{
return true; return true;
}
return false; return false;
} }
......
...@@ -65,32 +65,24 @@ TEST_F(DefineTest, RedefinePredefined) ...@@ -65,32 +65,24 @@ TEST_F(DefineTest, RedefinePredefined)
preprocess(input, expected); preprocess(input, expected);
} }
TEST_F(DefineTest, ReservedUnderScore1) TEST_F(DefineTest, UnderScore1)
{ {
const char* input = "#define __foo bar\n" const char* input = "#define __foo bar\n";
"__foo\n"; const char* expected = "\n";
const char* expected = "\n"
"__foo\n";
EXPECT_CALL(mDiagnostics, using testing::_;
print(pp::Diagnostics::PP_MACRO_NAME_RESERVED, EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
pp::SourceLocation(0, 1),
"__foo"));
preprocess(input, expected); preprocess(input, expected);
} }
TEST_F(DefineTest, ReservedUnderScore2) TEST_F(DefineTest, UnderScore2)
{ {
const char* input = "#define foo__bar baz\n" const char* input = "#define foo__bar baz\n";
"foo__bar\n"; const char* expected = "\n";
const char* expected = "\n"
"foo__bar\n";
EXPECT_CALL(mDiagnostics, using testing::_;
print(pp::Diagnostics::PP_MACRO_NAME_RESERVED, EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
pp::SourceLocation(0, 1),
"foo__bar"));
preprocess(input, expected); preprocess(input, expected);
} }
......
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