• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
prefix(TPrefixType message)17 void TInfoSinkBase::prefix(TPrefixType message) {
18 	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 	}
40 }
41 
location(const TSourceLoc & loc)42 void TInfoSinkBase::location(const TSourceLoc& loc) {
43 	int string = loc.first_file, line = loc.first_line;
44 
45 	TPersistStringStream stream;
46 	if (line)
47 		stream << string << ":" << line;
48 	else
49 		stream << string << ":? ";
50 	stream << ": ";
51 
52 	sink.append(stream.str());
53 }
54 
message(TPrefixType message,const char * s)55 void TInfoSinkBase::message(TPrefixType message, const char* s) {
56 	prefix(message);
57 	sink.append(s);
58 	sink.append("\n");
59 }
60 
message(TPrefixType message,const char * s,TSourceLoc loc)61 void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) {
62 	prefix(message);
63 	location(loc);
64 	sink.append(s);
65 	sink.append("\n");
66 }
67