Changeset 75 in dev for BasicCompiler_Common/Type.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Type.cpp
r73 r75 65 65 //関数ポインタ(*Function) 66 66 type.basicType = DEF_PTR_PROC; 67 return true; 67 68 } 68 69 … … 109 110 } 110 111 112 int Type::GetBasicSize( int basicType ) 113 { 114 115 // 基本型 116 switch( basicType ){ 117 case DEF_SBYTE: 118 case DEF_BYTE: 119 case DEF_BOOLEAN: 120 return sizeof(BYTE); 121 122 case DEF_INTEGER: 123 case DEF_WORD: 124 return sizeof(WORD); 125 126 case DEF_LONG: 127 case DEF_DWORD: 128 return sizeof(DWORD); 129 130 case DEF_INT64: 131 case DEF_QWORD: 132 return sizeof(_int64); 133 134 case DEF_DOUBLE: 135 return sizeof(double); 136 case DEF_SINGLE: 137 return sizeof(float); 138 } 139 140 // ポインタ 141 if(IsPtrType(basicType)){ 142 return PTR_SIZE; 143 } 144 145 // オブジェクト 146 if(basicType==DEF_OBJECT){ 147 return PTR_SIZE; 148 } 149 150 SetError(); 151 return 0; 152 } 153 111 154 112 155 bool Type::Equals( const Type &type ) const … … 128 171 } 129 172 173 int Type::GetBasicSize() const 174 { 175 GetBasicSize( basicType ); 176 return 0; 177 } 178 int Type::GetSize() const 179 { 180 181 // 基本型 182 switch( basicType ){ 183 case DEF_LONG: 184 if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){ 185 return sizeof(BYTE); 186 } 187 else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){ 188 return sizeof(WORD); 189 } 190 return sizeof(DWORD); 191 192 case DEF_SBYTE: 193 case DEF_BYTE: 194 case DEF_BOOLEAN: 195 return sizeof(BYTE); 196 197 case DEF_INTEGER: 198 case DEF_WORD: 199 return sizeof(WORD); 200 201 case DEF_DWORD: 202 return sizeof(DWORD); 203 204 case DEF_INT64: 205 case DEF_QWORD: 206 return sizeof(_int64); 207 208 case DEF_DOUBLE: 209 return sizeof(double); 210 case DEF_SINGLE: 211 return sizeof(float); 212 } 213 214 // ポインタ 215 if(IsPtrType(basicType)){ 216 return PTR_SIZE; 217 } 218 219 // 構造体 220 if( basicType == DEF_STRUCT ){ 221 if( !pClass ){ 222 SetError(); 223 return 0; 224 } 225 226 return pClass->GetSize(); 227 } 228 229 // オブジェクト 230 if(basicType==DEF_OBJECT){ 231 return PTR_SIZE; 232 } 233 234 SetError(); 235 return 0; 236 } 237 130 238 bool Type::IsNull() const{ 131 239 if( basicType == DEF_NON ){ … … 134 242 return false; 135 243 } 244 245 bool Type::IsByte() const{ 246 if( basicType == DEF_BYTE ){ 247 return true; 248 } 249 return false; 250 } 251 bool Type::IsSByte() const{ 252 if( basicType == DEF_SBYTE ){ 253 return true; 254 } 255 return false; 256 } 257 bool Type::IsWord() const{ 258 if( basicType == DEF_WORD ){ 259 return true; 260 } 261 return false; 262 } 263 bool Type::IsInteger() const{ 264 if( basicType == DEF_INTEGER ){ 265 return true; 266 } 267 return false; 268 } 269 bool Type::IsDWord() const{ 270 if( basicType == DEF_DWORD ){ 271 return true; 272 } 273 return false; 274 } 275 bool Type::IsLong() const{ 276 if( basicType == DEF_LONG ){ 277 return true; 278 } 279 return false; 280 } 281 bool Type::IsQWord() const{ 282 if( basicType == DEF_QWORD ){ 283 return true; 284 } 285 return false; 286 } 287 bool Type::IsInt64() const{ 288 if( basicType == DEF_INT64 ){ 289 return true; 290 } 291 return false; 292 } 293 bool Type::IsSingle() const{ 294 if( basicType == DEF_SINGLE ){ 295 return true; 296 } 297 return false; 298 } 299 bool Type::IsDouble() const{ 300 if( basicType == DEF_DOUBLE ){ 301 return true; 302 } 303 return false; 304 } 305 bool Type::IsBoolean() const{ 306 if( basicType == DEF_BOOLEAN ){ 307 return true; 308 } 309 return false; 310 } 311 136 312 bool Type::IsPointer() const 137 313 { … … 219 395 return false; 220 396 } 397 bool Type::IsStructPtr() const 398 { 399 if( basicType == DEF_PTR_STRUCT ){ 400 return true; 401 } 402 return false; 403 } 404 bool Type::IsObject() const 405 { 406 if( basicType == DEF_OBJECT ){ 407 return true; 408 } 409 return false; 410 } 411 bool Type::IsObjectPtr() const 412 { 413 if( basicType == DEF_PTR_OBJECT ){ 414 return true; 415 } 416 return false; 417 } 418 bool Type::IsStringObject() const 419 { 420 if( basicType == DEF_OBJECT ){ 421 if( lstrcmp( pClass->name,"String")==0){ 422 return true; 423 } 424 } 425 return false; 426 } 427 bool Type::IsVoidPtr() const 428 { 429 if( basicType == DEF_PTR_VOID ){ 430 return true; 431 } 432 return false; 433 } 434 435 bool Type::IsAny() const 436 { 437 if( basicType == DEF_ANY ){ 438 return true; 439 } 440 return false; 441 } 442 443 const string Type::ToString() const 444 { 445 if( PTR_LEVEL( basicType ) ){ 446 //ポインタレベルが1以上の場合 447 Type type( *this ); 448 type.PtrLevelDown(); 449 450 return (string)"*" + type.ToString(); 451 } 452 else if( IsObject() || IsStruct() ){ 453 //オブジェクトまたは構造体 454 455 if( !( index == 0 || index == -1 ) ){ 456 return pClass->name; 457 } 458 } 459 else if( IsProcPtr() ){ 460 if( index == 0 || index == -1 ){ 461 return "VoidPtr"; 462 } 463 else{ 464 extern ProcPointer **ppProcPointer; 465 if( ppProcPointer[index]->ReturnType().IsNull() ){ 466 return "*Sub"; 467 } 468 return "*Function"; 469 } 470 } 471 else{ 472 // 基本型 473 474 for( int i=0; ; i++ ){ 475 if( basicTypeList[i] == DEF_NON ){ 476 break; 477 } 478 if( basicTypeList[i] == basicType ){ 479 return basicTypeNameList[i]; 480 } 481 } 482 } 483 484 extern int cp; 485 SetError(1,NULL,cp); 486 487 return (string)"(null)"; 488 }
Note:
See TracChangeset
for help on using the changeset viewer.