• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 #ifndef VK_DEBUG_LOCATION_HPP_
16 #define VK_DEBUG_LOCATION_HPP_
17 
18 #include <memory>
19 
20 namespace vk {
21 namespace dbg {
22 
23 class File;
24 
25 // Location holds a file path and line number.
26 struct Location
27 {
28 	Location() = default;
29 	inline Location(const std::shared_ptr<File> &file, int line, int column = 0);
30 
31 	inline bool operator==(const Location &o) const;
32 	inline bool operator!=(const Location &o) const;
33 	inline bool operator<(const Location &o) const;
34 
35 	std::shared_ptr<File> file;
36 	int line = 0;    // 1 based. 0 represents no line.
37 	int column = 0;  // 1 based. 0 represents no particular column.
38 };
39 
Location(const std::shared_ptr<File> & file,int line,int column)40 Location::Location(const std::shared_ptr<File> &file, int line, int column /* = 0 */)
41     : file(file)
42     , line(line)
43     , column(column)
44 {}
45 
operator ==(const Location & o) const46 bool Location::operator==(const Location &o) const
47 {
48 	return file == o.file && line == o.line && column == o.column;
49 }
50 
operator !=(const Location & o) const51 bool Location::operator!=(const Location &o) const
52 {
53 	return !(*this == o);
54 }
55 
operator <(const Location & o) const56 bool Location::operator<(const Location &o) const
57 {
58 	if(file.get() < o.file.get()) { return true; }
59 	if(file.get() > o.file.get()) { return false; }
60 
61 	if(line < o.line) { return true; }
62 	if(line > o.line) { return false; }
63 
64 	if(column < o.column) { return true; }
65 	if(column > o.column) { return false; }
66 
67 	return true;
68 }
69 
70 }  // namespace dbg
71 }  // namespace vk
72 
73 namespace std {
74 
75 template<>
76 struct hash<vk::dbg::Location>
77 {
operator ()std::hash78 	size_t operator()(const vk::dbg::Location &l) const
79 	{
80 		auto h = std::hash<vk::dbg::File *>()(l.file.get());
81 		h = h * 31 + l.line;
82 		h = h * 31 + l.column;
83 		return h;
84 	}
85 };
86 
87 }  // namespace std
88 
89 #endif  // VK_DEBUG_LOCATION_HPP_
90