Edit

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

Branch :

  • Show log

    Commit

  • Author : Olli Etuaho
    Date : 2018-06-20 11:43:08
    Hash : 72e3589c
    Message : Refactor debug output of types Instead of passing around strings from TType::getCompleteString(), add a stream operator to InfoSinkBase that takes a TType. This makes the compiler executable a few kilobytes smaller and will help with getting rid of TString altogether. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I31a6693b40a28824b3959e19ad3c0a2ce0f0a35f Reviewed-on: https://chromium-review.googlesource.com/1107712 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>

  • src/compiler/translator/InfoSink.cpp
  • //
    // 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.
    //
    
    #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(" ");
        }
        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;
        if (line)
            stream << file << ":" << line;
        else
            stream << file << ":? ";
        stream << ": ";
    
        sink.append(stream.str());
    }
    
    }  // namespace sh