gfx/angle/src/compiler/Common.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/Common.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +//
     1.5 +// Copyright (c) 2002-2010 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 _COMMON_INCLUDED_
    1.11 +#define _COMMON_INCLUDED_
    1.12 +
    1.13 +#include <map>
    1.14 +#include <sstream>
    1.15 +#include <string>
    1.16 +#include <vector>
    1.17 +
    1.18 +#include "compiler/PoolAlloc.h"
    1.19 +
    1.20 +struct TSourceLoc {
    1.21 +    int first_file;
    1.22 +    int first_line;
    1.23 +    int last_file;
    1.24 +    int last_line;
    1.25 +};
    1.26 +
    1.27 +//
    1.28 +// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
    1.29 +//
    1.30 +#define POOL_ALLOCATOR_NEW_DELETE()                                                  \
    1.31 +    void* operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); }   \
    1.32 +    void* operator new(size_t, void *_Where) { return (_Where); }                    \
    1.33 +    void operator delete(void*) { }                                                  \
    1.34 +    void operator delete(void *, void *) { }                                         \
    1.35 +    void* operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \
    1.36 +    void* operator new[](size_t, void *_Where) { return (_Where); }                  \
    1.37 +    void operator delete[](void*) { }                                                \
    1.38 +    void operator delete[](void *, void *) { }
    1.39 +
    1.40 +//
    1.41 +// Pool version of string.
    1.42 +//
    1.43 +typedef pool_allocator<char> TStringAllocator;
    1.44 +typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
    1.45 +typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream;
    1.46 +inline TString* NewPoolTString(const char* s)
    1.47 +{
    1.48 +	void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString));
    1.49 +	return new(memory) TString(s);
    1.50 +}
    1.51 +
    1.52 +//
    1.53 +// Persistent string memory.  Should only be used for strings that survive
    1.54 +// across compiles.
    1.55 +//
    1.56 +#define TPersistString std::string
    1.57 +#define TPersistStringStream std::ostringstream
    1.58 +
    1.59 +//
    1.60 +// Pool allocator versions of vectors, lists, and maps
    1.61 +//
    1.62 +template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
    1.63 +public:
    1.64 +    typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
    1.65 +    TVector() : std::vector<T, pool_allocator<T> >() {}
    1.66 +    TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
    1.67 +    TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
    1.68 +};
    1.69 +
    1.70 +template <class K, class D, class CMP = std::less<K> > 
    1.71 +class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D> > > {
    1.72 +public:
    1.73 +    typedef pool_allocator<std::pair<const K, D> > tAllocator;
    1.74 +
    1.75 +    TMap() : std::map<K, D, CMP, tAllocator>() {}
    1.76 +    // use correct two-stage name lookup supported in gcc 3.4 and above
    1.77 +    TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {}
    1.78 +};
    1.79 +
    1.80 +#endif // _COMMON_INCLUDED_

mercurial