eae4b7357e6ef84291ddc983d6f9e618f94d61ab
[oota-llvm.git] / include / llvm / DerivedTypes.h
1 //===-- llvm/DerivedTypes.h - Classes for handling data types ----*- C++ -*--=//
2 //
3 // This file contains the declarations of classes that represent "derived 
4 // types".  These are things like "arrays of x" or "structure of x, y, z" or
5 // "method returning x taking (y,z) as parameters", etc...
6 //
7 // The implementations of these classes live in the Type.cpp file.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_DERIVED_TYPES_H
12 #define LLVM_DERIVED_TYPES_H
13
14 #include "llvm/Type.h"
15 #include <vector>
16
17 // Future derived types: SIMD packed format
18
19 class MethodType : public Type {
20 public:
21   typedef vector<const Type*> ParamTypes;
22 private:
23   const Type *ResultType;
24   ParamTypes ParamTys;
25   bool isVarArgs;
26
27   MethodType(const MethodType &);                   // Do not implement
28   const MethodType &operator=(const MethodType &);  // Do not implement
29 protected:
30   // This should really be private, but it squelches a bogus warning
31   // from GCC to make them protected:  warning: `class MethodType' only 
32   // defines private constructors and has no friends
33
34   // Private ctor - Only can be created by a static member...
35   MethodType(const Type *Result, const vector<const Type*> &Params, 
36              bool IsVarArgs, const string &Name);
37 public:
38
39   inline bool isVarArg() const { return isVarArgs; }
40   inline const Type *getReturnType() const { return ResultType; }
41   inline const ParamTypes &getParamTypes() const { return ParamTys; }
42
43   static const MethodType *getMethodType(const Type *Result, 
44                                          const ParamTypes &Params);
45   static const MethodType *get(const Type *Result, const ParamTypes &Params) {
46     return getMethodType(Result, Params);
47   }
48 };
49
50
51 class ArrayType : public Type {
52 private:
53   const Type *ElementType;
54   int NumElements;       // >= 0 for sized array, -1 for unbounded/unknown array
55
56   ArrayType(const ArrayType &);                   // Do not implement
57   const ArrayType &operator=(const ArrayType &);  // Do not implement
58 protected:
59   // This should really be private, but it squelches a bogus warning
60   // from GCC to make them protected:  warning: `class ArrayType' only 
61   // defines private constructors and has no friends
62
63
64   // Private ctor - Only can be created by a static member...
65   ArrayType(const Type *ElType, int NumEl, const string &Name);
66 public:
67
68   inline const Type *getElementType() const { return ElementType; }
69   inline int         getNumElements() const { return NumElements; }
70
71   inline bool isSized()   const { return NumElements >= 0; }
72   inline bool isUnsized() const { return NumElements == -1; }
73
74   static const ArrayType *getArrayType(const Type *ElementType, 
75                                        int NumElements = -1);
76   static const ArrayType *get(const Type *ElementType, int NumElements = -1) {
77     return getArrayType(ElementType, NumElements);
78   }
79 };
80
81
82 class StructType : public Type {
83 public:
84   typedef vector<const Type*> ElementTypes;
85
86 private:
87   ElementTypes ETypes;
88
89   StructType(const StructType &);                   // Do not implement
90   const StructType &operator=(const StructType &);  // Do not implement
91   
92 protected:
93   // This should really be private, but it squelches a bogus warning
94   // from GCC to make them protected:  warning: `class StructType' only 
95   // defines private constructors and has no friends
96
97   // Private ctor - Only can be created by a static member...
98   StructType(const vector<const Type*> &Types, const string &Name);
99   
100 public:
101   inline const ElementTypes &getElementTypes() const { return ETypes; }
102   static const StructType *getStructType(const ElementTypes &Params);
103   static const StructType *get(const ElementTypes &Params) {
104     return getStructType(Params);
105   }
106 };
107
108
109 class PointerType : public Type {
110 private:
111   const Type *ValueType;
112
113   PointerType(const PointerType &);                   // Do not implement
114   const PointerType &operator=(const PointerType &);  // Do not implement
115 protected:
116   // This should really be private, but it squelches a bogus warning
117   // from GCC to make them protected:  warning: `class PointerType' only 
118   // defines private constructors and has no friends
119
120
121   // Private ctor - Only can be created by a static member...
122   PointerType(const Type *ElType);
123 public:
124
125   inline const Type *getValueType() const { return ValueType; }
126
127
128   static const PointerType *getPointerType(const Type *ElementType);
129   static const PointerType *get(const Type *ElementType) {
130     return getPointerType(ElementType);
131   }
132 };
133
134 #endif