michael@0: // michael@0: // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef COMPILER_MAP_LONG_VARIABLE_NAMES_H_ michael@0: #define COMPILER_MAP_LONG_VARIABLE_NAMES_H_ michael@0: michael@0: #include "GLSLANG/ShaderLang.h" michael@0: michael@0: #include "compiler/intermediate.h" michael@0: #include "compiler/VariableInfo.h" michael@0: michael@0: // This size does not include '\0' in the end. michael@0: #define MAX_SHORTENED_IDENTIFIER_SIZE 32 michael@0: michael@0: // This is a ref-counted singleton. GetInstance() returns a pointer to the michael@0: // singleton, and after use, call Release(). GetInstance() and Release() should michael@0: // be paired. michael@0: class LongNameMap { michael@0: public: michael@0: static LongNameMap* GetInstance(); michael@0: void Release(); michael@0: michael@0: // Return the mapped name if is in the map; michael@0: // otherwise, return NULL. michael@0: const char* Find(const char* originalName) const; michael@0: michael@0: // Insert a pair into the map. michael@0: void Insert(const char* originalName, const char* mappedName); michael@0: michael@0: // Return the number of entries in the map. michael@0: size_t Size() const; michael@0: michael@0: private: michael@0: LongNameMap(); michael@0: ~LongNameMap(); michael@0: michael@0: size_t refCount; michael@0: std::map mLongNameMap; michael@0: }; michael@0: michael@0: // Traverses intermediate tree to map attributes and uniforms names that are michael@0: // longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE. michael@0: class MapLongVariableNames : public TIntermTraverser { michael@0: public: michael@0: MapLongVariableNames(LongNameMap* globalMap); michael@0: michael@0: virtual void visitSymbol(TIntermSymbol*); michael@0: virtual bool visitLoop(Visit, TIntermLoop*); michael@0: michael@0: private: michael@0: TString mapGlobalLongName(const TString& name); michael@0: michael@0: LongNameMap* mGlobalMap; michael@0: }; michael@0: michael@0: #endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_