source: dev/trunk/abdev/BasicCompiler_Common/include/Type.h@ 206

Last change on this file since 206 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

File size: 5.6 KB
Line 
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <boost/foreach.hpp>
7
8#include <jenga/include/common/Exception.h>
9#include <jenga/include/common/BoostXmlSupport.h>
10#include <jenga/include/smoothie/BasicFixed.h>
11
12#include <option.h>
13#include <Program.h>
14
15#include <windows.h>
16
17class CClass;
18
19class Type{
20 int basicType;
21 union{
22 LONG_PTR index;
23 const CClass *pClass;
24 };
25
26 // XMLシリアライズ用
27private:
28 friend class boost::serialization::access;
29 template<class Archive> void serialize(Archive& ar, const unsigned int version)
30 {
31 trace_for_serialize( "serializing - Type" );
32
33 ar & BOOST_SERIALIZATION_NVP( basicType );
34 if( HasMember() )
35 {
36 ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass));
37 }
38 else
39 {
40 ar & BOOST_SERIALIZATION_NVP( index );
41 }
42 }
43
44public:
45 static int GetBasicSize( int basicType );
46
47 Type():
48 basicType( DEF_NON ),
49 index( -1 ){}
50 Type( int basicType ):
51 basicType( basicType ),
52 index( -1 ){}
53
54 Type( int basicType, LONG_PTR index ):
55 basicType( basicType ),
56 index( index ){}
57
58 Type( int basicType, const CClass &objClass ):
59 basicType( basicType ),
60 index( (LONG_PTR)&objClass ){}
61
62 Type( const Type &type ):
63 basicType( type.basicType ),
64 index( type.index ){}
65
66 __inline int GetBasicType() const
67 {
68 return basicType;
69 }
70 LONG_PTR GetIndex() const
71 {
72 return index;
73 }
74 const CClass &GetClass() const
75 {
76 return *pClass;
77 }
78
79 void SetBasicType( int basicType ){
80 this->basicType = basicType;
81 }
82 void SetIndex( LONG_PTR index ){
83 this->index = index;
84 }
85 void SetClassPtr( const CClass *pClass )
86 {
87 this->pClass = pClass;
88 }
89 void SetNull(){
90 SetBasicType( DEF_NON );
91 SetIndex( -1 );
92 }
93 void SetType( int basicType, LONG_PTR index ){
94 SetBasicType( basicType );
95 SetIndex( index );
96 }
97 void SetType( int basicType, const CClass *pClass ){
98 SetBasicType( basicType );
99 this->pClass = pClass;
100 }
101
102 int PtrLevel() const
103 {
104 return PTR_LEVEL( basicType );
105 }
106 void PtrLevelUp(){
107 PTR_LEVEL_UP( basicType );
108 }
109 void PtrLevelDown(){
110 PTR_LEVEL_DOWN( basicType );
111 }
112
113 bool Equals( const Type &type ) const;
114
115 int GetBasicSize() const;
116 int GetSize() const;
117
118 bool IsNull() const;
119
120 bool IsByte() const;
121 bool IsSByte() const;
122 bool IsWord() const;
123 bool IsInteger() const;
124 bool IsDWord() const;
125 bool IsLong() const;
126 bool IsQWord() const;
127 bool IsInt64() const;
128 bool IsSingle() const;
129 bool IsDouble() const;
130 bool IsBoolean() const;
131
132 static bool IsPointer( int basicType );
133 bool IsPointer() const;
134 bool IsSigned() const;
135 bool IsNaturalWhole() const;
136 bool IsWhole() const;
137 bool IsReal() const;
138 bool Is64() const;
139 bool IsProcPtr() const;
140 bool IsStruct() const;
141 bool IsStructPtr() const;
142 bool IsObject() const;
143 bool IsObjectPtr() const;
144 bool IsObjectClass() const;
145 bool IsStringClass() const;
146 bool IsVoidPtr() const;
147 bool IsAny() const;
148
149 // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
150 bool HasMember() const;
151
152 void operator= ( const Type &type ){
153 basicType = type.basicType;
154 index = type.index;
155 }
156
157
158private:
159 static const int basicTypeList[];
160 static const std::string basicTypeNameList[];
161public:
162 static bool StringToBasicType( const std::string &typeName, int &basicType );
163 static const char *Type::BasicTypeToCharPtr( const Type &type );
164 static int GetBasicTypeFromSimpleName( const char *variable );
165};
166
167class BlittableType
168{
169 Type basicType;
170 CClass *pClass;
171
172 // XMLシリアライズ用
173private:
174 friend class boost::serialization::access;
175 template<class Archive> void serialize(Archive& ar, const unsigned int version)
176 {
177 trace_for_serialize( "serializing - BlittableType" );
178
179 ar & BOOST_SERIALIZATION_NVP( basicType );
180 ar & BOOST_SERIALIZATION_NVP( pClass );
181 }
182
183public:
184 BlittableType( const Type &basicType, CClass *pClass )
185 : basicType( basicType )
186 , pClass( pClass )
187 {
188 }
189 BlittableType()
190 {
191 }
192 const Type &GetBasicType() const
193 {
194 return basicType;
195 }
196 const CClass *GetClassPtr() const
197 {
198 return pClass;
199 }
200 const std::string GetCreateStaticMethodFullName() const;
201};
202class BlittableTypes : public std::vector<BlittableType>
203{
204 // XMLシリアライズ用
205private:
206 friend class boost::serialization::access;
207 template<class Archive> void serialize(Archive& ar, const unsigned int version)
208 {
209 trace_for_serialize( "serializing - BlittableTypes" );
210
211 ar & boost::serialization::make_nvp("vector_BlittableType",
212 boost::serialization::base_object<std::vector<BlittableType>>(*this));
213 }
214
215public:
216 bool IsExist( Type type ) const
217 {
218 const BlittableTypes &blittableTypes = *this;
219 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
220 if( blittableType.GetBasicType().Equals( type ) ){
221 return true;
222 }
223 }
224 return false;
225 }
226 const BlittableType &Find( const Type &type ) const
227 {
228 const BlittableTypes &blittableTypes = *this;
229 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
230 if( blittableType.GetBasicType().Equals( type ) ){
231 return blittableType;
232 }
233 }
234 Jenga::Throw( "Blittable型ではない" );
235
236 static BlittableType dummy;
237 return dummy;
238 }
239 const CClass *GetClassPtr( const Type &type ) const
240 {
241 const BlittableTypes &blittableTypes = *this;
242 BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
243 if( blittableType.GetBasicType().Equals( type ) ){
244 return blittableType.GetClassPtr();
245 }
246 }
247 return NULL;
248 }
249 const CClass &GetClass( const Type &type ) const
250 {
251 return *GetClassPtr( type );
252 }
253};
Note: See TracBrowser for help on using the repository browser.