summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2013-04-03 19:57:09 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-08 11:35:44 +0200
commit710ad8ce1bd5d01ce048851d210ac3831ca17dde (patch)
treebb3f645e57a7887341113275c9caa2583f7e2dfa /src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp
parent8307ab784eb4d8d22441ee61f02cb381684ca3a2 (diff)
Upgrade ANGLE to DX11 Proto
Upgrades ANGLE to dx11proto (dx11-MRT-support tag), which splits out support for DirectX9 & DirectX11. The DX9 codepath is used by default; CONFIG+=angle_d3d11 must be passed to the ANGLE project to build for DX11. Existing patches to ANGLE have been updated (or removed if no longer needed), and a patch has been added to make DX9/DX11 codepaths mutually exclusive. Change-Id: Ibe13befadb94f04883eca449d0ee1f0da955ff92 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Axel Waggershauser <awagger@gmail.com>
Diffstat (limited to 'src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp')
-rw-r--r--src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp b/src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp
new file mode 100644
index 0000000000..5ffc6420bc
--- /dev/null
+++ b/src/3rdparty/angle/src/compiler/preprocessor/Preprocessor.cpp
@@ -0,0 +1,142 @@
+//
+// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+#include "Preprocessor.h"
+
+#include <cassert>
+#include <sstream>
+
+#include "DiagnosticsBase.h"
+#include "DirectiveParser.h"
+#include "Macro.h"
+#include "MacroExpander.h"
+#include "Token.h"
+#include "Tokenizer.h"
+
+namespace pp
+{
+
+struct PreprocessorImpl
+{
+ Diagnostics* diagnostics;
+ MacroSet macroSet;
+ Tokenizer tokenizer;
+ DirectiveParser directiveParser;
+ MacroExpander macroExpander;
+
+ PreprocessorImpl(Diagnostics* diag,
+ DirectiveHandler* directiveHandler) :
+ diagnostics(diag),
+ tokenizer(diag),
+ directiveParser(&tokenizer, &macroSet, diag, directiveHandler),
+ macroExpander(&directiveParser, &macroSet, diag)
+ {
+ }
+};
+
+Preprocessor::Preprocessor(Diagnostics* diagnostics,
+ DirectiveHandler* directiveHandler)
+{
+ mImpl = new PreprocessorImpl(diagnostics, directiveHandler);
+}
+
+Preprocessor::~Preprocessor()
+{
+ delete mImpl;
+}
+
+bool Preprocessor::init(size_t count,
+ const char* const string[],
+ const int length[])
+{
+ static const int kGLSLVersion = 100;
+
+ // Add standard pre-defined macros.
+ predefineMacro("__LINE__", 0);
+ predefineMacro("__FILE__", 0);
+ predefineMacro("__VERSION__", kGLSLVersion);
+ predefineMacro("GL_ES", 1);
+
+ return mImpl->tokenizer.init(count, string, length);
+}
+
+void Preprocessor::predefineMacro(const char* name, int value)
+{
+ std::ostringstream stream;
+ stream << value;
+
+ Token token;
+ token.type = Token::CONST_INT;
+ token.text = stream.str();
+
+ Macro macro;
+ macro.predefined = true;
+ macro.type = Macro::kTypeObj;
+ macro.name = name;
+ macro.replacements.push_back(token);
+
+ mImpl->macroSet[name] = macro;
+}
+
+void Preprocessor::lex(Token* token)
+{
+ bool validToken = false;
+ while (!validToken)
+ {
+ mImpl->macroExpander.lex(token);
+ switch (token->type)
+ {
+ // We should not be returning internal preprocessing tokens.
+ // Convert preprocessing tokens to compiler tokens or report
+ // diagnostics.
+ case Token::PP_HASH:
+ assert(false);
+ break;
+ case Token::CONST_INT:
+ {
+ int val = 0;
+ if (!token->iValue(&val))
+ {
+ // Do not mark the token as invalid.
+ // Just emit the diagnostic and reset value to 0.
+ mImpl->diagnostics->report(Diagnostics::INTEGER_OVERFLOW,
+ token->location, token->text);
+ token->text.assign("0");
+ }
+ validToken = true;
+ break;
+ }
+ case Token::CONST_FLOAT:
+ {
+ float val = 0;
+ if (!token->fValue(&val))
+ {
+ // Do not mark the token as invalid.
+ // Just emit the diagnostic and reset value to 0.0.
+ mImpl->diagnostics->report(Diagnostics::FLOAT_OVERFLOW,
+ token->location, token->text);
+ token->text.assign("0.0");
+ }
+ validToken = true;
+ break;
+ }
+ case Token::PP_NUMBER:
+ mImpl->diagnostics->report(Diagnostics::INVALID_NUMBER,
+ token->location, token->text);
+ break;
+ case Token::PP_OTHER:
+ mImpl->diagnostics->report(Diagnostics::INVALID_CHARACTER,
+ token->location, token->text);
+ break;
+ default:
+ validToken = true;
+ break;
+ }
+ }
+}
+
+} // namespace pp
+