Allow double underscore in macro names

Double underscore is allowed according to GLSL ES 3.10, and based on
Khronos discussions the intent is that this should also apply to older
specs. The dEQP tests also check this, and WebGL tests that check the
opposite were recently removed. The error is changed into a warning.

BUG=angleproject:989
TEST=angle_unittests
     dEQP-GLES3.functional.shaders.preprocessor.* (2 tests start passing)
     dEQP-GLES2.functional.shaders.preprocessor.* (2 tests start passing)

Change-Id: I582c01b4adc8fc416354351e02b776f2cc602408
Reviewed-on: https://chromium-review.googlesource.com/300965
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/preprocessor/DirectiveParser.cpp b/src/compiler/preprocessor/DirectiveParser.cpp
index 203630a..2faa331 100644
--- a/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/src/compiler/preprocessor/DirectiveParser.cpp
@@ -119,14 +119,12 @@
 bool isMacroNameReserved(const std::string &name)
 {
     // Names prefixed with "GL_" are reserved.
-    if (name.substr(0, 3) == "GL_")
-        return true;
+    return (name.substr(0, 3) == "GL_");
+}
 
-    // Names containing two consecutive underscores are reserved.
-    if (name.find("__") != std::string::npos)
-        return true;
-
-    return false;
+bool hasDoubleUnderscores(const std::string &name)
+{
+    return (name.find("__") != std::string::npos);
 }
 
 bool isMacroPredefined(const std::string &name,
@@ -291,6 +289,16 @@
                              token->location, token->text);
         return;
     }
+    // Using double underscores is allowed, but may result in unintended
+    // behavior, so a warning is issued. At the time of writing this was
+    // specified in ESSL 3.10, but the intent judging from Khronos
+    // discussions and dEQP tests was that double underscores should be
+    // allowed in earlier ESSL versions too.
+    if (hasDoubleUnderscores(token->text))
+    {
+        mDiagnostics->report(Diagnostics::PP_WARNING_MACRO_NAME_RESERVED, token->location,
+                             token->text);
+    }
 
     Macro macro;
     macro.type = Macro::kTypeObj;