Commit more code over to new cast style
[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/Value.h"
12 #include "llvm/SymTabValue.h"
13 #include "llvm/ValueHolder.h"
14 class Method;
15 class GlobalVariable;
16
17 class Module : public Value, public SymTabValue {
18 public:
19   typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType;
20   typedef ValueHolder<Method, Module, Module> MethodListType;
21
22   // Global Variable iterators...
23   typedef GlobalListType::iterator                        giterator;
24   typedef GlobalListType::const_iterator            const_giterator;
25   typedef reverse_iterator<giterator>             reverse_giterator;
26   typedef reverse_iterator<const_giterator> const_reverse_giterator;
27
28   // Method iterators...
29   typedef MethodListType::iterator                       iterator;
30   typedef MethodListType::const_iterator           const_iterator;
31   typedef reverse_iterator<const_iterator> const_reverse_iterator;
32   typedef reverse_iterator<iterator>             reverse_iterator;
33
34 private:
35   GlobalListType GlobalList;     // The Global Variables
36   MethodListType MethodList;     // The Methods
37
38 public:
39   Module();
40   ~Module();
41
42   // reduceApply - Apply the specified function to all of the methods in this 
43   // module.  The result values are or'd together and the result is returned.
44   //
45   bool reduceApply(bool (*Func)(GlobalVariable*));
46   bool reduceApply(bool (*Func)(const GlobalVariable*)) const;
47   bool reduceApply(bool (*Func)(Method*));
48   bool reduceApply(bool (*Func)(const Method*)) const;
49
50
51   // Get the underlying elements of the Module...
52   inline const GlobalListType &getGlobalList() const  { return GlobalList; }
53   inline       GlobalListType &getGlobalList()        { return GlobalList; }
54   inline const MethodListType &getMethodList() const  { return MethodList; }
55   inline       MethodListType &getMethodList()        { return MethodList; }
56
57   //===--------------------------------------------------------------------===//
58   // Module iterator forwarding functions
59   //
60   inline giterator                gbegin()       { return GlobalList.begin(); }
61   inline const_giterator          gbegin() const { return GlobalList.begin(); }
62   inline giterator                gend  ()       { return GlobalList.end();   }
63   inline const_giterator          gend  () const { return GlobalList.end();   }
64
65   inline reverse_giterator       grbegin()       { return GlobalList.rbegin(); }
66   inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); }
67   inline reverse_giterator       grend  ()       { return GlobalList.rend();   }
68   inline const_reverse_giterator grend  () const { return GlobalList.rend();   }
69
70   inline unsigned                  gsize() const { return GlobalList.size(); }
71   inline bool                     gempty() const { return GlobalList.empty(); }
72   inline const GlobalVariable    *gfront() const { return GlobalList.front(); }
73   inline       GlobalVariable    *gfront()       { return GlobalList.front(); }
74   inline const GlobalVariable     *gback() const { return GlobalList.back(); }
75   inline       GlobalVariable     *gback()       { return GlobalList.back(); }
76
77
78
79   inline iterator                begin()       { return MethodList.begin(); }
80   inline const_iterator          begin() const { return MethodList.begin(); }
81   inline iterator                end  ()       { return MethodList.end();   }
82   inline const_iterator          end  () const { return MethodList.end();   }
83
84   inline reverse_iterator       rbegin()       { return MethodList.rbegin(); }
85   inline const_reverse_iterator rbegin() const { return MethodList.rbegin(); }
86   inline reverse_iterator       rend  ()       { return MethodList.rend();   }
87   inline const_reverse_iterator rend  () const { return MethodList.rend();   }
88
89   inline unsigned                 size() const { return MethodList.size(); }
90   inline bool                    empty() const { return MethodList.empty(); }
91   inline const Method           *front() const { return MethodList.front(); }
92   inline       Method           *front()       { return MethodList.front(); }
93   inline const Method            *back() const { return MethodList.back(); }
94   inline       Method            *back()       { return MethodList.back(); }
95
96   // Methods for support type inquiry through isa, cast, and dyn_cast:
97   static inline bool classof(const Module *T) { return true; }
98   static inline bool classof(const Value *V) {
99     return V->getValueType() == Value::ModuleVal;
100   }
101
102   // dropAllReferences() - This function causes all the subinstructions to "let
103   // go" of all references that they are maintaining.  This allows one to
104   // 'delete' a whole class at a time, even though there may be circular
105   // references... first all references are dropped, and all use counts go to
106   // zero.  Then everything is delete'd for real.  Note that no operations are
107   // valid on an object that has "dropped all references", except operator 
108   // delete.
109   //
110   void dropAllReferences();
111 };
112
113 #endif