From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- gfx/angle/src/compiler/translator/Common.h | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 gfx/angle/src/compiler/translator/Common.h (limited to 'gfx/angle/src/compiler/translator/Common.h') diff --git a/gfx/angle/src/compiler/translator/Common.h b/gfx/angle/src/compiler/translator/Common.h new file mode 100755 index 000000000..853317891 --- /dev/null +++ b/gfx/angle/src/compiler/translator/Common.h @@ -0,0 +1,100 @@ +// +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// + +#ifndef COMPILER_TRANSLATOR_COMMON_H_ +#define COMPILER_TRANSLATOR_COMMON_H_ + +#include +#include +#include +#include +#include +#include + +#include "common/angleutils.h" +#include "common/debug.h" +#include "compiler/translator/PoolAlloc.h" + +namespace sh +{ + +struct TSourceLoc { + int first_file; + int first_line; + int last_file; + int last_line; +}; + +// +// 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 *) { } + +// +// Pool version of string. +// +typedef pool_allocator TStringAllocator; +typedef std::basic_string , TStringAllocator> TString; +typedef std::basic_ostringstream, TStringAllocator> TStringStream; +inline TString* NewPoolTString(const char* s) +{ + void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString)); + return new(memory) TString(s); +} + +// +// Persistent string memory. Should only be used for strings that survive +// across compiles. +// +#define TPersistString std::string +#define TPersistStringStream std::ostringstream + +// +// Pool allocator versions of vectors, lists, and maps +// +template +class TVector : public std::vector> +{ + public: + typedef typename std::vector>::size_type size_type; + TVector() : std::vector>() {} + TVector(const pool_allocator &a) : std::vector>(a) {} + TVector(size_type i) : std::vector>(i) {} +}; + +template > +class TMap : public std::map>> +{ + public: + typedef pool_allocator> tAllocator; + + TMap() : std::map() {} + // use correct two-stage name lookup supported in gcc 3.4 and above + TMap(const tAllocator& a) : std::map(std::map::key_compare(), a) {} +}; + +// Integer to TString conversion +template +inline TString str(T i) +{ + ASSERT(std::numeric_limits::is_integer); + char buffer[((8 * sizeof(T)) / 3) + 3]; + const char *formatStr = std::numeric_limits::is_signed ? "%d" : "%u"; + snprintf(buffer, sizeof(buffer), formatStr, i); + return buffer; +} + +} // namespace sh + +#endif // COMPILER_TRANSLATOR_COMMON_H_ -- cgit v1.2.3