Factor parentness out of Module & GlobalVariable into GlobalValue
[oota-llvm.git] / include / llvm / GlobalValue.h
1 //===-- llvm/GlobalValue.h - Class to represent a global value ---*- C++ -*--=//
2 //
3 // This file is a common base class of all globally definable objects.  As such,
4 // it is subclassed by GlobalVariable and by Method.  This is used because you
5 // can do certain things with these global objects that you can't do to anything
6 // else.  For example, use the address of one as a constant.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_GLOBALVALUE_H
11 #define LLVM_GLOBALVALUE_H
12
13 #include "llvm/User.h"
14 class PointerType;
15
16 class GlobalValue : public User {
17   GlobalValue(const GlobalValue &);             // do not implement
18 protected:
19   GlobalValue(const Type *Ty, ValueTy vty, const string &name = "")
20     : User(Ty, vty, name) { Parent = 0; }
21
22   Module *Parent;
23 public:
24   ~GlobalValue() {}
25
26   // getType - Global values are always pointers.
27   inline const PointerType *getType() const {
28     return (const PointerType*)User::getType();
29   }
30
31   // Get the module that this global value is contained inside of...
32   inline Module *getParent() { return Parent; }
33   inline const Module *getParent() const { return Parent; }
34
35   // Methods for support type inquiry through isa, cast, and dyn_cast:
36   static inline bool classof(const GlobalValue *T) { return true; }
37   static inline bool classof(const Value *V) {
38     return V->getValueType() == Value::MethodVal || 
39            V->getValueType() == Value::GlobalVariableVal;
40   }
41 };
42
43 #endif