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

« back to all changes in this revision

Viewing changes to AspectC++/IncludeGraph.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 __include_graph_h__
 
20
#define __include_graph_h__
 
21
 
 
22
// Visitor, which expands all project-local includes 
 
23
 
 
24
#include "Puma/PreVisitor.h"
 
25
namespace Puma {
 
26
  class CTranslationUnit;
 
27
  class Unit;
 
28
  class CProject;
 
29
}
 
30
using namespace Puma;
 
31
 
 
32
#include <map>
 
33
using std::map;
 
34
#include <set>
 
35
using std::set;
 
36
#include <iostream>
 
37
using std::ostream;
 
38
using std::endl;
 
39
 
 
40
class IncludeGraph : public PreVisitor {
 
41
 
 
42
  struct Node {
 
43
    const Unit *_unit;
 
44
    mutable bool _visited; // for cycle detection
 
45
    set<Node*> _includes;
 
46
    Node (const Unit *u) : _unit (u), _visited (false) {}
 
47
    void dump () const;
 
48
  };
 
49
  
 
50
  // associates a node object to each unit
 
51
  typedef map<const Unit*, Node> Map;
 
52
  Map _nodes;
 
53
  
 
54
  // the project to which all this belongs
 
55
  CProject &_project;
 
56
  
 
57
  // Go through the nodes of the syntax tree.
 
58
  void iterateNodes (PreTree*);
 
59
 
 
60
  // Visiting the parts of the preprocessor syntax tree.
 
61
  void visitPreIncludeDirective_Pre (PreIncludeDirective*);
 
62
 
 
63
  // find/create an entry in '_nodes'
 
64
  Node &find (const Unit*);
 
65
  
 
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;
 
68
 
 
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;
 
72
  
 
73
  // Reset the 'visited' flag of all nodes in the DAG
 
74
  void reset_visited () const;
 
75
  
 
76
public:
 
77
 
 
78
  IncludeGraph (CProject &p) : _project (p) {}
 
79
  IncludeGraph (CProject &p, CTranslationUnit &tunit) : _project (p) {
 
80
    init (tunit);
 
81
  }
 
82
  virtual ~IncludeGraph () {}
 
83
 
 
84
  // Fills the include graph
 
85
  void init (CTranslationUnit &tunit);
 
86
 
 
87
  // Checks whether on unit 'a' directly or indirecly includes another unit 'b'
 
88
  bool includes (const Unit *a, const Unit *b) const;
 
89
  
 
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;
 
93
 
 
94
  // Add an edge to the include graph from 'a' to 'b'
 
95
  void add_edge (const Unit *a, const Unit *b);
 
96
  
 
97
  // print all nodes
 
98
  void dump () const;
 
99
};          
 
100
 
 
101
#endif // __include_graph_h__