Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/CodeLocation.h

    rd48e529 rb128d3e  
    1616#pragma once
    1717
    18 #include <iostream>
    1918#include <string>
    2019
    2120struct 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;
    2423
    2524        /// Create a new unset CodeLocation.
    26         CodeLocation() = default;
     25                CodeLocation()
     26                : linenumber( -1 )
     27                , filename("")
     28        {}
    2729
    2830        /// Create a new CodeLocation with the given values.
    2931        CodeLocation( const char* filename, int lineno )
    30                 : first_line( lineno )
     32                : linenumber( lineno )
    3133                , filename(filename ? filename : "")
    3234        {}
     
    3537
    3638        bool isSet () const {
    37                 return -1 != first_line;
     39                return -1 != linenumber;
    3840        }
    3941
     
    4244        }
    4345
     46        void unset () {
     47                linenumber = -1;
     48                filename = "";
     49        }
     50
     51        // Use field access for set.
     52
    4453        bool followedBy( CodeLocation const & other, int seperation ) {
    45                 return (first_line + seperation == other.first_line &&
     54                return (linenumber + seperation == other.linenumber &&
    4655                        filename == other.filename);
    4756        }
     
    5665};
    5766
    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;
     67inline 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 " : "";
    6170}
     71
Note: See TracChangeset for help on using the changeset viewer.