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
with_gc
Last change
on this file since 982832e was b128d3e, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago |
remove contraction from error message
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
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 <string>
|
---|
19 |
|
---|
20 | struct CodeLocation {
|
---|
21 | int linenumber;
|
---|
22 | std::string filename;
|
---|
23 |
|
---|
24 | /// Create a new unset CodeLocation.
|
---|
25 | CodeLocation()
|
---|
26 | : linenumber( -1 )
|
---|
27 | , filename("")
|
---|
28 | {}
|
---|
29 |
|
---|
30 | /// Create a new CodeLocation with the given values.
|
---|
31 | CodeLocation( const char* filename, int lineno )
|
---|
32 | : linenumber( lineno )
|
---|
33 | , filename(filename ? filename : "")
|
---|
34 | {}
|
---|
35 |
|
---|
36 | CodeLocation( const CodeLocation& rhs ) = default;
|
---|
37 |
|
---|
38 | bool isSet () const {
|
---|
39 | return -1 != linenumber;
|
---|
40 | }
|
---|
41 |
|
---|
42 | bool isUnset () const {
|
---|
43 | return !isSet();
|
---|
44 | }
|
---|
45 |
|
---|
46 | void unset () {
|
---|
47 | linenumber = -1;
|
---|
48 | filename = "";
|
---|
49 | }
|
---|
50 |
|
---|
51 | // Use field access for set.
|
---|
52 |
|
---|
53 | bool followedBy( CodeLocation const & other, int seperation ) {
|
---|
54 | return (linenumber + seperation == other.linenumber &&
|
---|
55 | filename == other.filename);
|
---|
56 | }
|
---|
57 |
|
---|
58 | bool operator==( CodeLocation const & other ) {
|
---|
59 | return followedBy( other, 0 );
|
---|
60 | }
|
---|
61 |
|
---|
62 | bool operator!=( CodeLocation const & other ) {
|
---|
63 | return !(*this == other);
|
---|
64 | }
|
---|
65 | };
|
---|
66 |
|
---|
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 " : "";
|
---|
70 | }
|
---|
71 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.