1 | #include "common.h"
|
---|
2 |
|
---|
3 | const int Type::basicTypeList[] = {
|
---|
4 | DEF_BYTE,
|
---|
5 | DEF_SBYTE,
|
---|
6 | DEF_WORD,
|
---|
7 | DEF_INTEGER,
|
---|
8 | DEF_DWORD,
|
---|
9 | DEF_LONG,
|
---|
10 | DEF_QWORD,
|
---|
11 | DEF_INT64,
|
---|
12 |
|
---|
13 | DEF_SINGLE,
|
---|
14 | DEF_DOUBLE,
|
---|
15 |
|
---|
16 | DEF_BOOLEAN,
|
---|
17 |
|
---|
18 | DEF_PTR_VOID,
|
---|
19 |
|
---|
20 | DEF_ANY,
|
---|
21 |
|
---|
22 | DEF_NON
|
---|
23 | };
|
---|
24 |
|
---|
25 | const string Type::basicTypeNameList[] = {
|
---|
26 | "Byte",
|
---|
27 | "SByte",
|
---|
28 | "Word",
|
---|
29 | "Integer",
|
---|
30 | "DWord",
|
---|
31 | "Long",
|
---|
32 | "QWord",
|
---|
33 | "Int64",
|
---|
34 |
|
---|
35 | "Single",
|
---|
36 | "Double",
|
---|
37 |
|
---|
38 | "Boolean",
|
---|
39 |
|
---|
40 | "VoidPtr",
|
---|
41 |
|
---|
42 | "Any",
|
---|
43 |
|
---|
44 | ""
|
---|
45 | };
|
---|
46 |
|
---|
47 | bool Type::StringToBasicType( const string &typeName, int &basicType ){
|
---|
48 | for( int i=0; ; i++ ){
|
---|
49 | if( basicTypeList[i] == DEF_NON ){
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | if( basicTypeNameList[i] == typeName ){
|
---|
53 | basicType = basicTypeList[i];
|
---|
54 | return true;
|
---|
55 | }
|
---|
56 | }
|
---|
57 | return false;
|
---|
58 | }
|
---|
59 | bool Type::StringToType( const string &typeName, Type &type ){
|
---|
60 | type.index = -1;
|
---|
61 |
|
---|
62 | if( typeName[0] == '*' ){
|
---|
63 | if( typeName.size() >= 3
|
---|
64 | && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){
|
---|
65 | //関数ポインタ(*Function)
|
---|
66 | type.basicType = DEF_PTR_PROC;
|
---|
67 | }
|
---|
68 |
|
---|
69 | string nextTypeName = typeName.substr( 1 );
|
---|
70 |
|
---|
71 | if( !StringToType( nextTypeName, type ) ){
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 |
|
---|
75 | type.PtrLevelUp();
|
---|
76 |
|
---|
77 | return true;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if( StringToBasicType( typeName, type.basicType ) ){
|
---|
81 | // 基本型だったとき
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | ////////////////////
|
---|
87 | // TypeDefされた型
|
---|
88 | ////////////////////
|
---|
89 | int i=pobj_DBTypeDef->check( typeName.c_str() );
|
---|
90 | if(i!=-1){
|
---|
91 | return StringToType( pobj_DBTypeDef->ppobj_TypeDef[i]->lpszBaseName, type );
|
---|
92 | }
|
---|
93 |
|
---|
94 | //クラス
|
---|
95 | CClass *pobj_c = pobj_DBClass->check( typeName.c_str() );
|
---|
96 | if(pobj_c){
|
---|
97 | type.pClass = pobj_c;
|
---|
98 |
|
---|
99 | if( pobj_c->IsStructure() ){
|
---|
100 | type.basicType = DEF_STRUCT;
|
---|
101 | }
|
---|
102 | else{
|
---|
103 | type.basicType = DEF_OBJECT;
|
---|
104 | }
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | return false;
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | bool Type::Equals( const Type &type ) const
|
---|
113 | {
|
---|
114 | if( basicType == type.basicType ){
|
---|
115 | if( NATURAL_TYPE( basicType ) == DEF_OBJECT
|
---|
116 | || NATURAL_TYPE( basicType ) == DEF_STRUCT ){
|
---|
117 |
|
---|
118 | if( index == type.index ){
|
---|
119 | return true;
|
---|
120 | }
|
---|
121 |
|
---|
122 | }
|
---|
123 | else{
|
---|
124 | return true;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 |
|
---|
130 | bool Type::IsNull() const{
|
---|
131 | if( basicType == DEF_NON ){
|
---|
132 | return true;
|
---|
133 | }
|
---|
134 | return false;
|
---|
135 | }
|
---|
136 | bool Type::IsPointer() const
|
---|
137 | {
|
---|
138 | if(PTR_LEVEL( basicType )|| basicType == DEF_PTR_VOID || basicType == DEF_PTR_PROC
|
---|
139 | || ( basicType & FLAG_PTR ) ){
|
---|
140 | return true;
|
---|
141 | }
|
---|
142 |
|
---|
143 | return false;
|
---|
144 | }
|
---|
145 | bool Type::IsSigned() const
|
---|
146 | {
|
---|
147 | switch( basicType ){
|
---|
148 | case DEF_SBYTE:
|
---|
149 | case DEF_INTEGER:
|
---|
150 | case DEF_LONG:
|
---|
151 | case DEF_INT64:
|
---|
152 | case DEF_SINGLE:
|
---|
153 | case DEF_DOUBLE:
|
---|
154 | return true;
|
---|
155 | default:
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | return false;
|
---|
159 | }
|
---|
160 | bool Type::IsNaturalWhole() const
|
---|
161 | {
|
---|
162 | switch( basicType ){
|
---|
163 | case DEF_SBYTE:
|
---|
164 | case DEF_BYTE:
|
---|
165 | case DEF_INTEGER:
|
---|
166 | case DEF_WORD:
|
---|
167 | case DEF_LONG:
|
---|
168 | case DEF_DWORD:
|
---|
169 | case DEF_INT64:
|
---|
170 | case DEF_QWORD:
|
---|
171 | return true;
|
---|
172 | default:
|
---|
173 | break;
|
---|
174 | }
|
---|
175 | return false;
|
---|
176 | }
|
---|
177 | bool Type::IsWhole() const
|
---|
178 | {
|
---|
179 | return (
|
---|
180 | IsNaturalWhole()
|
---|
181 | || IsPtrType( basicType )
|
---|
182 | || basicType == DEF_BOOLEAN
|
---|
183 | );
|
---|
184 | }
|
---|
185 | bool Type::IsReal() const
|
---|
186 | {
|
---|
187 | switch( basicType ){
|
---|
188 | case DEF_SINGLE:
|
---|
189 | case DEF_DOUBLE:
|
---|
190 | return true;
|
---|
191 | default:
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | return false;
|
---|
195 | }
|
---|
196 | bool Type::Is64() const
|
---|
197 | {
|
---|
198 | switch( basicType ){
|
---|
199 | case DEF_QWORD:
|
---|
200 | case DEF_INT64:
|
---|
201 | return true;
|
---|
202 | default:
|
---|
203 | break;
|
---|
204 | }
|
---|
205 | return false;
|
---|
206 | }
|
---|
207 | bool Type::IsProcPtr() const
|
---|
208 | {
|
---|
209 | if( basicType == DEF_PTR_PROC ){
|
---|
210 | return true;
|
---|
211 | }
|
---|
212 | return false;
|
---|
213 | }
|
---|
214 | bool Type::IsStruct() const
|
---|
215 | {
|
---|
216 | if( basicType == DEF_STRUCT ){
|
---|
217 | return true;
|
---|
218 | }
|
---|
219 | return false;
|
---|
220 | }
|
---|