1 // 2 // Copyright (c) 2002-2012 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 #ifndef COMPILER_MAP_LONG_VARIABLE_NAMES_H_ 8 #define COMPILER_MAP_LONG_VARIABLE_NAMES_H_ 9 10 #include "GLSLANG/ShaderLang.h" 11 12 #include "compiler/intermediate.h" 13 #include "compiler/VariableInfo.h" 14 15 // This size does not include '\0' in the end. 16 #define MAX_SHORTENED_IDENTIFIER_SIZE 32 17 18 // This is a ref-counted singleton. GetInstance() returns a pointer to the 19 // singleton, and after use, call Release(). GetInstance() and Release() should 20 // be paired. 21 class LongNameMap { 22 public: 23 static LongNameMap* GetInstance(); 24 void Release(); 25 26 // Return the mapped name if <originalName, mappedName> is in the map; 27 // otherwise, return NULL. 28 const char* Find(const char* originalName) const; 29 30 // Insert a pair into the map. 31 void Insert(const char* originalName, const char* mappedName); 32 33 // Return the number of entries in the map. 34 size_t Size() const; 35 36 private: 37 LongNameMap(); 38 ~LongNameMap(); 39 40 size_t refCount; 41 std::map<std::string, std::string> mLongNameMap; 42 }; 43 44 // Traverses intermediate tree to map attributes and uniforms names that are 45 // longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE. 46 class MapLongVariableNames : public TIntermTraverser { 47 public: 48 MapLongVariableNames(LongNameMap* globalMap); 49 50 virtual void visitSymbol(TIntermSymbol*); 51 52 private: 53 TString mapGlobalLongName(const TString& name); 54 55 LongNameMap* mGlobalMap; 56 }; 57 58 #endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_ 59