Add a reduceApply method
[oota-llvm.git] / include / llvm / Module.h
1 //===-- llvm/Module.h - C++ class to represent a VM module -------*- C++ -*--=//
2 //
3 // This file contains the declarations for the Module class that is used to 
4 // maintain all the information related to a VM module.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_MODULE_H
9 #define LLVM_MODULE_H
10
11 #include "llvm/SymTabValue.h"
12 class Method;
13
14 class Module : public SymTabValue {
15 public:
16   typedef ValueHolder<Method, Module> MethodListType;
17
18   // Method iterators...
19   typedef MethodListType::iterator iterator;
20   typedef MethodListType::const_iterator const_iterator;
21   typedef reverse_iterator<const_iterator> const_reverse_iterator;
22   typedef reverse_iterator<iterator>             reverse_iterator;
23 private:
24   MethodListType MethodList;     // The Methods
25
26 public:
27   Module();
28   ~Module();
29
30   // reduceApply - Apply the specified function to all of the methods in this 
31   // module.  The result values are or'd together and the result is returned.
32   //
33   bool reduceApply(bool (*Func)(Method*));
34   bool reduceApply(bool (*Func)(const Method*)) const;
35
36
37   // Get the underlying elements of the Module...
38   inline const MethodListType &getMethodList() const  { return MethodList; }
39   inline       MethodListType &getMethodList()        { return MethodList; }
40
41   //===--------------------------------------------------------------------===//
42   // Module iterator forwarding functions
43   //
44   inline iterator                begin()       { return MethodList.begin(); }
45   inline const_iterator          begin() const { return MethodList.begin(); }
46   inline iterator                end  ()       { return MethodList.end();   }
47   inline const_iterator          end  () const { return MethodList.end();   }
48
49   inline reverse_iterator       rbegin()       { return MethodList.rbegin(); }
50   inline const_reverse_iterator rbegin() const { return MethodList.rbegin(); }
51   inline reverse_iterator       rend  ()       { return MethodList.rend();   }
52   inline const_reverse_iterator rend  () const { return MethodList.rend();   }
53
54   inline unsigned                 size() const { return MethodList.size(); }
55   inline bool                    empty() const { return MethodList.empty(); }
56   inline const Method           *front() const { return MethodList.front(); }
57   inline       Method           *front()       { return MethodList.front(); }
58   inline const Method            *back() const { return MethodList.back(); }
59   inline       Method            *back()       { return MethodList.back(); }
60
61
62   // dropAllReferences() - This function causes all the subinstructions to "let
63   // go" of all references that they are maintaining.  This allows one to
64   // 'delete' a whole class at a time, even though there may be circular
65   // references... first all references are dropped, and all use counts go to
66   // zero.  Then everything is delete'd for real.  Note that no operations are
67   // valid on an object that has "dropped all references", except operator 
68   // delete.
69   //
70   void dropAllReferences();
71 };
72
73 #endif