Changes in src/Common/CodeLocation.h [d48e529:b128d3e]
- File:
-
- 1 edited
-
src/Common/CodeLocation.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/CodeLocation.h
rd48e529 rb128d3e 16 16 #pragma once 17 17 18 #include <iostream>19 18 #include <string> 20 19 21 20 struct CodeLocation { 22 int first_line = -1, first_column = -1, last_line = -1, last_column = -1;23 std::string filename = "";21 int linenumber; 22 std::string filename; 24 23 25 24 /// Create a new unset CodeLocation. 26 CodeLocation() = default; 25 CodeLocation() 26 : linenumber( -1 ) 27 , filename("") 28 {} 27 29 28 30 /// Create a new CodeLocation with the given values. 29 31 CodeLocation( const char* filename, int lineno ) 30 : first_line( lineno )32 : linenumber( lineno ) 31 33 , filename(filename ? filename : "") 32 34 {} … … 35 37 36 38 bool isSet () const { 37 return -1 != first_line;39 return -1 != linenumber; 38 40 } 39 41 … … 42 44 } 43 45 46 void unset () { 47 linenumber = -1; 48 filename = ""; 49 } 50 51 // Use field access for set. 52 44 53 bool followedBy( CodeLocation const & other, int seperation ) { 45 return ( first_line + seperation == other.first_line&&54 return (linenumber + seperation == other.linenumber && 46 55 filename == other.filename); 47 56 } … … 56 65 }; 57 66 58 inline std:: ostream & operator<<( std::ostream & out, const CodeLocation& location ) {59 // Column number ":1" allows IDEs to parse the error message and position the cursor in the source text.60 return location.isSet() ? out << location.filename << ":" << location.first_line << ":1 " : out;67 inline std::string to_string( const CodeLocation& location ) { 68 // Column number ":1" allows IDEs to parse the error message and position the cursor in the source text. 69 return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + ":1 " : ""; 61 70 } 71
Note:
See TracChangeset
for help on using the changeset viewer.