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 ( 25 os.path.exists(self.path) 26 and os.path.exists(rhs.path) 27 and os.path.samefile(self.path, rhs.path) 28 and self.lineno == rhs.lineno 29 and self.column == rhs.column 30 ) 31 32 def __lt__(self, rhs): 33 if self.path != rhs.path: 34 return False 35 36 if self.lineno == rhs.lineno: 37 return self.column < rhs.column 38 39 return self.lineno < rhs.lineno 40 41 def __gt__(self, rhs): 42 if self.path != rhs.path: 43 return False 44 45 if self.lineno == rhs.lineno: 46 return self.column > rhs.column 47 48 return self.lineno > rhs.lineno 49