1# DExTer : Debugging Experience Tester 2# ~~~~~~ ~ ~~ ~ ~~ 3# 4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5# See https://llvm.org/LICENSE.txt for license information. 6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7import os 8 9 10class LocIR: 11 """Data class which represents a source location.""" 12 13 def __init__(self, path: str, lineno: int, column: int): 14 if path: 15 path = os.path.normcase(path) 16 self.path = path 17 self.lineno = lineno 18 self.column = column 19 20 def __str__(self): 21 return '{}({}:{})'.format(self.path, self.lineno, self.column) 22 23 def __eq__(self, rhs): 24 return (os.path.exists(self.path) and os.path.exists(rhs.path) 25 and os.path.samefile(self.path, rhs.path) 26 and self.lineno == rhs.lineno 27 and self.column == rhs.column) 28 29 def __lt__(self, rhs): 30 if self.path != rhs.path: 31 return False 32 33 if self.lineno == rhs.lineno: 34 return self.column < rhs.column 35 36 return self.lineno < rhs.lineno 37 38 def __gt__(self, rhs): 39 if self.path != rhs.path: 40 return False 41 42 if self.lineno == rhs.lineno: 43 return self.column > rhs.column 44 45 return self.lineno > rhs.lineno 46