1// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "InfoSink.h"
16
17void TInfoSinkBase::prefix(TPrefixType message) {
18 switch(message) {
19 case EPrefixNone:
20 break;
21 case EPrefixInfo:
22 sink.append("INFO: ");
23 break;
24 case EPrefixWarning:
25 sink.append("WARNING: ");
26 break;
27 case EPrefixError:
28 sink.append("ERROR: ");
29 break;
30 case EPrefixInternalError:
31 sink.append("INTERNAL ERROR: ");
32 break;
33 case EPrefixUnimplemented:
34 sink.append("UNIMPLEMENTED: ");
35 break;
36 case EPrefixNote:
37 sink.append("NOTE: ");
38 break;
39 default:
40 sink.append("UNKOWN ERROR: ");
41 break;
42 }
43}
44
45void TInfoSinkBase::location(const TSourceLoc& loc) {
46 int string = loc.first_file, line = loc.first_line;
47
48 TPersistStringStream stream;
49 if (line)
50 stream << string << ":" << line;
51 else
52 stream << string << ":? ";
53 stream << ": ";
54
55 sink.append(stream.str());
56}
57
58void TInfoSinkBase::message(TPrefixType message, const char* s) {
59 prefix(message);
60 sink.append(s);
61 sink.append("\n");
62}
63
64void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) {
65 prefix(message);
66 location(loc);
67 sink.append(s);
68 sink.append("\n");
69}
70