Implement shader identifier name mapping.
The name mapping happens when an identifier is longer than 32 characters. The name mapping is behind a flag, so it won't happen by default. Also, functions to query the mapped names are added.
The purpose of this CL is for the drivers that can't handle long names. For example, linux NVIDIA driver can't handle 256 character name, whereas WebGL spec requires that.
This CL also fixes the issue that some of the TIntermSymbols' ids are 0s.
ANGLEBUG=144
TEST=test manually with shaders with long identifier names.
Review URL: http://codereview.appspot.com/4428058
git-svn-id: https://angleproject.googlecode.com/svn/trunk@619 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/MapLongVariableNames.cpp b/src/compiler/MapLongVariableNames.cpp
new file mode 100644
index 0000000..9968262
--- /dev/null
+++ b/src/compiler/MapLongVariableNames.cpp
@@ -0,0 +1,61 @@
+//
+// Copyright (c) 2002-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 "compiler/MapLongVariableNames.h"
+
+namespace {
+
+TString mapLongName(int id, const TString& name)
+{
+ ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
+ TStringStream stream;
+ stream << "webgl_" << id << "_";
+ stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
+ return stream.str();
+}
+
+} // anonymous namespace
+
+void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
+{
+ ASSERT(symbol != NULL);
+ if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE)
+ symbol->setSymbol(mapLongName(symbol->getId(), symbol->getSymbol()));
+}
+
+void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
+{
+}
+
+bool MapLongVariableNames::visitBinary(Visit, TIntermBinary*)
+{
+ return true;
+}
+
+bool MapLongVariableNames::visitUnary(Visit, TIntermUnary*)
+{
+ return true;
+}
+
+bool MapLongVariableNames::visitSelection(Visit, TIntermSelection*)
+{
+ return true;
+}
+
+bool MapLongVariableNames::visitAggregate(Visit, TIntermAggregate* node)
+{
+ return true;
+}
+
+bool MapLongVariableNames::visitLoop(Visit, TIntermLoop*)
+{
+ return true;
+}
+
+bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
+{
+ return true;
+}