source: src/Common/CodeLocation.h@ c655650

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since c655650 was 968f280, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Made some implicit methods explicit due to clang warning

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[21f0aa8]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// CodeLocation.h --
8//
9// Author : Andrew Beach
10// Created On : Thr Aug 17 11:23:00 2017
[b128d3e]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Aug 28 12:46:01 2017
13// Update Count : 2
[21f0aa8]14//
15
16#pragma once
17
[80ac42d]18#include <iostream>
[21f0aa8]19#include <string>
20
21struct CodeLocation {
[d48e529]22 int first_line = -1, first_column = -1, last_line = -1, last_column = -1;
23 std::string filename = "";
[21f0aa8]24
25 /// Create a new unset CodeLocation.
[d48e529]26 CodeLocation() = default;
[21f0aa8]27
[968f280]28
[21f0aa8]29 /// Create a new CodeLocation with the given values.
30 CodeLocation( const char* filename, int lineno )
[d48e529]31 : first_line( lineno )
[21f0aa8]32 , filename(filename ? filename : "")
33 {}
34
35 CodeLocation( const CodeLocation& rhs ) = default;
[968f280]36 CodeLocation( CodeLocation&& rhs ) = default;
37 CodeLocation& operator=( const CodeLocation & ) = default;
38 CodeLocation& operator=( CodeLocation && ) = default;
[21f0aa8]39
40 bool isSet () const {
[d48e529]41 return -1 != first_line;
[21f0aa8]42 }
43
44 bool isUnset () const {
45 return !isSet();
46 }
47
[ddcedfe]48 bool startsBefore( CodeLocation const & other ) const {
49 if( filename < other.filename ) return true;
50 if( filename > other.filename ) return false;
51
52 if( first_line < other.first_line ) return true;
53 if( first_line > other.first_line ) return false;
54
55 if( last_line < other.last_line ) return true;
56 return false;
57 }
58
59 bool followedBy( CodeLocation const & other, int seperation ) const {
[d48e529]60 return (first_line + seperation == other.first_line &&
[21f0aa8]61 filename == other.filename);
62 }
63
[ddcedfe]64 bool operator==( CodeLocation const & other ) const {
[21f0aa8]65 return followedBy( other, 0 );
66 }
67
[ddcedfe]68 bool operator!=( CodeLocation const & other ) const {
[21f0aa8]69 return !(*this == other);
70 }
71};
72
[80ac42d]73inline std::ostream & operator<<( std::ostream & out, const CodeLocation & location ) {
74 // Column number ":1" allows IDEs to parse the error message and position the cursor in the source text.
[d48e529]75 return location.isSet() ? out << location.filename << ":" << location.first_line << ":1 " : out;
[21f0aa8]76}
Note: See TracBrowser for help on using the repository browser.