19
19
#ifndef __location_h__
20
20
#define __location_h__
22
#include "Puma/SmartPtr.h"
23
#include "Puma/Printable.h"
24
#include "Puma/LocationInfo.h"
22
#include "Puma/Filename.h"
29
class Location : public SmartPtr, public Printable {
30
LocationInfo *info () const { return (LocationInfo*)data (); }
34
Location (Filename f, int l) { setup (f, l); }
35
Location (LocationInfo *lptr) : SmartPtr (lptr) {}
36
LocationInfo *operator ~ () { if (info ()) info ()->ref (); return info (); }
37
void setup (Filename f, int l);
38
const Filename &filename () const { return info ()->filename (); }
40
bool operator == (const Location &l) const;
33
Location () : _filename (), _line (0), _column (0) {}
34
Location (Filename f, int l, int c = 0) { setup (f, l, c); }
35
void setup (Filename f, int l, int c = 0) {
40
const Filename &filename () const { return _filename; }
41
int line () const { return _line; }
42
int column () const { return _column; }
43
bool operator == (const Location &l) const {
44
return filename () == l.filename () && line () == l.line () &&
45
column () == l.column ();
41
47
bool operator != (const Location &l) const { return ! (*this == l); }
42
bool operator < (const Location &l) const;
48
bool operator < (const Location &l) const {
49
// TODO: does it make sense to compare the filenames? better assert?
50
if (filename () != l.filename ())
52
return line () < l.line () && column () < l.column ();
44
virtual void print (ostream &os) const {
56
inline std::ostream &operator << (std::ostream &os, const Location &loc) {
46
57
#ifdef VISUAL_STUDIO
47
os << filename () << "(" << line () << ")";
58
os << loc.filename () << "(" << loc.line () << ")";
49
os << filename () << ":" << line ();
60
os << loc.filename () << ":" << loc.line ();
55
64
} // namespace Puma
57
66
#endif /* __location_h__ */