1 // 2 // Copyright 2002 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #include "compiler/translator/InfoSink.h" 8 9 #include "compiler/translator/ImmutableString.h" 10 #include "compiler/translator/Symbol.h" 11 #include "compiler/translator/Types.h" 12 13 namespace sh 14 { 15 prefix(Severity severity)16void TInfoSinkBase::prefix(Severity severity) 17 { 18 switch (severity) 19 { 20 case SH_WARNING: 21 sink.append("WARNING: "); 22 break; 23 case SH_ERROR: 24 sink.append("ERROR: "); 25 break; 26 default: 27 sink.append("UNKOWN ERROR: "); 28 break; 29 } 30 } 31 operator <<(const ImmutableString & str)32TInfoSinkBase &TInfoSinkBase::operator<<(const ImmutableString &str) 33 { 34 sink.append(str.data()); 35 return *this; 36 } 37 operator <<(const TType & type)38TInfoSinkBase &TInfoSinkBase::operator<<(const TType &type) 39 { 40 if (type.isInvariant()) 41 sink.append("invariant "); 42 if (type.getQualifier() != EvqTemporary && type.getQualifier() != EvqGlobal) 43 { 44 sink.append(type.getQualifierString()); 45 sink.append(" "); 46 } 47 if (type.getPrecision() != EbpUndefined) 48 { 49 sink.append(type.getPrecisionString()); 50 sink.append(" "); 51 } 52 53 const TMemoryQualifier &memoryQualifier = type.getMemoryQualifier(); 54 if (memoryQualifier.readonly) 55 { 56 sink.append("readonly "); 57 } 58 if (memoryQualifier.writeonly) 59 { 60 sink.append("writeonly "); 61 } 62 if (memoryQualifier.coherent) 63 { 64 sink.append("coherent "); 65 } 66 if (memoryQualifier.restrictQualifier) 67 { 68 sink.append("restrict "); 69 } 70 if (memoryQualifier.volatileQualifier) 71 { 72 sink.append("volatile "); 73 } 74 75 if (type.isArray()) 76 { 77 for (auto arraySizeIter = type.getArraySizes().rbegin(); 78 arraySizeIter != type.getArraySizes().rend(); ++arraySizeIter) 79 { 80 *this << "array[" << (*arraySizeIter) << "] of "; 81 } 82 } 83 if (type.isMatrix()) 84 { 85 *this << static_cast<uint32_t>(type.getCols()) << "X" 86 << static_cast<uint32_t>(type.getRows()) << " matrix of "; 87 } 88 else if (type.isVector()) 89 *this << static_cast<uint32_t>(type.getNominalSize()) << "-component vector of "; 90 91 sink.append(type.getBasicString()); 92 93 if (type.getStruct() != nullptr) 94 { 95 *this << ' ' << static_cast<const TSymbol &>(*type.getStruct()); 96 if (type.isStructSpecifier()) 97 { 98 *this << " (specifier)"; 99 } 100 } 101 102 return *this; 103 } 104 operator <<(const TSymbol & symbol)105TInfoSinkBase &TInfoSinkBase::operator<<(const TSymbol &symbol) 106 { 107 switch (symbol.symbolType()) 108 { 109 case (SymbolType::BuiltIn): 110 *this << symbol.name(); 111 break; 112 case (SymbolType::Empty): 113 *this << "''"; 114 break; 115 case (SymbolType::AngleInternal): 116 *this << '#' << symbol.name(); 117 break; 118 case (SymbolType::UserDefined): 119 *this << '\'' << symbol.name() << '\''; 120 break; 121 } 122 *this << " (symbol id " << symbol.uniqueId().get() << ")"; 123 return *this; 124 } 125 location(int file,int line)126void TInfoSinkBase::location(int file, int line) 127 { 128 TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>(); 129 if (line) 130 stream << file << ":" << line; 131 else 132 stream << file << ":? "; 133 stream << ": "; 134 135 sink.append(stream.str()); 136 } 137 138 } // namespace sh 139