ADT
        arm-eh
        ast-experimental
        cleanup-dtors
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since 23f99e1 was             d48e529, checked in by Rob Schluntz <rschlunt@…>, 8 years ago           | 
        
        
          | 
             
Begin to introduce support for yylloc in the parser and extend CodeLocation to include start column and end column/line number information 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.6 KB
           | 
        
      
      
| Rev | Line |   | 
|---|
| [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 | 
 | 
|---|
 | 21 | struct 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 | 
 | 
|---|
 | 28 |         /// Create a new CodeLocation with the given values.
 | 
|---|
 | 29 |         CodeLocation( const char* filename, int lineno )
 | 
|---|
| [d48e529] | 30 |                 : first_line( lineno )
 | 
|---|
| [21f0aa8] | 31 |                 , filename(filename ? filename : "")
 | 
|---|
 | 32 |         {}
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |         CodeLocation( const CodeLocation& rhs ) = default;
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |         bool isSet () const {
 | 
|---|
| [d48e529] | 37 |                 return -1 != first_line;
 | 
|---|
| [21f0aa8] | 38 |         }
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |         bool isUnset () const {
 | 
|---|
 | 41 |                 return !isSet();
 | 
|---|
 | 42 |         }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |         bool followedBy( CodeLocation const & other, int seperation ) {
 | 
|---|
| [d48e529] | 45 |                 return (first_line + seperation == other.first_line &&
 | 
|---|
| [21f0aa8] | 46 |                         filename == other.filename);
 | 
|---|
 | 47 |         }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |         bool operator==( CodeLocation const & other ) {
 | 
|---|
 | 50 |                 return followedBy( other, 0 );
 | 
|---|
 | 51 |         }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 |         bool operator!=( CodeLocation const & other ) {
 | 
|---|
 | 54 |                 return !(*this == other);
 | 
|---|
 | 55 |         }
 | 
|---|
 | 56 | };
 | 
|---|
 | 57 | 
 | 
|---|
| [80ac42d] | 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.
 | 
|---|
| [d48e529] | 60 |         return location.isSet() ? out << location.filename << ":" << location.first_line << ":1 " : out;
 | 
|---|
| [21f0aa8] | 61 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.