Allow 'defined' in define in non-WebGL.

This is needed to pass dEQP conformance. Several of the harder dEQP
tests around this behaviour are excluded from the mustpass list. This
is presumably because the behaviours weren't implemented portably.
Nevertheless we need to support conformant behaviour for GLES 2.0
Contexts for the most simple uses.

This also leaves the error behaviour intact for WebGL specs.

Bug: angleproject:1335
Change-Id: Ia80b4f71475efa928488ee6c2ee35c566d4602d4
Reviewed-on: https://chromium-review.googlesource.com/c/1242013
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/preprocessor/DirectiveParser.cpp b/src/compiler/preprocessor/DirectiveParser.cpp
index 0731a41..739cbd4 100644
--- a/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/src/compiler/preprocessor/DirectiveParser.cpp
@@ -141,72 +141,11 @@
 
 namespace pp
 {
-
-class DefinedParser : public Lexer
-{
-  public:
-    DefinedParser(Lexer *lexer, const MacroSet *macroSet, Diagnostics *diagnostics)
-        : mLexer(lexer), mMacroSet(macroSet), mDiagnostics(diagnostics)
-    {
-    }
-
-  protected:
-    void lex(Token *token) override
-    {
-        const char kDefined[] = "defined";
-
-        mLexer->lex(token);
-        if (token->type != Token::IDENTIFIER)
-            return;
-        if (token->text != kDefined)
-            return;
-
-        bool paren = false;
-        mLexer->lex(token);
-        if (token->type == '(')
-        {
-            paren = true;
-            mLexer->lex(token);
-        }
-
-        if (token->type != Token::IDENTIFIER)
-        {
-            mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
-            skipUntilEOD(mLexer, token);
-            return;
-        }
-        MacroSet::const_iterator iter = mMacroSet->find(token->text);
-        std::string expression        = iter != mMacroSet->end() ? "1" : "0";
-
-        if (paren)
-        {
-            mLexer->lex(token);
-            if (token->type != ')')
-            {
-                mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location,
-                                     token->text);
-                skipUntilEOD(mLexer, token);
-                return;
-            }
-        }
-
-        // We have a valid defined operator.
-        // Convert the current token into a CONST_INT token.
-        token->type = Token::CONST_INT;
-        token->text = expression;
-    }
-
-  private:
-    Lexer *mLexer;
-    const MacroSet *mMacroSet;
-    Diagnostics *mDiagnostics;
-};
-
 DirectiveParser::DirectiveParser(Tokenizer *tokenizer,
                                  MacroSet *macroSet,
                                  Diagnostics *diagnostics,
                                  DirectiveHandler *directiveHandler,
-                                 int maxMacroExpansionDepth)
+                                 const PreprocessorSettings &settings)
     : mPastFirstStatement(false),
       mSeenNonPreprocessorToken(false),
       mTokenizer(tokenizer),
@@ -214,7 +153,7 @@
       mDiagnostics(diagnostics),
       mDirectiveHandler(directiveHandler),
       mShaderVersion(100),
-      mMaxMacroExpansionDepth(maxMacroExpansionDepth)
+      mSettings(settings)
 {
 }
 
@@ -843,7 +782,7 @@
     bool parsedFileNumber = false;
     int line = 0, file = 0;
 
-    MacroExpander macroExpander(mTokenizer, mMacroSet, mDiagnostics, mMaxMacroExpansionDepth);
+    MacroExpander macroExpander(mTokenizer, mMacroSet, mDiagnostics, mSettings, false);
 
     // Lex the first token after "#line" so we can check it for EOD.
     macroExpander.lex(token);
@@ -951,8 +890,7 @@
 {
     ASSERT((getDirective(token) == DIRECTIVE_IF) || (getDirective(token) == DIRECTIVE_ELIF));
 
-    DefinedParser definedParser(mTokenizer, mMacroSet, mDiagnostics);
-    MacroExpander macroExpander(&definedParser, mMacroSet, mDiagnostics, mMaxMacroExpansionDepth);
+    MacroExpander macroExpander(mTokenizer, mMacroSet, mDiagnostics, mSettings, true);
     ExpressionParser expressionParser(&macroExpander, mDiagnostics);
 
     int expression = 0;