1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/MapLongVariableNames.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#ifndef COMPILER_MAP_LONG_VARIABLE_NAMES_H_ 1.11 +#define COMPILER_MAP_LONG_VARIABLE_NAMES_H_ 1.12 + 1.13 +#include "GLSLANG/ShaderLang.h" 1.14 + 1.15 +#include "compiler/intermediate.h" 1.16 +#include "compiler/VariableInfo.h" 1.17 + 1.18 +// This size does not include '\0' in the end. 1.19 +#define MAX_SHORTENED_IDENTIFIER_SIZE 32 1.20 + 1.21 +// This is a ref-counted singleton. GetInstance() returns a pointer to the 1.22 +// singleton, and after use, call Release(). GetInstance() and Release() should 1.23 +// be paired. 1.24 +class LongNameMap { 1.25 +public: 1.26 + static LongNameMap* GetInstance(); 1.27 + void Release(); 1.28 + 1.29 + // Return the mapped name if <originalName, mappedName> is in the map; 1.30 + // otherwise, return NULL. 1.31 + const char* Find(const char* originalName) const; 1.32 + 1.33 + // Insert a pair into the map. 1.34 + void Insert(const char* originalName, const char* mappedName); 1.35 + 1.36 + // Return the number of entries in the map. 1.37 + size_t Size() const; 1.38 + 1.39 +private: 1.40 + LongNameMap(); 1.41 + ~LongNameMap(); 1.42 + 1.43 + size_t refCount; 1.44 + std::map<std::string, std::string> mLongNameMap; 1.45 +}; 1.46 + 1.47 +// Traverses intermediate tree to map attributes and uniforms names that are 1.48 +// longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE. 1.49 +class MapLongVariableNames : public TIntermTraverser { 1.50 +public: 1.51 + MapLongVariableNames(LongNameMap* globalMap); 1.52 + 1.53 + virtual void visitSymbol(TIntermSymbol*); 1.54 + virtual bool visitLoop(Visit, TIntermLoop*); 1.55 + 1.56 +private: 1.57 + TString mapGlobalLongName(const TString& name); 1.58 + 1.59 + LongNameMap* mGlobalMap; 1.60 +}; 1.61 + 1.62 +#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_