Edit

kc3-lang/angle/src/compiler/translator/InfoSink.cpp

Branch :

  • Show log

    Commit

  • Author : Shahbaz Youssefi
    Date : 2019-12-16 16:07:04
    Hash : 86d9c93a
    Message : Use TSpan for TType's array sizes Until C++20, std::vector doesn't have a constexpr constructor, which means TType cannot use a `TVector` for `mArraySizes` if an arrayed type needs to be created constexpr. This is needed for the upcoming textureGatherOffsets implementation. A new TSpan class is introduced, based on std::span (from C++20) that holds the pointer/size allocated from a TVector without owning it. Since TVector's allocation are made from a pool, the allocated memory will live beyond the vector's destruction. `TType::mArraySizes` is changed to this type. This change will allow a new constexpr constructor to be added to TType that takes a TSpan as array directly, a value which is constexpr initialized from a static array (instead of TVector). Bug: angleproject:3569 Change-Id: I78793b0f4c64519e0ebe30cf6e0de995ba70035d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1968260 Reviewed-by: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>

  • src/compiler/translator/InfoSink.cpp
  • //
    // 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.
    //
    
    #include "compiler/translator/InfoSink.h"
    
    #include "compiler/translator/ImmutableString.h"
    #include "compiler/translator/Types.h"
    
    namespace sh
    {
    
    void TInfoSinkBase::prefix(Severity severity)
    {
        switch (severity)
        {
            case SH_WARNING:
                sink.append("WARNING: ");
                break;
            case SH_ERROR:
                sink.append("ERROR: ");
                break;
            default:
                sink.append("UNKOWN ERROR: ");
                break;
        }
    }
    
    TInfoSinkBase &TInfoSinkBase::operator<<(const ImmutableString &str)
    {
        sink.append(str.data());
        return *this;
    }
    
    TInfoSinkBase &TInfoSinkBase::operator<<(const TType &type)
    {
        if (type.isInvariant())
            sink.append("invariant ");
        if (type.getQualifier() != EvqTemporary && type.getQualifier() != EvqGlobal)
        {
            sink.append(type.getQualifierString());
            sink.append(" ");
        }
        if (type.getPrecision() != EbpUndefined)
        {
            sink.append(type.getPrecisionString());
            sink.append(" ");
        }
    
        const TMemoryQualifier &memoryQualifier = type.getMemoryQualifier();
        if (memoryQualifier.readonly)
        {
            sink.append("readonly ");
        }
        if (memoryQualifier.writeonly)
        {
            sink.append("writeonly ");
        }
        if (memoryQualifier.coherent)
        {
            sink.append("coherent ");
        }
        if (memoryQualifier.restrictQualifier)
        {
            sink.append("restrict ");
        }
        if (memoryQualifier.volatileQualifier)
        {
            sink.append("volatile ");
        }
    
        if (type.isArray())
        {
            for (auto arraySizeIter = type.getArraySizes().rbegin();
                 arraySizeIter != type.getArraySizes().rend(); ++arraySizeIter)
            {
                *this << "array[" << (*arraySizeIter) << "] of ";
            }
        }
        if (type.isMatrix())
        {
            *this << type.getCols() << "X" << type.getRows() << " matrix of ";
        }
        else if (type.isVector())
            *this << type.getNominalSize() << "-component vector of ";
    
        sink.append(type.getBasicString());
        return *this;
    }
    
    void TInfoSinkBase::location(int file, int line)
    {
        TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>();
        if (line)
            stream << file << ":" << line;
        else
            stream << file << ":? ";
        stream << ": ";
    
        sink.append(stream.str());
    }
    
    }  // namespace sh