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/DiagnosticsBase.cpp b/src/compiler/preprocessor/DiagnosticsBase.cpp
index b254a97..68c6e9c 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.cpp
+++ b/src/compiler/preprocessor/DiagnosticsBase.cpp
@@ -125,6 +125,8 @@
         return "unrecognized pragma";
       case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
         return "extension directive should occur before any non-preprocessor tokens";
+      case PP_WARNING_MACRO_NAME_RESERVED:
+        return "macro name with a double underscore is reserved - unintented behavior is possible";
       // Warnings end.
       default:
         assert(false);
diff --git a/src/compiler/preprocessor/DiagnosticsBase.h b/src/compiler/preprocessor/DiagnosticsBase.h
index f478b86..d26c174 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.h
+++ b/src/compiler/preprocessor/DiagnosticsBase.h
@@ -71,6 +71,7 @@
         PP_EOF_IN_DIRECTIVE,
         PP_UNRECOGNIZED_PRAGMA,
         PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
+        PP_WARNING_MACRO_NAME_RESERVED,
         PP_WARNING_END
     };
 
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;