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 __include_graph_h__
20
#define __include_graph_h__
22
// Visitor, which expands all project-local includes
24
#include "Puma/PreVisitor.h"
26
class CTranslationUnit;
40
class IncludeGraph : public PreVisitor {
44
mutable bool _visited; // for cycle detection
46
Node (const Unit *u) : _unit (u), _visited (false) {}
50
// associates a node object to each unit
51
typedef map<const Unit*, Node> Map;
54
// the project to which all this belongs
57
// Go through the nodes of the syntax tree.
58
void iterateNodes (PreTree*);
60
// Visiting the parts of the preprocessor syntax tree.
61
void visitPreIncludeDirective_Pre (PreIncludeDirective*);
63
// find/create an entry in '_nodes'
64
Node &find (const Unit*);
66
// Checks whether there is a path from node 'a' to 'b' in the include graph
67
bool includes (const Node &a, const Node &b) const;
69
// collect all units included by some node
70
void included_files (const Node &node, set<const Unit*> &units,
71
bool only_project = true) const;
73
// Reset the 'visited' flag of all nodes in the DAG
74
void reset_visited () const;
78
IncludeGraph (CProject &p) : _project (p) {}
79
IncludeGraph (CProject &p, CTranslationUnit &tunit) : _project (p) {
82
virtual ~IncludeGraph () {}
84
// Fills the include graph
85
void init (CTranslationUnit &tunit);
87
// Checks whether on unit 'a' directly or indirecly includes another unit 'b'
88
bool includes (const Unit *a, const Unit *b) const;
90
// Get all files the are directly or indirectly included
91
bool included_files (const Unit *unit, set<const Unit*> &units,
92
bool only_project = true) const;
94
// Add an edge to the include graph from 'a' to 'b'
95
void add_edge (const Unit *a, const Unit *b);
101
#endif // __include_graph_h__