~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to AspectC++/SourceLoc.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of the AspectC++ compiler 'ac++'.
 
2
// Copyright (C) 1999-2003  The 'ac++' developers (see aspectc.org)
 
3
//                                                                
 
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.            
 
8
//                                                                
 
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.                   
 
13
//                                                                
 
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, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __source_loc_h__
 
20
#define __source_loc_h__
 
21
 
 
22
#include "File.h"
 
23
 
 
24
#include <string>
 
25
using std::string;
 
26
 
 
27
enum SourceLocKind { SLK_DEF, SLK_DECL, SLK_NONE };
 
28
 
 
29
class SourceLoc {
 
30
  int _file_id;
 
31
  int _line;
 
32
  int _len;
 
33
  SourceLocKind _kind;
 
34
public:
 
35
  SourceLoc (int file_id, int line, int len, SourceLocKind kind) :
 
36
    _file_id (file_id), _line (line), _len (len), _kind (kind) {}
 
37
 
 
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");
 
42
    _kind = SLK_NONE;
 
43
    if (sn.has_prop ("kind")) {
 
44
      string kind_str = sn.get_str_prop ("kind");
 
45
      if (kind_str == "decl")
 
46
        _kind = SLK_DECL;
 
47
      else if (kind_str == "def")
 
48
        _kind = SLK_DEF;
 
49
    }
 
50
  }
 
51
      
 
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; }
 
57
  
 
58
  void print (int indent = 0) const {
 
59
    for (int i = 0; i < indent; i++)
 
60
      cout << "  ";
 
61
    cout << "source file " << _file_id << " line " << _line << " len " << _len;
 
62
    if (_kind != SLK_NONE)
 
63
      cout << " kind " << (int)_kind;
 
64
    cout << endl;
 
65
  }
 
66
 
 
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");
 
74
  }
 
75
 
 
76
  bool operator < (const SourceLoc &sl) const {
 
77
    return _kind < sl._kind ? true : (_line < sl._line ? true : (_file_id < sl._file_id));
 
78
  }
 
79
  bool operator == (const SourceLoc &sl) const {
 
80
    return _kind == sl._kind && _line == sl._line && _file_id == sl._file_id;
 
81
  }
 
82
};
 
83
 
 
84
#endif // __source_loc_h__