chromium/third_party/angle/src/compiler/translator/Common.h

//
// Copyright 2002 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 <stdio.h>
#include <limits>
#include <map>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "common/angleutils.h"
#include "common/debug.h"
#include "compiler/translator/PoolAlloc.h"

namespace sh
{

struct TSourceLoc
{};

constexpr TSourceLoc kNoSourceLoc{};

//
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
//
#define POOL_ALLOCATOR_NEW_DELETE

//
// Pool version of string.
//
TStringAllocator;
TString;
TStringStream;

//
// Persistent memory.  Should only be used for strings that survive across compiles.
//
TPersistString;
TPersistStringStream;

//
// Pool allocator versions of vectors, lists, and maps
//
template <class T>
class TVector : public std::vector<T, pool_allocator<T>>
{};

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() :{}
    // use correct two-stage name lookup supported in gcc 3.4 and above
    TUnorderedMap(const tAllocator &a)
        :{}
};

template <class K, class H = std::hash<K>, class CMP = std::equal_to<K>>
class TUnorderedSet : public std::unordered_set<K, H, CMP, pool_allocator<K>>
{
  public:
    POOL_ALLOCATOR_NEW_DELETE
    typedef pool_allocator<K> tAllocator;

    TUnorderedSet() :{}
    // use correct two-stage name lookup supported in gcc 3.4 and above
    TUnorderedSet(const tAllocator &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() :{}
    // use correct two-stage name lookup supported in gcc 3.4 and above
    TMap(const tAllocator &a)
        :{}
};

// Basic implementation of C++20's span for use with pool-allocated containers (TVector) or static
// arrays.  This is used by the array sizes member of TType to allow arrayed types to be
// constexpr-constructed.
// See the reference for std::span here: https://en.cppreference.com/w/cpp/container/span
template <typename T>
class TSpan
{};

// Integer to TString conversion
template <typename T>
inline TString str(T i)
{}

// Allocate a char array in the global memory pool. str must be a null terminated string. strLength
// is the length without the null terminator.
inline const char *AllocatePoolCharArray(const char *str, size_t strLength)
{}

// Initialize a new stream which must be imbued with the classic locale
template <typename T>
T InitializeStream()
{}

}  // namespace sh

namespace std
{
template <>
struct hash<sh::TString>
{};
}  // namespace std

#endif  // COMPILER_TRANSLATOR_COMMON_H_