blob: 847e6e616346fa9579ed4af4025163fdece91b2a [file] [log] [blame]
zmo@google.comfd747b82011-04-23 01:30:07 +00001//
2// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "compiler/MapLongVariableNames.h"
8
9namespace {
10
zmo@google.com24c08c42011-05-27 17:40:48 +000011TString mapLongName(int id, const TString& name, bool isVarying)
zmo@google.comfd747b82011-04-23 01:30:07 +000012{
13 ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
14 TStringStream stream;
zmo@google.com24c08c42011-05-27 17:40:48 +000015 stream << "webgl_";
16 if (isVarying)
17 stream << "v";
18 stream << id << "_";
zmo@google.comfd747b82011-04-23 01:30:07 +000019 stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
20 return stream.str();
21}
22
23} // anonymous namespace
24
zmo@google.com24c08c42011-05-27 17:40:48 +000025MapLongVariableNames::MapLongVariableNames(
26 TMap<TString, TString>& varyingLongNameMap)
27 : mVaryingLongNameMap(varyingLongNameMap)
28{
29}
30
zmo@google.comfd747b82011-04-23 01:30:07 +000031void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
32{
33 ASSERT(symbol != NULL);
zmo@google.com24c08c42011-05-27 17:40:48 +000034 if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE) {
35 switch (symbol->getQualifier()) {
36 case EvqVaryingIn:
37 case EvqVaryingOut:
38 case EvqInvariantVaryingIn:
39 case EvqInvariantVaryingOut:
40 symbol->setSymbol(
41 mapVaryingLongName(symbol->getSymbol()));
42 break;
43 default:
44 symbol->setSymbol(
45 mapLongName(symbol->getId(), symbol->getSymbol(), false));
46 break;
47 };
48 }
zmo@google.comfd747b82011-04-23 01:30:07 +000049}
50
51void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
52{
53}
54
55bool MapLongVariableNames::visitBinary(Visit, TIntermBinary*)
56{
57 return true;
58}
59
60bool MapLongVariableNames::visitUnary(Visit, TIntermUnary*)
61{
62 return true;
63}
64
65bool MapLongVariableNames::visitSelection(Visit, TIntermSelection*)
66{
67 return true;
68}
69
70bool MapLongVariableNames::visitAggregate(Visit, TIntermAggregate* node)
71{
72 return true;
73}
74
75bool MapLongVariableNames::visitLoop(Visit, TIntermLoop*)
76{
77 return true;
78}
79
80bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
81{
82 return true;
83}
zmo@google.com24c08c42011-05-27 17:40:48 +000084
85TString MapLongVariableNames::mapVaryingLongName(const TString& name)
86{
87 TMap<TString, TString>::const_iterator it = mVaryingLongNameMap.find(name);
88 if (it != mVaryingLongNameMap.end())
89 return (*it).second;
90
91 int id = mVaryingLongNameMap.size();
92 TString mappedName = mapLongName(id, name, true);
93 mVaryingLongNameMap.insert(
94 TMap<TString, TString>::value_type(name, mappedName));
95 return mappedName;
96}