* ValueHolder now takes 3 arguments
[oota-llvm.git] / lib / VMCore / Module.cpp
1 //===-- Module.cpp - Implement the Module class ------------------*- C++ -*--=//
2 //
3 // This file implements the Module class for the VMCore library.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/Module.h"
8 #include "llvm/Method.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/InstrTypes.h"
11 #include "llvm/ValueHolderImpl.h"
12 #include "llvm/Tools/STLExtras.h"
13
14 // Instantiate Templates - This ugliness is the price we have to pay
15 // for having a DefHolderImpl.h file seperate from DefHolder.h!  :(
16 //
17 template class ValueHolder<Method, Module, Module>;
18
19 Module::Module()
20   : Value(0/*TODO: REAL TYPE*/, Value::ModuleVal, ""), SymTabValue(this),
21     MethodList(this, this) {
22 }
23
24 Module::~Module() {
25   dropAllReferences();
26   MethodList.delete_all();
27   MethodList.setParent(0);
28 }
29
30
31 // dropAllReferences() - This function causes all the subinstructions to "let
32 // go" of all references that they are maintaining.  This allows one to
33 // 'delete' a whole class at a time, even though there may be circular
34 // references... first all references are dropped, and all use counts go to
35 // zero.  Then everything is delete'd for real.  Note that no operations are
36 // valid on an object that has "dropped all references", except operator 
37 // delete.
38 //
39 void Module::dropAllReferences() {
40   MethodListType::iterator MI = MethodList.begin();
41   for (; MI != MethodList.end(); ++MI)
42     (*MI)->dropAllReferences();
43 }
44
45 // reduceApply - Apply the specified function to all of the methods in this 
46 // module.  The result values are or'd together and the result is returned.
47 //
48 bool Module::reduceApply(bool (*Func)(Method*)) {
49   return reduce_apply_bool(begin(), end(), Func);
50 }
51 bool Module::reduceApply(bool (*Func)(const Method*)) const {
52   return reduce_apply_bool(begin(), end(), Func);
53 }
54