Make isExtern() be a virtual function inherited from 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 Function.  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 class Module;
16
17 class GlobalValue : public User {
18   GlobalValue(const GlobalValue &);             // do not implement
19 protected:
20   GlobalValue(const Type *Ty, ValueTy vty, bool hasInternalLinkage,
21               const std::string &name = "")
22     : User(Ty, vty, name), HasInternalLinkage(hasInternalLinkage), Parent(0) {}
23
24   bool HasInternalLinkage;    // Is this value accessable externally?
25   Module *Parent;
26 public:
27   ~GlobalValue() {}
28
29   /// getType - Global values are always pointers.
30   inline const PointerType *getType() const {
31     return (const PointerType*)User::getType();
32   }
33
34   /// Internal Linkage - True if the global value is inaccessible to 
35   bool hasInternalLinkage() const { return HasInternalLinkage; }
36   bool hasExternalLinkage() const { return !HasInternalLinkage; }
37   void setInternalLinkage(bool HIL) { HasInternalLinkage = HIL; }
38
39   /// isExternal - Return true if the primary definition of this global value is
40   /// outside of the current translation unit...
41   virtual bool isExternal() const = 0;
42
43   /// getParent - Get the module that this global value is contained inside
44   /// of...
45   inline Module *getParent() { return Parent; }
46   inline const Module *getParent() const { return Parent; }
47
48   // Methods for support type inquiry through isa, cast, and dyn_cast:
49   static inline bool classof(const GlobalValue *T) { return true; }
50   static inline bool classof(const Value *V) {
51     return V->getValueType() == Value::FunctionVal || 
52            V->getValueType() == Value::GlobalVariableVal;
53   }
54 };
55
56 #endif