zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MapLongVariableNames.cpp
Go to the documentation of this file.
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 
8 
9 namespace {
10 
11 TString mapLongName(size_t id, const TString& name, bool isGlobal)
12 {
15  stream << "webgl_";
16  if (isGlobal)
17  stream << "g";
18  stream << id;
19  if (name[0] != '_')
20  stream << "_";
21  stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size());
22  return stream.str();
23 }
24 
25 LongNameMap* gLongNameMapInstance = NULL;
26 
27 } // anonymous namespace
28 
29 LongNameMap::LongNameMap()
30  : refCount(0)
31 {
32 }
33 
34 LongNameMap::~LongNameMap()
35 {
36 }
37 
38 // static
40 {
41  if (gLongNameMapInstance == NULL)
42  gLongNameMapInstance = new LongNameMap;
43  gLongNameMapInstance->refCount++;
44  return gLongNameMapInstance;
45 }
46 
48 {
49  ASSERT(gLongNameMapInstance == this);
50  ASSERT(refCount > 0);
51  refCount--;
52  if (refCount == 0) {
53  delete gLongNameMapInstance;
54  gLongNameMapInstance = NULL;
55  }
56 }
57 
58 const char* LongNameMap::Find(const char* originalName) const
59 {
60  std::map<std::string, std::string>::const_iterator it = mLongNameMap.find(
61  originalName);
62  if (it != mLongNameMap.end())
63  return (*it).second.c_str();
64  return NULL;
65 }
66 
67 void LongNameMap::Insert(const char* originalName, const char* mappedName)
68 {
69  mLongNameMap.insert(std::map<std::string, std::string>::value_type(
70  originalName, mappedName));
71 }
72 
73 size_t LongNameMap::Size() const
74 {
75  return mLongNameMap.size();
76 }
77 
79 {
80  ASSERT(globalMap);
81  mGlobalMap = globalMap;
82 }
83 
85 {
86  ASSERT(symbol != NULL);
87  if (symbol->getSymbol().size() > MAX_SHORTENED_IDENTIFIER_SIZE) {
88  switch (symbol->getQualifier()) {
89  case EvqVaryingIn:
90  case EvqVaryingOut:
93  case EvqUniform:
94  symbol->setSymbol(
95  mapGlobalLongName(symbol->getSymbol()));
96  break;
97  default:
98  symbol->setSymbol(
99  mapLongName(symbol->getId(), symbol->getSymbol(), false));
100  break;
101  };
102  }
103 }
104 
106 {
107  if (node->getInit())
108  node->getInit()->traverse(this);
109  return true;
110 }
111 
112 TString MapLongVariableNames::mapGlobalLongName(const TString& name)
113 {
114  ASSERT(mGlobalMap);
115  const char* mappedName = mGlobalMap->Find(name.c_str());
116  if (mappedName != NULL)
117  return mappedName;
118  size_t id = mGlobalMap->Size();
119  TString rt = mapLongName(id, name, true);
120  mGlobalMap->Insert(name.c_str(), rt.c_str());
121  return rt;
122 }
Visit
Definition: intermediate.h:524
virtual void visitSymbol(TIntermSymbol *)
virtual bool visitLoop(Visit, TIntermLoop *)
int getId() const
Definition: intermediate.h:348
#define NULL
Definition: ftobjs.h:61
#define MAX_SHORTENED_IDENTIFIER_SIZE
GLuint GLuint stream
Definition: glew.h:6573
MapLongVariableNames(LongNameMap *globalMap)
EGLImageKHR EGLint * name
Definition: eglext.h:284
TQualifier getQualifier() const
Definition: intermediate.h:255
GLuint id
Definition: gl2ext.h:1142
#define ASSERT(expression)
Definition: debug.h:36
std::basic_ostringstream< char, std::char_traits< char >, TStringAllocator > TStringStream
Definition: Common.h:42
virtual void traverse(TIntermTraverser *)=0
void setSymbol(const TString &sym)
Definition: intermediate.h:352
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
const char * Find(const char *originalName) const
static LongNameMap * GetInstance()
const TString & getSymbol() const
Definition: intermediate.h:349
TIntermNode * getInit()
Definition: intermediate.h:300
size_t Size() const
void Insert(const char *originalName, const char *mappedName)