blob: 84dd3374b6500bb371d8d0132faf5f92cdbb2188 [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;
Nicolas Capens937e6a52018-05-29 17:11:37 -040021 case EPrefixInfo:
22 sink.append("INFO: ");
23 break;
Nicolas Capens0bac2852016-05-07 06:09:58 -040024 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 }
John Bauman89401822014-05-06 15:04:28 -040043}
44
Alexis Hetu253fdd12015-07-07 15:12:46 -040045void TInfoSinkBase::location(const TSourceLoc& loc) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040046 int string = loc.first_file, line = loc.first_line;
John Bauman89401822014-05-06 15:04:28 -040047
Nicolas Capens0bac2852016-05-07 06:09:58 -040048 TPersistStringStream stream;
49 if (line)
50 stream << string << ":" << line;
51 else
52 stream << string << ":? ";
53 stream << ": ";
John Bauman89401822014-05-06 15:04:28 -040054
Nicolas Capens0bac2852016-05-07 06:09:58 -040055 sink.append(stream.str());
John Bauman89401822014-05-06 15:04:28 -040056}
57
58void TInfoSinkBase::message(TPrefixType message, const char* s) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040059 prefix(message);
60 sink.append(s);
61 sink.append("\n");
John Bauman89401822014-05-06 15:04:28 -040062}
63
64void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040065 prefix(message);
66 location(loc);
67 sink.append(s);
68 sink.append("\n");
John Bauman89401822014-05-06 15:04:28 -040069}