ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
stuck-waitfor-destruct
with_gc
| Line | |
|---|
| 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
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Mon Aug 28 12:46:01 2017
|
|---|
| 13 | // Update Count : 2
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include <iostream>
|
|---|
| 19 | #include <string>
|
|---|
| 20 |
|
|---|
| 21 | struct CodeLocation {
|
|---|
| 22 | int linenumber;
|
|---|
| 23 | std::string filename;
|
|---|
| 24 |
|
|---|
| 25 | /// Create a new unset CodeLocation.
|
|---|
| 26 | CodeLocation()
|
|---|
| 27 | : linenumber( -1 )
|
|---|
| 28 | , filename("")
|
|---|
| 29 | {}
|
|---|
| 30 |
|
|---|
| 31 | /// Create a new CodeLocation with the given values.
|
|---|
| 32 | CodeLocation( const char* filename, int lineno )
|
|---|
| 33 | : linenumber( lineno )
|
|---|
| 34 | , filename(filename ? filename : "")
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | CodeLocation( const CodeLocation& rhs ) = default;
|
|---|
| 38 |
|
|---|
| 39 | bool isSet () const {
|
|---|
| 40 | return -1 != linenumber;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | bool isUnset () const {
|
|---|
| 44 | return !isSet();
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | bool followedBy( CodeLocation const & other, int seperation ) {
|
|---|
| 48 | return (linenumber + seperation == other.linenumber &&
|
|---|
| 49 | filename == other.filename);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | bool operator==( CodeLocation const & other ) {
|
|---|
| 53 | return followedBy( other, 0 );
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | bool operator!=( CodeLocation const & other ) {
|
|---|
| 57 | return !(*this == other);
|
|---|
| 58 | }
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | inline std::ostream & operator<<( std::ostream & out, const CodeLocation & location ) {
|
|---|
| 62 | // Column number ":1" allows IDEs to parse the error message and position the cursor in the source text.
|
|---|
| 63 | return location.isSet() ? out << location.filename << ":" << location.linenumber << ":1 " : out;
|
|---|
| 64 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.