Implement "internal vs external linkage" which corresponds to the C notion of static
[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, bool hasInternalLinkage,
20               const string &name = "")
21     : User(Ty, vty, name), HasInternalLinkage(hasInternalLinkage), Parent(0) {}
22
23   bool HasInternalLinkage;    // Is this value accessable externally?
24   Module *Parent;
25 public:
26   ~GlobalValue() {}
27
28   // getType - Global values are always pointers.
29   inline const PointerType *getType() const {
30     return (const PointerType*)User::getType();
31   }
32
33   // Internal Linkage - True if the global value is inaccessible to 
34   bool hasInternalLinkage() const { return HasInternalLinkage; }
35   bool hasExternalLinkage() const { return !HasInternalLinkage; }
36   void setInternalLinkage(bool HIL) { HasInternalLinkage = HIL; }
37
38   // Get the module that this global value is contained inside of...
39   inline Module *getParent() { return Parent; }
40   inline const Module *getParent() const { return Parent; }
41
42   // Methods for support type inquiry through isa, cast, and dyn_cast:
43   static inline bool classof(const GlobalValue *T) { return true; }
44   static inline bool classof(const Value *V) {
45     return V->getValueType() == Value::MethodVal || 
46            V->getValueType() == Value::GlobalVariableVal;
47   }
48 };
49
50 #endif