source: src/Common/CodeLocation.h @ 21f0aa8

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 21f0aa8 was 21f0aa8, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Seperated CodeLocation? out from the general utilities.

  • Property mode set to 100644
File size: 1.5 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 : Andrew Beach
12// Last Modified On : Thr Aug 17 14:07:00 2017
13// Update Count     : 0
14//
15
16#pragma once
17
18#include <string>
19
20struct 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
67inline std::string to_string( const CodeLocation& location ) {
68    return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
69}
70
Note: See TracBrowser for help on using the repository browser.