blob: d059d05795557d3802dec6eab6a63f7cfc63d66e [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
John Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// 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.
John Bauman89401822014-05-06 15:04:28 -040014
Nicolas Capenscc863da2015-01-21 15:50:55 -050015#include "InfoSink.h"
John Bauman89401822014-05-06 15:04:28 -040016
17void TInfoSinkBase::prefix(TPrefixType message) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040018 switch(message) {
19 case EPrefixNone:
20 break;
21 case EPrefixWarning:
22 sink.append("WARNING: ");
23 break;
24 case EPrefixError:
25 sink.append("ERROR: ");
26 break;
27 case EPrefixInternalError:
28 sink.append("INTERNAL ERROR: ");
29 break;
30 case EPrefixUnimplemented:
31 sink.append("UNIMPLEMENTED: ");
32 break;
33 case EPrefixNote:
34 sink.append("NOTE: ");
35 break;
36 default:
37 sink.append("UNKOWN ERROR: ");
38 break;
39 }
John Bauman89401822014-05-06 15:04:28 -040040}
41
Alexis Hetu253fdd12015-07-07 15:12:46 -040042void TInfoSinkBase::location(const TSourceLoc& loc) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040043 int string = loc.first_file, line = loc.first_line;
John Bauman89401822014-05-06 15:04:28 -040044
Nicolas Capens0bac2852016-05-07 06:09:58 -040045 TPersistStringStream stream;
46 if (line)
47 stream << string << ":" << line;
48 else
49 stream << string << ":? ";
50 stream << ": ";
John Bauman89401822014-05-06 15:04:28 -040051
Nicolas Capens0bac2852016-05-07 06:09:58 -040052 sink.append(stream.str());
John Bauman89401822014-05-06 15:04:28 -040053}
54
55void TInfoSinkBase::message(TPrefixType message, const char* s) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040056 prefix(message);
57 sink.append(s);
58 sink.append("\n");
John Bauman89401822014-05-06 15:04:28 -040059}
60
61void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040062 prefix(message);
63 location(loc);
64 sink.append(s);
65 sink.append("\n");
John Bauman89401822014-05-06 15:04:28 -040066}