• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)16 void 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)32 TInfoSinkBase &TInfoSinkBase::operator<<(const ImmutableString &str)
33 {
34     sink.append(str.data());
35     return *this;
36 }
37 
operator <<(const TType & type)38 TInfoSinkBase &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         if (type.getStruct()->symbolType() == SymbolType::Empty)
96         {
97             *this << " <anonymous>";
98         }
99         else
100         {
101             *this << " '" << type.getStruct()->name() << "'";
102         }
103         if (type.isStructSpecifier())
104         {
105             *this << " (specifier)";
106         }
107     }
108 
109     return *this;
110 }
111 
location(int file,int line)112 void TInfoSinkBase::location(int file, int line)
113 {
114     TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>();
115     if (line)
116         stream << file << ":" << line;
117     else
118         stream << file << ":? ";
119     stream << ": ";
120 
121     sink.append(stream.str());
122 }
123 
124 }  // namespace sh
125