1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
#ifndef __File_h__
#define __File_h__
#ifndef ACMODEL
#include <string>
using std::string;
#include <set>
using std::set;
#include <iostream>
using std::cout;
#include "RepoXMLNode.h"
#include "JoinPointModelElement.h"
class File : public JoinPointModelElement {
string _file_name;
int _len;
set<int> _tunits; // set for header files => which tunits include this file?
bool _is_tunit;
public:
File () {}
File (const string &file_name, int len, bool is_tunit) :
_file_name (file_name), _len (len), _is_tunit (is_tunit) {}
const string &name () const { return _file_name; }
int len () const { return _len; }
bool is_tunit () const { return _is_tunit; }
bool is_in_no_tunit () const { return !_is_tunit && _tunits.size () == 0; }
bool is_known_in_tunit (File *tunit) const {
return (_is_tunit && tunit->id () == id ()) ||
(!_is_tunit && _tunits.find (tunit->id ()) != _tunits.end ());
}
void included_by (File *f) { _tunits.insert (f->id ()); }
void not_included_by (File *f) { _tunits.erase (f->id ()); }
void print (int indent = 0) const {
for (int i = 0; i < indent; i++)
cout << " ";
cout << (is_tunit () ? "tunit " : "header ") << id () << " name "
<< _file_name << " len " << _len;
if (!is_tunit ()) {
cout << " tunits";
for (set<int>::const_iterator i = _tunits.begin ();
i != _tunits.end (); ++i)
cout << " " << *i;
cout << endl;
}
}
bool operator < (const File &f) const {
return _file_name < f._file_name;
}
bool operator == (const File &f) const {
return _file_name == f._file_name;
}
void to_xml (RepoXMLNode parent) const {
RepoXMLNode fn = parent.make_child (is_tunit () ? "tunit" : "header");
fn.set_int_prop ("id", id ());
fn.set_str_prop ("name", _file_name.c_str ());
fn.set_int_prop ("len", _len);
if (!is_tunit ()) {
ostringstream buf;
for (set<int>::const_iterator i = _tunits.begin ();
i != _tunits.end (); ++i) {
if (i != _tunits.begin ())
buf << " ";
buf << *i;
}
fn.set_str_prop ("tunits", buf.str ().c_str ());
}
}
void from_xml (RepoXMLNode fn) {
_is_tunit = fn.has_name ("tunit");
id (fn.get_int_prop ("id"));
_len = fn.get_int_prop ("len");
_file_name = fn.get_str_prop ("name");
if (fn.has_prop ("tunits")) {
string tunits = fn.get_str_prop ("tunits");
istringstream in (tunits, istringstream::in);
int id;
while (!in.eof ()) {
in >> id;
if (!in.fail ())
_tunits.insert (id);
}
}
}
};
#endif // !ACMODEL
#endif // __File_h__
|