michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef _COMMON_INCLUDED_ michael@0: #define _COMMON_INCLUDED_ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "compiler/PoolAlloc.h" michael@0: michael@0: struct TSourceLoc { michael@0: int first_file; michael@0: int first_line; michael@0: int last_file; michael@0: int last_line; michael@0: }; michael@0: michael@0: // michael@0: // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme. michael@0: // michael@0: #define POOL_ALLOCATOR_NEW_DELETE() \ michael@0: void* operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ michael@0: void* operator new(size_t, void *_Where) { return (_Where); } \ michael@0: void operator delete(void*) { } \ michael@0: void operator delete(void *, void *) { } \ michael@0: void* operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ michael@0: void* operator new[](size_t, void *_Where) { return (_Where); } \ michael@0: void operator delete[](void*) { } \ michael@0: void operator delete[](void *, void *) { } michael@0: michael@0: // michael@0: // Pool version of string. michael@0: // michael@0: typedef pool_allocator TStringAllocator; michael@0: typedef std::basic_string , TStringAllocator> TString; michael@0: typedef std::basic_ostringstream, TStringAllocator> TStringStream; michael@0: inline TString* NewPoolTString(const char* s) michael@0: { michael@0: void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString)); michael@0: return new(memory) TString(s); michael@0: } michael@0: michael@0: // michael@0: // Persistent string memory. Should only be used for strings that survive michael@0: // across compiles. michael@0: // michael@0: #define TPersistString std::string michael@0: #define TPersistStringStream std::ostringstream michael@0: michael@0: // michael@0: // Pool allocator versions of vectors, lists, and maps michael@0: // michael@0: template class TVector : public std::vector > { michael@0: public: michael@0: typedef typename std::vector >::size_type size_type; michael@0: TVector() : std::vector >() {} michael@0: TVector(const pool_allocator& a) : std::vector >(a) {} michael@0: TVector(size_type i): std::vector >(i) {} michael@0: }; michael@0: michael@0: template > michael@0: class TMap : public std::map > > { michael@0: public: michael@0: typedef pool_allocator > tAllocator; michael@0: michael@0: TMap() : std::map() {} michael@0: // use correct two-stage name lookup supported in gcc 3.4 and above michael@0: TMap(const tAllocator& a) : std::map(std::map::key_compare(), a) {} michael@0: }; michael@0: michael@0: #endif // _COMMON_INCLUDED_