zenilib: zenilib/jni/external/angle/src/compiler/MapLongVariableNames.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
7 #include "compiler/MapLongVariableNames.h"
8
9 namespace {
10
11 TString mapLongName(size_t id, const TString& name, bool isGlobal)
12 {
13 ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
14 TStringStream stream;
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
39 LongNameMap* LongNameMap::GetInstance()
40 {
41 if (gLongNameMapInstance == NULL)
42 gLongNameMapInstance = new LongNameMap;
43 gLongNameMapInstance->refCount++;
44 return gLongNameMapInstance;
45 }
46
47 void LongNameMap::Release()
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
78 MapLongVariableNames::MapLongVariableNames(LongNameMap* globalMap)
79 {
80 ASSERT(globalMap);
81 mGlobalMap = globalMap;
82 }
83
84 void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
85 {
86 ASSERT(symbol != NULL);
87 if (symbol->getSymbol().size() > MAX_SHORTENED_IDENTIFIER_SIZE) {
88 switch (symbol->getQualifier()) {
89 case EvqVaryingIn:
90 case EvqVaryingOut:
91 case EvqInvariantVaryingIn:
92 case EvqInvariantVaryingOut:
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
105 bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node)
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
Visit
Definition: intermediate.h:524
MapLongVariableNames::visitSymbol
virtual void visitSymbol(TIntermSymbol *)
Definition: MapLongVariableNames.cpp:84
MapLongVariableNames::visitLoop
virtual bool visitLoop(Visit, TIntermLoop *)
Definition: MapLongVariableNames.cpp:105
TIntermSymbol::getId
int getId() const
Definition: intermediate.h:348
EvqUniform
Definition: BaseTypes.h:91
NULL
#define NULL
Definition: ftobjs.h:61
EvqVaryingOut
Definition: BaseTypes.h:88
MAX_SHORTENED_IDENTIFIER_SIZE
#define MAX_SHORTENED_IDENTIFIER_SIZE
Definition: MapLongVariableNames.h:16
stream
GLuint GLuint stream
Definition: glew.h:6573
MapLongVariableNames::MapLongVariableNames
MapLongVariableNames(LongNameMap *globalMap)
Definition: MapLongVariableNames.cpp:78
EvqInvariantVaryingOut
Definition: BaseTypes.h:90
LongNameMap
Definition: MapLongVariableNames.h:21
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
TIntermTyped::getQualifier
TQualifier getQualifier() const
Definition: intermediate.h:255
id
GLuint id
Definition: gl2ext.h:1142
ASSERT
#define ASSERT(expression)
Definition: debug.h:36
TStringStream
std::basic_ostringstream< char, std::char_traits< char >, TStringAllocator > TStringStream
Definition: Common.h:42
TIntermNode::traverse
virtual void traverse(TIntermTraverser *)=0
MapLongVariableNames.h
TIntermSymbol::setSymbol
void setSymbol(const TString &sym)
Definition: intermediate.h:352
TString
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
TIntermSymbol
Definition: intermediate.h:340
TIntermLoop
Definition: intermediate.h:284
LongNameMap::Find
const char * Find(const char *originalName) const
Definition: MapLongVariableNames.cpp:58
EvqVaryingIn
Definition: BaseTypes.h:87
LongNameMap::GetInstance
static LongNameMap * GetInstance()
Definition: MapLongVariableNames.cpp:39
TIntermSymbol::getSymbol
const TString & getSymbol() const
Definition: intermediate.h:349
TIntermLoop::getInit
TIntermNode * getInit()
Definition: intermediate.h:300
LongNameMap::Size
size_t Size() const
Definition: MapLongVariableNames.cpp:73
LongNameMap::Release
void Release()
Definition: MapLongVariableNames.cpp:47
EvqInvariantVaryingIn
Definition: BaseTypes.h:89
LongNameMap::Insert
void Insert(const char *originalName, const char *mappedName)
Definition: MapLongVariableNames.cpp:67