diff options
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/Common.h')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/Common.h | 73 |
1 files changed, 58 insertions, 15 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/Common.h b/src/3rdparty/angle/src/compiler/translator/Common.h index 60223232af..cb3a680d85 100644 --- a/src/3rdparty/angle/src/compiler/translator/Common.h +++ b/src/3rdparty/angle/src/compiler/translator/Common.h @@ -10,15 +10,21 @@ #include <map> #include <sstream> #include <string> +#include <unordered_map> #include <vector> #include <limits> #include <stdio.h> #include "common/angleutils.h" #include "common/debug.h" +#include "common/third_party/smhasher/src/PMurHash.h" #include "compiler/translator/PoolAlloc.h" -struct TSourceLoc { +namespace sh +{ + +struct TSourceLoc +{ int first_file; int first_line; int last_file; @@ -29,25 +35,25 @@ struct TSourceLoc { // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme. // #define POOL_ALLOCATOR_NEW_DELETE() \ - void* operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ - void* operator new(size_t, void *_Where) { return (_Where); } \ - void operator delete(void*) { } \ - void operator delete(void *, void *) { } \ - void* operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ - void* operator new[](size_t, void *_Where) { return (_Where); } \ - void operator delete[](void*) { } \ - void operator delete[](void *, void *) { } + void *operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ + void *operator new(size_t, void *_Where) { return (_Where); } \ + void operator delete(void *) {} \ + void operator delete(void *, void *) {} \ + void *operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ + void *operator new[](size_t, void *_Where) { return (_Where); } \ + void operator delete[](void *) {} \ + void operator delete[](void *, void *) {} // // Pool version of string. // typedef pool_allocator<char> TStringAllocator; -typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString; +typedef std::basic_string<char, std::char_traits<char>, TStringAllocator> TString; typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream; -inline TString* NewPoolTString(const char* s) +inline TString *NewPoolTString(const char *s) { - void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString)); - return new(memory) TString(s); + void *memory = GetGlobalPoolAllocator()->allocate(sizeof(TString)); + return new (memory) TString(s); } // @@ -64,21 +70,44 @@ template <class T> class TVector : public std::vector<T, pool_allocator<T>> { public: + POOL_ALLOCATOR_NEW_DELETE(); + typedef typename std::vector<T, pool_allocator<T>>::size_type size_type; TVector() : std::vector<T, pool_allocator<T>>() {} TVector(const pool_allocator<T> &a) : std::vector<T, pool_allocator<T>>(a) {} TVector(size_type i) : std::vector<T, pool_allocator<T>>(i) {} }; +template <class K, class D, class H = std::hash<K>, class CMP = std::equal_to<K>> +class TUnorderedMap : public std::unordered_map<K, D, H, CMP, pool_allocator<std::pair<const K, D>>> +{ + public: + POOL_ALLOCATOR_NEW_DELETE(); + typedef pool_allocator<std::pair<const K, D>> tAllocator; + + TUnorderedMap() : std::unordered_map<K, D, H, CMP, tAllocator>() {} + // use correct two-stage name lookup supported in gcc 3.4 and above + TUnorderedMap(const tAllocator &a) + : std::unordered_map<K, D, H, CMP, tAllocator>( + std::unordered_map<K, D, H, CMP, tAllocator>::key_compare(), + a) + { + } +}; + template <class K, class D, class CMP = std::less<K>> class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D>>> { public: + POOL_ALLOCATOR_NEW_DELETE(); typedef pool_allocator<std::pair<const K, D>> tAllocator; TMap() : std::map<K, D, CMP, tAllocator>() {} // use correct two-stage name lookup supported in gcc 3.4 and above - TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {} + TMap(const tAllocator &a) + : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) + { + } }; // Integer to TString conversion @@ -92,4 +121,18 @@ inline TString str(T i) return buffer; } -#endif // COMPILER_TRANSLATOR_COMMON_H_ +} // namespace sh + +namespace std +{ +template <> +struct hash<sh::TString> +{ + size_t operator()(const sh::TString &s) const + { + return angle::PMurHash32(0, s.data(), static_cast<int>(s.length())); + } +}; +} // namespace std + +#endif // COMPILER_TRANSLATOR_COMMON_H_ |