Add pragma errors for malformed pragmas.

Instead of always warning on invalid pragmas, only warn when the pragma
type is not recognized and error when the syntax is invalid.

Fixes:
dEQP-GLES2.functional.shaders.preprocessor.pragmas.invalid_pragma_invalid_debug_vertex
dEQP-GLES2.functional.shaders.preprocessor.pragmas.invalid_pragma_invalid_debug_fragment
dEQP-GLES2.functional.shaders.preprocessor.pragmas.invalid_pragma_invalid_token_vertex
dEQP-GLES2.functional.shaders.preprocessor.pragmas.invalid_pragma_invalid_token_fragment

BUG=angleproject:989

Change-Id: Ibd584dc08a2436e163dfc52eeffdf2dac8a22cb8
Reviewed-on: https://chromium-review.googlesource.com/267639
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/preprocessor/DiagnosticsBase.cpp b/src/compiler/preprocessor/DiagnosticsBase.cpp
index cf60bc2..6868e1f 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.cpp
+++ b/src/compiler/preprocessor/DiagnosticsBase.cpp
@@ -109,6 +109,10 @@
         return "invalid file number";
       case PP_INVALID_LINE_DIRECTIVE:
         return "invalid line directive";
+      case PP_INVALID_PRAGMA:
+        return "invalid pragma";
+      case PP_INVALID_PRAGMA_VALUE:
+        return "invalid pragma value, must be 'on' or 'off'";
       // Errors end.
       // Warnings begin.
       case PP_EOF_IN_DIRECTIVE:
diff --git a/src/compiler/preprocessor/DiagnosticsBase.h b/src/compiler/preprocessor/DiagnosticsBase.h
index 5922d03..e67fbff 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.h
+++ b/src/compiler/preprocessor/DiagnosticsBase.h
@@ -61,6 +61,8 @@
         PP_INVALID_LINE_NUMBER,
         PP_INVALID_FILE_NUMBER,
         PP_INVALID_LINE_DIRECTIVE,
+        PP_INVALID_PRAGMA,
+        PP_INVALID_PRAGMA_VALUE,
         PP_ERROR_END,
 
         PP_WARNING_BEGIN,
diff --git a/src/compiler/preprocessor/DirectiveParser.cpp b/src/compiler/preprocessor/DirectiveParser.cpp
index 55ff3f6..62fe6ab 100644
--- a/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/src/compiler/preprocessor/DirectiveParser.cpp
@@ -616,7 +616,8 @@
             break;
           case PRAGMA_VALUE:
             value = token->text;
-            valid = valid && (token->type == Token::IDENTIFIER);
+            // Pragma value validation is handled in DirectiveHandler::handlePragma
+            // because the proper pragma value is dependent on the pragma name.
             break;
           case RIGHT_PAREN:
             valid = valid && (token->type == ')');
@@ -633,7 +634,7 @@
                       (state == RIGHT_PAREN + 1));  // With value.
     if (!valid)
     {
-        mDiagnostics->report(Diagnostics::PP_UNRECOGNIZED_PRAGMA,
+        mDiagnostics->report(Diagnostics::PP_INVALID_PRAGMA,
                              token->location, name);
     }
     else if (state > PRAGMA_NAME)  // Do not notify for empty pragma.
diff --git a/src/compiler/translator/DirectiveHandler.cpp b/src/compiler/translator/DirectiveHandler.cpp
index 084c22d..5bdecd5 100644
--- a/src/compiler/translator/DirectiveHandler.cpp
+++ b/src/compiler/translator/DirectiveHandler.cpp
@@ -98,9 +98,8 @@
 
         if (invalidValue)
         {
-            mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
-                                   "invalid pragma value", value,
-                                   "'on' or 'off' expected");
+            mDiagnostics.report(pp::Diagnostics::PP_INVALID_PRAGMA_VALUE, loc, value);
+            return;
         }
     }
 }
diff --git a/src/tests/preprocessor_tests/pragma_test.cpp b/src/tests/preprocessor_tests/pragma_test.cpp
index 25db7c7..39acc38 100644
--- a/src/tests/preprocessor_tests/pragma_test.cpp
+++ b/src/tests/preprocessor_tests/pragma_test.cpp
@@ -137,9 +137,9 @@
     using testing::_;
     // No handlePragma calls.
     EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, false)).Times(0);
-    // Unrecognized pragma warning.
+    // Invalid pragma error.
     EXPECT_CALL(mDiagnostics,
-                print(pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA,
+                print(pp::Diagnostics::PP_INVALID_PRAGMA,
                       pp::SourceLocation(0, 1), _));
 
     preprocess(str, expected);