1
// This file is part of the AspectC++ compiler 'ac++'.
2
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License as
6
// published by the Free Software Foundation; either version 2 of
7
// the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public
15
// License along with this program; if not, write to the Free
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19
#ifndef __source_loc_h__
20
#define __source_loc_h__
27
enum SourceLocKind { SLK_DEF, SLK_DECL, SLK_NONE };
35
SourceLoc (int file_id, int line, int len, SourceLocKind kind) :
36
_file_id (file_id), _line (line), _len (len), _kind (kind) {}
38
SourceLoc (RepoXMLNode sn) {
39
_file_id = sn.get_int_prop ("file");
40
_line = sn.get_int_prop ("line");
41
_len = sn.get_int_prop ("len");
43
if (sn.has_prop ("kind")) {
44
string kind_str = sn.get_str_prop ("kind");
45
if (kind_str == "decl")
47
else if (kind_str == "def")
52
SourceLocKind kind() const { return _kind; }
53
void file (File *f) { _file_id = f->id (); }
54
int file_id () const { return _file_id; }
55
int line () const { return _line; }
56
int len () const { return _len; }
58
void print (int indent = 0) const {
59
for (int i = 0; i < indent; i++)
61
cout << "source file " << _file_id << " line " << _line << " len " << _len;
62
if (_kind != SLK_NONE)
63
cout << " kind " << (int)_kind;
67
void make_xml (RepoXMLNode parent) const {
68
RepoXMLNode fn = parent.make_child ("src");
69
fn.set_int_prop ("file", _file_id);
70
fn.set_int_prop ("line", _line);
71
fn.set_int_prop ("len", _len);
72
if (_kind != SLK_NONE)
73
fn.set_str_prop ("kind", _kind == SLK_DECL ? "decl" : "def");
76
bool operator < (const SourceLoc &sl) const {
77
return _kind < sl._kind ? true : (_line < sl._line ? true : (_file_id < sl._file_id));
79
bool operator == (const SourceLoc &sl) const {
80
return _kind == sl._kind && _line == sl._line && _file_id == sl._file_id;
84
#endif // __source_loc_h__