Standardize header file comments
[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 public:
20   enum LinkageTypes {
21     ExternalLinkage,   // Externally visible function
22     LinkOnceLinkage,   // Keep one copy of named function when linking (inline)
23     AppendingLinkage,  // Special purpose, only applies to global arrays
24     InternalLinkage    // Rename collisions when linking (static functions)
25   };
26 protected:
27   GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
28               const std::string &name = "")
29     : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
30
31   LinkageTypes Linkage;   // The linkage of this global
32   Module *Parent;
33 public:
34   ~GlobalValue() {}
35
36   /// getType - Global values are always pointers.
37   inline const PointerType *getType() const {
38     return (const PointerType*)User::getType();
39   }
40
41   bool hasExternalLinkage()  const { return Linkage == ExternalLinkage; }
42   bool hasLinkOnceLinkage()  const { return Linkage == LinkOnceLinkage; }
43   bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
44   bool hasInternalLinkage()  const { return Linkage == InternalLinkage; }
45   void setLinkage(LinkageTypes LT) { Linkage = LT; }
46   LinkageTypes getLinkage() const { return Linkage; }
47
48   /// isExternal - Return true if the primary definition of this global value is
49   /// outside of the current translation unit...
50   virtual bool isExternal() const = 0;
51
52   /// getParent - Get the module that this global value is contained inside
53   /// of...
54   inline Module *getParent() { return Parent; }
55   inline const Module *getParent() const { return Parent; }
56
57   // Methods for support type inquiry through isa, cast, and dyn_cast:
58   static inline bool classof(const GlobalValue *T) { return true; }
59   static inline bool classof(const Value *V) {
60     return V->getValueType() == Value::FunctionVal || 
61            V->getValueType() == Value::GlobalVariableVal;
62   }
63 };
64
65 #endif