Changeset 290 in dev for trunk/abdev
- Timestamp:
- Aug 21, 2007, 11:00:25 PM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/Compile_Calc.cpp
r265 r290 373 373 } 374 374 375 void SetVariableFromEax( int VarType,int CalcType,RELATIVE_VAR *pRelativeVar){375 void SetVariableFromEax( const Type &varType,int CalcType,RELATIVE_VAR *pRelativeVar){ 376 376 ///////////////////////////////////////////////// 377 377 // eaxの内容を変数にコピーするコードを抽出 378 378 ///////////////////////////////////////////////// 379 379 380 if(VarType==DEF_BOOLEAN){ 380 if( varType.IsBoolean() ) 381 { 381 382 //bool 382 383 SetBooleanVariable(CalcType,pRelativeVar); 383 384 } 384 else if( IsRealNumberType( VarType ) ){ 385 else if( varType.IsReal() ) 386 { 385 387 // Double/Single型変数へレジスタの値を代入 386 SetRealVariable(VarType, CalcType, pRelativeVar); 387 } 388 else if( IsWholeNumberType( VarType ) || VarType == DEF_OBJECT ){ 389 int typeSize = GetTypeSize( VarType, -1 ); 388 SetRealVariable(varType.GetBasicType(), CalcType, pRelativeVar); 389 } 390 else if( varType.IsWhole() || varType.IsObject() ) 391 { 392 int typeSize = varType.GetSize(); 390 393 391 394 //整数変数へraxの値を格納する … … 640 643 RestoreDefaultRegisterFromStackMemory( calcType.GetBasicType() ); 641 644 642 SetVariableFromEax(varType .GetBasicType(),calcType.GetBasicType(),&VarRelativeVar);643 } 645 SetVariableFromEax(varType,calcType.GetBasicType(),&VarRelativeVar); 646 } -
trunk/abdev/BasicCompiler32/Compile_Calc_PushVar.cpp
r253 r290 59 59 } 60 60 } 61 void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head){ 61 void SetReg_WholeVariable( Type &type, RELATIVE_VAR *pRelativeVar,int reg, bool is64Head) 62 { 62 63 int varSize; 63 64 64 varSize =GetTypeSize(type,-1);65 varSize = type.GetSize(); 65 66 66 67 if(varSize==sizeof(_int64)){ … … 72 73 73 74 //下位32ビットをeaxにロード 74 SetReg_WholeVariable( DEF_LONG,pRelativeVar,REG_EAX);75 SetReg_WholeVariable( Type(DEF_LONG),pRelativeVar,REG_EAX); 75 76 76 77 //上位32ビットをedxにロード 77 SetReg_WholeVariable( DEF_LONG,pRelativeVar,REG_EDX, true);78 SetReg_WholeVariable( Type(DEF_LONG),pRelativeVar,REG_EDX, true); 78 79 79 80 return; -
trunk/abdev/BasicCompiler32/Compile_CallProc.cpp
r265 r290 81 81 } 82 82 83 bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName ,int RefType){83 bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName ){ 84 84 int i2; 85 85 … … 115 115 Type varType; 116 116 GetVarType( ObjectName, varType, false ); 117 pobj_c = &varType.GetClass(); 118 if( NATURAL_TYPE( varType.GetBasicType() ) != DEF_OBJECT ){ 117 if( NATURAL_TYPE( varType.GetBasicType() ) == DEF_OBJECT ) 118 { 119 pobj_c = &varType.GetClass(); 120 } 121 else 122 { 119 123 pobj_c=compiler.GetObjectModule().meta.GetClasses().Find(ObjectName); 120 124 if( pobj_c ){ -
trunk/abdev/BasicCompiler32/Compile_Func.cpp
r265 r290 259 259 260 260 char ObjectName[VN_SIZE]; 261 int RefType;262 SplitObjectName(name,ObjectName, &RefType);261 ReferenceKind referenceKind; 262 SplitObjectName(name,ObjectName, referenceKind ); 263 263 264 264 if(ObjectName[0]){ … … 274 274 275 275 //参照タイプが整合しているかをチェック 276 if(type.GetBasicType()!=RefType) SetError(104,ObjectName,cp); 276 if( !( type.IsObject() && referenceKind == RefDot 277 || type.IsObjectPtr() && referenceKind == RefPointer ) ) 278 { 279 SetError(104,ObjectName,cp); 280 } 277 281 278 282 if(type.IsObjectPtr()){ -
trunk/abdev/BasicCompiler32/Compile_Object.cpp
r263 r290 52 52 Opcode_CallProc(CreateParameter, 53 53 pUserProc, 54 PROCFLAG_NEW,"" ,0);54 PROCFLAG_NEW,""); 55 55 56 56 { … … 65 65 Opcode_CallProc(temporary, 66 66 subs[0], 67 PROCFLAG_NEW,"" ,0);67 PROCFLAG_NEW,""); 68 68 } 69 69 else{ -
trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp
r285 r290 267 267 268 268 //コンパイル中の関数が属するクラス 269 compiler.pCompilingClass =pUserProc->GetParentClassPtr();269 compiler.pCompilingClass = pUserProc->GetParentClassPtr(); 270 270 271 271 //コンパイルスタートをクラス管理クラスに追加 … … 495 495 &compiler.pCompilingClass->GetSuperClass().GetConstructorMethod()->GetUserProc(), 496 496 0, 497 "" ,498 0);497 "" 498 ); 499 499 } 500 500 } … … 587 587 &method->GetUserProc(), 588 588 0, 589 "" ,590 0);589 "" 590 ); 591 591 } 592 592 } … … 629 629 GetVarOffsetReadWrite(temp,&RelativeVar,Type()); 630 630 631 i3=pUserProc->ReturnType().GetBasicType();632 633 if(i3==DEF_OBJECT || i3==DEF_STRUCT){631 const Type &returnType = pUserProc->ReturnType(); 632 if( returnType.IsObject() || returnType.IsStruct() ) 633 { 634 634 SetVarPtrToEax(&RelativeVar); 635 if( i3==DEF_OBJECT ){ 635 if( returnType.IsObject() ) 636 { 636 637 //mov eax,dword ptr[eax] 637 638 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE ); 638 639 } 639 640 } 640 else if( i3==DEF_DOUBLE 641 || i3 == DEF_SINGLE ) 641 else if( returnType.IsReal() ) 642 642 { 643 643 //fld qword ptr[ebp+offset] 644 644 compiler.codeGenerator.localVarPertialSchedules.push_back( 645 compiler.codeGenerator.op_fld_base_offset( i3, REG_EBP, RelativeVar.offset, Schedule::None, true )645 compiler.codeGenerator.op_fld_base_offset( returnType.GetBasicType(), REG_EBP, RelativeVar.offset, Schedule::None, true ) 646 646 ); 647 647 } 648 else if(i3==DEF_INT64||i3==DEF_QWORD){ 649 //mov eax,dword ptr[ebp+offset] 650 compiler.codeGenerator.localVarPertialSchedules.push_back( 651 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true ) 652 ); 653 654 //mov edx,dword ptr[ebp+offset+sizeof(long)] 655 compiler.codeGenerator.localVarPertialSchedules.push_back( 656 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_EBP, RelativeVar.offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true ) 657 ); 658 } 659 else if(i3==DEF_LONG||i3==DEF_DWORD|| 660 IsPtrType(i3)) 648 else if( returnType.Is64() ) 661 649 { 662 650 //mov eax,dword ptr[ebp+offset] … … 664 652 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true ) 665 653 ); 666 } 667 else if(i3==DEF_INTEGER||i3==DEF_WORD || (Smoothie::IsUnicode()&&i3==DEF_CHAR)){ 654 655 //mov edx,dword ptr[ebp+offset+sizeof(long)] 656 compiler.codeGenerator.localVarPertialSchedules.push_back( 657 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_EBP, RelativeVar.offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true ) 658 ); 659 } 660 else if( returnType.GetSize() == sizeof(long) ) 661 { 662 //mov eax,dword ptr[ebp+offset] 663 compiler.codeGenerator.localVarPertialSchedules.push_back( 664 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true ) 665 ); 666 } 667 else if( returnType.GetSize() == sizeof(short) ) 668 { 668 669 //xor eax,eax(eaxを0に初期化する) 669 670 compiler.codeGenerator.op_zero_reg(REG_EAX); … … 674 675 ); 675 676 } 676 else if(i3==DEF_SBYTE||i3==DEF_BYTE||i3==DEF_BOOLEAN || (Smoothie::IsUnicode()==false&&i3==DEF_CHAR)){ 677 else if( returnType.GetSize() == sizeof(char) ) 678 { 677 679 //xor eax,eax(eaxを0に初期化する) 678 680 compiler.codeGenerator.op_zero_reg(REG_EAX); … … 682 684 compiler.codeGenerator.op_mov_RM( sizeof(char), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true ) 683 685 ); 686 } 687 else 688 { 689 SetError(); 684 690 } 685 691 } -
trunk/abdev/BasicCompiler32/Compile_Set_Var.cpp
r253 r290 188 188 189 189 //cmp eax,0 190 compiler.codeGenerator.op_cmp_value( GetTypeSize(type,-1),REG_EAX,0);190 compiler.codeGenerator.op_cmp_value(Type(type,-1).GetSize(),REG_EAX,0); 191 191 192 192 //setne al -
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r285 r290 81 81 } 82 82 83 Opcode_CallProc("",pUserProc,0,"" ,0);83 Opcode_CallProc("",pUserProc,0,""); 84 84 85 85 return; -
trunk/abdev/BasicCompiler32/Compile_Var.cpp
r288 r290 160 160 return 1; 161 161 } 162 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 162 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess) 163 { 164 const CClass &objClass = classType.GetClass(); 163 165 164 166 ////////////////////////////////////// … … 221 223 resultType = pMember->GetType(); 222 224 225 226 ///////////////////////////////////////////////////////// 227 // ☆★☆ ジェネリクスサポート ☆★☆ 228 229 if( resultType.IsTypeParameter() ) 230 { 231 // 型パラメータだったとき 232 if( classType.HasActualGenericType() ) 233 { 234 // TODO: GetDummyActualGenericTypeを適切な形に実装し直す 235 resultType = classType.GetDummyActualGenericType(); 236 } 237 else 238 { 239 // TODO: ベースオブジェクト(指定されていないときはObjectクラス)にセットする 240 resultType.SetBasicType( DEF_OBJECT ); 241 } 242 } 243 244 // 245 ///////////////////////////////////////////////////////// 246 247 223 248 //ポインタ変数の場合 224 249 if( resultType.IsPointer() ){ … … 321 346 isErrorEnabled, 322 347 isWriteAccess, 323 pMember->GetType() .GetClass(),348 pMember->GetType(), 324 349 NestMember, 325 350 pRelativeVar, … … 345 370 RelativeVar.offset=-LocalVar_ThisPtrOffset; 346 371 347 SetReg_WholeVariable( DEF_PTR_VOID,&RelativeVar,reg);372 SetReg_WholeVariable(Type(DEF_PTR_VOID),&RelativeVar,reg); 348 373 } 349 374 … … 472 497 isErrorEnabled, 473 498 isWriteAccess, 474 *compiler.pCompilingClass,499 Type( DEF_OBJECT, *compiler.pCompilingClass ), 475 500 variable, 476 501 pRelativeVar, … … 701 726 isErrorEnabled, 702 727 isWriteAccess, 703 resultType .GetClass(),728 resultType, 704 729 member,pRelativeVar,resultType,0)) return false; 705 730 … … 1204 1229 SetError(); 1205 1230 } 1206 SetVariableFromEax( DEF_OBJECT, DEF_OBJECT, &RelativeVar );1231 SetVariableFromEax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar ); 1207 1232 } 1208 1233 } -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r288 r290 397 397 InitGCVariables(); 398 398 399 if( compiler.IsStaticLibrary() )399 //if( compiler.IsStaticLibrary() ) 400 400 { 401 401 //_System_StartupProgramの呼び出し … … 504 504 } 505 505 506 CompileMessage( "リンク中..." ); 506 extern BOOL bError; 507 if( !bError ) 508 { 509 CompileMessage( "リンク中..." ); 510 } 507 511 508 512 -
trunk/abdev/BasicCompiler32/NumOpe.cpp
r276 r290 122 122 else if( resultType.IsWhole() || resultType.IsObject()){ 123 123 //整数型 124 SetReg_WholeVariable(resultType .GetBasicType(),&relativeVar,useReg);124 SetReg_WholeVariable(resultType,&relativeVar,useReg); 125 125 } 126 126 else if( resultType.IsStruct() ){ … … 142 142 return true; 143 143 } 144 bool TermMemberOpe( const CClass &objClass, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member ){ 144 bool TermMemberOpe( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member ) 145 { 146 const CClass &objClass = leftType.GetClass(); 147 145 148 const int useReg = REG_EAX; 146 149 147 if( GetMemberType( objClass, member, resultType, 0, false ) ){150 if( GetMemberType( leftType, member, resultType, 0, false ) ){ 148 151 // メンバが見つかったとき 149 152 … … 157 160 true, //エラー表示あり 158 161 false, //読み込み専用 159 objClass,162 leftType, 160 163 member,&relativeVar,resultType,0)){ 161 164 return false; … … 194 197 compiler.codeGenerator.op_push( useReg ); 195 198 196 if( !Opcode_CallProc(parameter,pUserProc,PROCFLAG_NEW,termLeft ,0) ){199 if( !Opcode_CallProc(parameter,pUserProc,PROCFLAG_NEW,termLeft) ){ 197 200 198 201 return false; … … 217 220 218 221 //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg); 222 223 224 ///////////////////////////////////////////////////////// 225 // ☆★☆ ジェネリクスサポート ☆★☆ 226 227 if( resultType.IsTypeParameter() ) 228 { 229 // 型パラメータだったとき 230 if( leftType.HasActualGenericType() ) 231 { 232 // TODO: GetDummyActualGenericTypeを適切な形に実装し直す 233 resultType = leftType.GetDummyActualGenericType(); 234 } 235 else 236 { 237 // TODO: ベースオブジェクト(指定されていないときはObjectクラス)にセットする 238 resultType.SetBasicType( DEF_OBJECT ); 239 } 240 } 241 242 // 243 ///////////////////////////////////////////////////////// 219 244 } 220 245 … … 227 252 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool isWantObject, bool *pIsClassName, bool isProcedureCallOnly ){ 228 253 char parameter[VN_SIZE]; 254 255 if( (string)term=="a.x") 256 { 257 int test=0; 258 } 229 259 230 260 // Withを解決 … … 279 309 } 280 310 281 return TermMemberOpe( leftType .GetClass(), baseType, resultType, termFull, termLeft, member );311 return TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, member ); 282 312 } 283 313 globalArea: -
trunk/abdev/BasicCompiler32/NumOpe_Arithmetic.cpp
r225 r290 217 217 } 218 218 219 if( GetTypeSize(type[sp-2],-1)==sizeof(_int64)){219 if(Type(type[sp-2],-1).GetSize()==sizeof(_int64)){ 220 220 if(AnswerType==DEF_SINGLE){ 221 221 //add esp,4 … … 652 652 } 653 653 //↓ここだけ例外DWord 654 if( GetTypeSize(type[sp-2],-1)==sizeof(_int64)||type[sp-2]==DEF_DWORD){654 if(Type(type[sp-2],-1).GetSize()==sizeof(_int64)||type[sp-2]==DEF_DWORD){ 655 655 if(AnswerType==DEF_SINGLE){ 656 656 //add esp,4 … … 997 997 sp=*pStackPointer; 998 998 999 int CastType; 1000 CastType=type[sp-1]; 1001 if((CastType&FLAG_CAST)==0){ 999 int castBasicType = type[sp-1]; 1000 if((castBasicType&FLAG_CAST)==0){ 1002 1001 SetError(47,NULL,cp); 1003 1002 return 0; 1004 1003 } 1005 CastType=CastType&(~FLAG_CAST); 1006 1007 if(IsPtrType(CastType)){ 1008 ChangeTypeToLong(type[sp-2]); 1009 } 1010 else if(IsRealNumberType(CastType)){ 1011 if(CastType==DEF_DOUBLE) ChangeTypeToDouble(type[sp-2]); 1012 else if(CastType==DEF_SINGLE) ChangeTypeToSingle(type[sp-2]); 1013 } 1014 else ChangeTypeToWhole(type[sp-2],CastType); 1015 1016 type[sp-2]=CastType; 1017 index_stack[sp-2]=index_stack[sp-1]; 1004 castBasicType = castBasicType&(~FLAG_CAST); 1005 1006 Type oldType( type[sp-2], index_stack[sp-2] ); 1007 Type castType( castBasicType, index_stack[sp-1] ); 1008 1009 if( castType.IsPointer() ) 1010 { 1011 ChangeTypeToLong( oldType.GetBasicType() ); 1012 } 1013 else if( castType.IsReal() ) 1014 { 1015 if( castType.IsDouble() ) 1016 { 1017 ChangeTypeToDouble( oldType.GetBasicType() ); 1018 } 1019 else if( castType.IsSingle() ) 1020 { 1021 ChangeTypeToSingle( oldType.GetBasicType() ); 1022 } 1023 } 1024 else 1025 { 1026 ChangeTypeToWhole( oldType, castType ); 1027 } 1028 1029 type[sp-2] = castType.GetBasicType(); 1030 index_stack[sp-2] = castType.GetIndex(); 1018 1031 1019 1032 sp--; -
trunk/abdev/BasicCompiler32/NumOpe_Logical.cpp
r225 r290 450 450 451 451 //cmp eax,0 452 compiler.codeGenerator.op_cmp_value( GetTypeSize(type[sp-1],-1),REG_EAX,0);452 compiler.codeGenerator.op_cmp_value(Type(type[sp-1],-1).GetSize(),REG_EAX,0); 453 453 454 454 //setne al -
trunk/abdev/BasicCompiler32/NumOpe_TypeOperation.cpp
r235 r290 8 8 #include "Opcode.h" 9 9 10 void ExtendStackTo32(int type); 11 void ExtendStackTo64(int type){ 12 if(Is64Type(type)) return; 10 void ExtendStackTo32( const Type &oldType ); 11 12 void ExtendStackTo64( const Type &oldType ) 13 { 14 if( oldType.Is64() ) 15 { 16 return; 17 } 13 18 14 19 //32ビットに拡張 15 ExtendStackTo32( type);20 ExtendStackTo32( oldType ); 16 21 17 22 //64ビットに拡張 18 if(IsSignedType(type)){ 23 if( oldType.IsSigned() ) 24 { 19 25 //符号あり 20 26 … … 44 50 } 45 51 } 46 void ExtendStackTo32(int type){ 47 if(GetTypeSize(type,-1)==sizeof(long)) return; 48 49 if(Is64Type(type)){ 52 void ExtendStackTo32( const Type &oldType ) 53 { 54 if( oldType.GetSize() == sizeof(long) ) 55 { 56 return; 57 } 58 59 if( oldType.Is64() ) 60 { 50 61 //pop eax 51 62 compiler.codeGenerator.op_pop(REG_EAX); … … 57 68 compiler.codeGenerator.op_push(REG_EAX); 58 69 } 59 else if(type==DEF_INTEGER || (Smoothie::IsUnicode()&&type==DEF_CHAR)){ 70 else if( oldType.IsInteger() ) 71 { 60 72 //pop eax 61 73 compiler.codeGenerator.op_pop(REG_EAX); … … 67 79 compiler.codeGenerator.op_push(REG_EAX); 68 80 } 69 else if(type==DEF_WORD){ 81 else if( oldType.IsWord() ) 82 { 70 83 //pop eax 71 84 compiler.codeGenerator.op_pop(REG_EAX); … … 77 90 compiler.codeGenerator.op_push(REG_EAX); 78 91 } 79 else if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){ 92 else if( oldType.IsSByte() ) 93 { 80 94 //pop eax 81 95 compiler.codeGenerator.op_pop(REG_EAX); … … 87 101 compiler.codeGenerator.op_push(REG_EAX); 88 102 } 89 else if(type==DEF_BYTE||type==DEF_BOOLEAN){ 103 else if( oldType.IsByte() || oldType.IsBoolean() ) 104 { 90 105 //pop eax 91 106 compiler.codeGenerator.op_pop(REG_EAX); … … 98 113 } 99 114 } 100 void ExtendStackTo16(int type){ 101 if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){ 115 void ExtendStackTo16( const Type &oldType ){ 116 if( oldType.IsSByte() ) 117 { 102 118 //pop eax 103 119 compiler.codeGenerator.op_pop(REG_EAX); … … 109 125 compiler.codeGenerator.op_push(REG_EAX); 110 126 } 111 else if(type==DEF_BYTE){ 127 else if( oldType.IsByte() ) 128 { 112 129 //pop eax 113 130 compiler.codeGenerator.op_pop(REG_EAX); … … 120 137 } 121 138 } 122 void ExtendStackTo8(int type){ 123 if(Is64Type(type)){ 139 void ExtendStackTo8( const Type &oldType ) 140 { 141 if( oldType.Is64() ) 142 { 124 143 //pop eax 125 144 compiler.codeGenerator.op_pop(REG_EAX); … … 134 153 135 154 136 void ChangeTypeToWhole(int OldType,int NewType){ 137 if(OldType==DEF_DOUBLE){ 138 if(Is64Type(NewType)){ 155 void ChangeTypeToWhole( const Type &oldType, const Type &newType ){ 156 if( oldType.IsDouble() ) 157 { 158 if( newType.Is64() ) 159 { 139 160 //fld qword ptr[esp] 140 161 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); … … 154 175 } 155 176 } 156 else if(OldType==DEF_SINGLE){ 157 if(Is64Type(NewType)){ 177 else if( oldType.IsSingle() ) 178 { 179 if( newType.Is64() ) 180 { 158 181 //fld dword ptr[esp] 159 182 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); … … 176 199 //整数から整数へ変換 177 200 178 if(Is64Type(NewType)){ 179 ExtendStackTo64(OldType); 180 } 181 else if(GetTypeSize(NewType,-1)==sizeof(long)){ 182 ExtendStackTo32(OldType); 183 } 184 else if(GetTypeSize(NewType,-1)==sizeof(short)){ 185 ExtendStackTo16(OldType); 186 } 187 else if(GetTypeSize(NewType,-1)==sizeof(char)){ 188 ExtendStackTo8(OldType); 189 } 190 } 191 } 201 if( newType.Is64() ) 202 { 203 ExtendStackTo64( oldType ); 204 } 205 else if( newType.GetSize()==sizeof(long)){ 206 ExtendStackTo32( oldType ); 207 } 208 else if( newType.GetSize()==sizeof(short)){ 209 ExtendStackTo16( oldType ); 210 } 211 else if( newType.GetSize()==sizeof(char)){ 212 ExtendStackTo8( oldType ); 213 } 214 } 215 } -
trunk/abdev/BasicCompiler32/Opcode.h
r261 r290 59 59 void ChangeTypeToInteger(int OldType); 60 60 void ChangeTypeToByte(int OldType); 61 void SetVariableFromEax( int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);61 void SetVariableFromEax( const Type &varType, int CalcType,RELATIVE_VAR *pRelativeVar); 62 62 void OpcodeCalc( const char *Command ); 63 63 … … 110 110 111 111 //NumOpe_TypeOperation.cpp 112 void ExtendStackTo64( int type);113 void ChangeTypeToWhole( int OldType,int NewType);112 void ExtendStackTo64( const Type &oldType ); 113 void ChangeTypeToWhole( const Type &oldType, const Type &newType ); 114 114 115 115 //Compile_Set_Var.cpp … … 147 147 //Compile_Calc_PushVar.cpp 148 148 void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar); 149 void SetReg_WholeVariable( int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head = false);149 void SetReg_WholeVariable( Type &type, RELATIVE_VAR *pRelativeVar,int reg, bool is64Head = false); 150 150 void PushLongVariable(RELATIVE_VAR *pRelativeVar); 151 151 … … 156 156 //Compile_Var.cpp 157 157 void SetRelativeOffset( RELATIVE_VAR &relativeVar ); 158 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess);158 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess); 159 159 void SetThisPtrToReg(int reg); 160 160 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL ); … … 208 208 #define PROCFLAG_NEW 1 209 209 bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer); 210 bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName ,int RefType);210 bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName ); 211 211 bool Opcode_CallDllProc( const char *lpszParms, const DllProc *pDllProc ); 212 212 -
trunk/abdev/BasicCompiler32/OperatorProc.cpp
r225 r290 79 79 for(int i=0;i<(int)params.size();i++){ 80 80 CheckDifferentType( 81 pUserProc->Params()[i]->GetBasicType(), 82 pUserProc->Params()[i]->GetIndex(), 83 params[i]->GetBasicType(), 84 params[i]->GetIndex(), 81 *pUserProc->Params()[i], 82 *params[i], 85 83 "", 86 84 i); … … 91 89 } 92 90 93 int right_side_size = GetTypeSize(type_stack[sp-1],index_stack[sp-1]);91 int right_side_size = Type(type_stack[sp-1],index_stack[sp-1]).GetSize(); 94 92 95 93 if(bTwoTerm){ … … 261 259 } 262 260 263 Opcode_CallProc(Parameter,subs[0],0,ObjectName ,DEF_OBJECT);261 Opcode_CallProc(Parameter,subs[0],0,ObjectName); 264 262 resultType = subs[0]->ReturnType(); 265 263 } -
trunk/abdev/BasicCompiler32/increment.cpp
r225 r290 35 35 else{ 36 36 //整数 37 SetReg_WholeVariable(varType .GetBasicType(),&VarRelativeVar,REG_EAX);37 SetReg_WholeVariable(varType,&VarRelativeVar,REG_EAX); 38 38 } 39 39 … … 114 114 if( varType.IsDouble() ) ChangeTypeToDouble(calcType.GetBasicType()); 115 115 else if( varType.IsSingle() ) ChangeTypeToSingle(calcType.GetBasicType()); 116 else ChangeTypeToWhole( calcType.GetBasicType(),varType.GetBasicType());116 else ChangeTypeToWhole( calcType, varType ); 117 117 118 118 int type_stack[255],sp; … … 202 202 } 203 203 204 SetVariableFromEax(varType .GetBasicType(),varType.GetBasicType(),&VarRelativeVar);204 SetVariableFromEax(varType,varType.GetBasicType(),&VarRelativeVar); 205 205 } -
trunk/abdev/BasicCompiler_Common/Intermediate_Step2.cpp
r272 r290 269 269 } 270 270 271 // クラス名を取得 272 char className[VN_SIZE]; 273 GetIdentifierToken( className, Command, i2 ); 274 271 275 //コンストラクタ、デストラクタを暗黙的に生成 272 MakeConstructorAndDestructor(buffer,nowLine, Command + i2);276 MakeConstructorAndDestructor(buffer,nowLine,className); 273 277 break; 274 278 case ESC_INTERFACE: -
trunk/abdev/BasicCompiler_Common/NumOpe_GetType.cpp
r265 r290 51 51 52 52 int BaseTypeSize; 53 BaseTypeSize= GetTypeSize(BaseType,-1);53 BaseTypeSize=Type(BaseType,-1).GetSize(); 54 54 55 55 if(IsRealNumberType(BaseType)){ 56 if( GetTypeSize(CalcType,-1)<4)56 if(Type(CalcType,-1).GetSize()<4) 57 57 type=MakeWholeType(4,IsSignedType(CalcType)); 58 58 } 59 else if(BaseTypeSize> GetTypeSize(CalcType,-1)){59 else if(BaseTypeSize>Type(CalcType,-1).GetSize()){ 60 60 //要求される型のほうがサイズが大きいとき 61 61 type=MakeWholeType(BaseTypeSize,IsSignedType(CalcType)); … … 358 358 } 359 359 360 const CClass &objClass = leftType.GetClass();361 362 360 363 361 /////////////////////////////////////////////////////////////////// 364 362 // メンバを検索 365 363 /////////////////////////////////////////////////////////////////// 366 if( GetMemberType( objClass, member, resultType, 0, false ) ){364 if( GetMemberType( leftType, member, resultType, 0, false ) ){ 367 365 // メンバが見つかったとき 368 366 return true; … … 378 376 379 377 vector<const UserProc *> userProcs; 380 objClass.GetMethods().Enum( methodName, userProcs );378 leftType.GetClass().GetMethods().Enum( methodName, userProcs ); 381 379 if(userProcs.size()){ 382 380 //オーバーロードを解決 … … 385 383 if( pUserProc ){ 386 384 resultType = pUserProc->ReturnType(); 385 386 ///////////////////////////////////////////////////////// 387 // ☆★☆ ジェネリクスサポート ☆★☆ 388 389 if( resultType.IsTypeParameter() ) 390 { 391 // 型パラメータだったとき 392 if( leftType.HasActualGenericType() ) 393 { 394 // TODO: GetDummyActualGenericTypeを適切な形に実装し直す 395 resultType = leftType.GetDummyActualGenericType(); 396 } 397 else 398 { 399 // TODO: ベースオブジェクト(指定されていないときはObjectクラス)にセットする 400 resultType.SetBasicType( DEF_OBJECT ); 401 } 402 } 403 404 // 405 ///////////////////////////////////////////////////////// 406 387 407 return true; 388 408 } -
trunk/abdev/BasicCompiler_Common/OldStatement.cpp
r206 r290 125 125 return; 126 126 } 127 Opcode_CallProc(buffer,pUserProc,0,"" ,0);127 Opcode_CallProc(buffer,pUserProc,0,""); 128 128 } 129 129 void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){ … … 227 227 return; 228 228 } 229 Opcode_CallProc(buffer,pUserProc,0,"" ,0);229 Opcode_CallProc(buffer,pUserProc,0,""); 230 230 } 231 231 void Opcode_Print(const char *Parameter,BOOL bWrite){ … … 331 331 return; 332 332 } 333 Opcode_CallProc(buffer,pUserProc,0,"" ,0);333 Opcode_CallProc(buffer,pUserProc,0,""); 334 334 } -
trunk/abdev/BasicCompiler_Common/ParamImpl.cpp
r284 r290 168 168 } 169 169 else{ 170 //if(NATURAL_TYPE(argType.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(argType.GetBasicType())==DEF_STRUCT){171 170 if( NATURAL_TYPE(argType.GetBasicType())==DEF_STRUCT){ 172 171 if(argType.GetIndex()!=param.GetIndex()){ -
trunk/abdev/BasicCompiler_Common/Subroutine.cpp
r277 r290 73 73 } 74 74 75 void SplitObjectName(const char *name,char *ObjectName,int *pRefType){ 75 void SplitObjectName(const char *name,char *ObjectName, ReferenceKind &referenceFind ) 76 { 77 referenceFind = RefNon; 78 76 79 int i4; 77 80 for(i4=lstrlen(name)-1;i4>=0;i4--){ … … 82 85 else{ 83 86 //参照タイプを判別 84 if(name[i4]=='.') *pRefType=DEF_OBJECT; 85 else *pRefType=DEF_PTR_OBJECT; 87 if(name[i4]=='.') 88 { 89 referenceFind = RefDot; 90 } 91 else 92 { 93 referenceFind = RefPointer; 94 } 86 95 87 96 if(i4==0) GetWithName(ObjectName); … … 109 118 //オブジェクト名を取得 110 119 char ObjectName[VN_SIZE]; 111 int RefType;112 SplitObjectName(fullCallName,ObjectName, &RefType);120 ReferenceKind referenceKind; 121 SplitObjectName(fullCallName,ObjectName, referenceKind ); 113 122 114 123 … … 131 140 132 141 if( isCallOn ){ 133 if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName ,RefType) ){142 if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName ) ){ 134 143 return false; 135 144 } … … 192 201 //オブジェクト名を取得 193 202 char ObjectName[VN_SIZE]; 194 int RefType;195 SplitObjectName(VarName,ObjectName, &RefType);203 ReferenceKind referenceKind; 204 SplitObjectName(VarName,ObjectName, referenceKind ); 196 205 197 206 //オーバーロード用の関数リストを作成 … … 216 225 if(pUserProc){ 217 226 //呼び出し 218 Opcode_CallProc(Parameter,pUserProc,0,ObjectName ,RefType);227 Opcode_CallProc(Parameter,pUserProc,0,ObjectName); 219 228 220 229 resultType = pUserProc->ReturnType(); … … 235 244 //オブジェクト名を取得 236 245 char ObjectName[VN_SIZE]; 237 int RefType;238 SplitObjectName(VarName,ObjectName, &RefType);246 ReferenceKind referenceKind; 247 SplitObjectName(VarName,ObjectName, referenceKind ); 239 248 240 249 //オーバーロード用の関数リストを作成 -
trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
r288 r290 124 124 return type; 125 125 } 126 int GetTypeSize(int type,LONG_PTR lpIndex){127 if(type==DEF_LONG){128 if(lpIndex==LITERAL_NULL||lpIndex==LITERAL_M128_0||lpIndex==LITERAL_0_255)129 return sizeof(BYTE);130 else if(lpIndex==LITERAL_M32768_0||lpIndex==LITERAL_0_65535)131 return sizeof(WORD);132 133 return sizeof(DWORD);134 }135 136 //整数型137 if(type==DEF_INT64||type==DEF_QWORD)138 return sizeof(_int64);139 else if(type==DEF_LONG||type==DEF_DWORD)140 return sizeof(DWORD);141 else if(type==DEF_INTEGER||type==DEF_WORD)142 return sizeof(WORD);143 else if(type==DEF_SBYTE||type==DEF_BYTE || type == DEF_BOOLEAN)144 return sizeof(BYTE);145 146 //実数型147 else if(type==DEF_DOUBLE) return sizeof(double);148 else if(type==DEF_SINGLE) return sizeof(float);149 150 //文字型151 else if( type == DEF_CHAR ){152 if( Smoothie::IsUnicode() ) return sizeof( WORD );153 return sizeof( BYTE );154 }155 156 //ポインタ型157 else if(IsPtrType(type)) return PTR_SIZE;158 159 else if( type == DEF_STRUCT ){160 if(lpIndex == 0 || lpIndex == -1){161 SetError(300,NULL,cp);162 return 0;163 }164 165 const CClass *pobj_c=(CClass *)lpIndex;166 167 return pobj_c->GetSize();168 }169 170 else if(type==DEF_OBJECT){171 return PTR_SIZE;172 }173 else{174 SetError(300,NULL,cp);175 }176 return 0;177 }178 126 int GetPtrType(int type){ 179 127 return MAKE_PTR_TYPE(NATURAL_TYPE(type),PTR_LEVEL(type)+1); … … 475 423 476 424 477 bool GetMemberType( const CClass &objClass, const char *lpszMember, Type &resultType, BOOL bPrivateAccess, bool isErrorEnabled){ 425 bool GetMemberType( const Type &classType, const char *lpszMember, Type &resultType, BOOL bPrivateAccess, bool isErrorEnabled) 426 { 427 const CClass &objClass = classType.GetClass(); 428 478 429 extern int cp; 479 430 … … 522 473 resultType = pMember->GetType(); 523 474 475 476 ///////////////////////////////////////////////////////// 477 // ☆★☆ ジェネリクスサポート ☆★☆ 478 479 if( resultType.IsTypeParameter() ) 480 { 481 // 型パラメータだったとき 482 if( classType.HasActualGenericType() ) 483 { 484 // TODO: GetDummyActualGenericTypeを適切な形に実装し直す 485 resultType = classType.GetDummyActualGenericType(); 486 } 487 else 488 { 489 // TODO: ベースオブジェクト(指定されていないときはObjectクラス)にセットする 490 resultType.SetBasicType( DEF_OBJECT ); 491 } 492 } 493 494 // 495 ///////////////////////////////////////////////////////// 496 497 524 498 //ポインタ変数の場合 525 499 if( resultType.IsPointer() ){ … … 539 513 //入れ子構造の場合 540 514 541 return GetMemberType( pMember->GetType() .GetClass(),515 return GetMemberType( pMember->GetType(), 542 516 NestMember, 543 517 resultType, … … 633 607 } 634 608 635 return GetMemberType(*compiler.pCompilingClass,variable,resultType,1,isErrorEnabled); 609 return GetMemberType( 610 Type( DEF_OBJECT, *compiler.pCompilingClass ), 611 variable, 612 resultType, 613 1, 614 isErrorEnabled 615 ); 636 616 } 637 617 … … 729 709 if(member[0]){ 730 710 if( NATURAL_TYPE( resultType.GetBasicType() )==DEF_OBJECT 731 || NATURAL_TYPE( resultType.GetBasicType() )==DEF_STRUCT){ 732 return GetMemberType(resultType.GetClass(),member,resultType,0,isErrorEnabled); 711 || NATURAL_TYPE( resultType.GetBasicType() )==DEF_STRUCT) 712 { 713 return GetMemberType(resultType,member,resultType,0,isErrorEnabled); 733 714 } 734 715 } … … 753 734 } 754 735 755 bool GetVarOffsetReadOnly(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){ 736 bool GetVarOffsetReadOnly(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ) 737 { 756 738 //読み取り専用で変数へアクセス 757 739 return GetVarOffset( … … 764 746 ); 765 747 } 766 bool GetVarOffsetReadWrite(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){ 748 bool GetVarOffsetReadWrite(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ) 749 { 767 750 //読み書き両用で変数へアクセス 768 751 return GetVarOffset( -
trunk/abdev/BasicCompiler_Common/VariableOpe.h
r206 r290 14 14 int GetSignedType(int type); 15 15 int GetUnsignedType(int type); 16 int GetTypeSize(int type,LONG_PTR lpIndex);17 16 int GetPtrType(int type); 18 17 BOOL GetTypeName(int type,LONG_PTR lpIndex,char *name); … … 23 22 BOOL CheckVarNameError(char *name,int nowLine); 24 23 int JumpSubScripts( const Subscripts &subscripts ); 25 bool GetMemberType( const CClass &objClass, const char *lpszMember, Type &resultType, BOOL bPrivateAccess, bool isErrorEnabled);24 bool GetMemberType( const Type &classType, const char *lpszMember, Type &resultType, BOOL bPrivateAccess, bool isErrorEnabled); 26 25 bool GetVarType( const char *nameBuffer, Type &resultType, bool isError); 27 26 bool GetVarOffsetReadOnly(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL ); -
trunk/abdev/BasicCompiler_Common/calculation.cpp
r265 r290 139 139 140 140 int size1,size2; 141 size1= GetTypeSize(type1,index1);142 size2= GetTypeSize(type2,index2);141 size1=Type(type1,index1).GetSize(); 142 size2=Type(type2,index2).GetSize(); 143 143 if(size1<size2){ 144 144 size1=size2; -
trunk/abdev/BasicCompiler_Common/common.h
r288 r290 352 352 int GetCallProcName(char *buffer,char *name); 353 353 int GetProc(char *name,void **ppInfo); 354 void SplitObjectName(const char *name,char *ObjectName, int *pRefType);354 void SplitObjectName(const char *name,char *ObjectName, ReferenceKind &referenceFind ); 355 355 bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true ); 356 356 bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType); -
trunk/abdev/BasicCompiler_Common/error.cpp
r287 r290 388 388 389 389 #define STRING_SYSTEM_DECLAREHANDLE "*_System_DeclareHandle_" 390 void DifferentTypeError( const int VarType,LONG_PTR VarIndex,const int CalcType,LONG_PTR CalcIndex,const int iWarning,const char *pszFuncName,const int ParmNum){390 void DifferentTypeError( const Type &varType, const Type &calcFormalType, const int iWarning,const char *pszFuncName,const int ParmNum){ 391 391 ////////////////////////// 392 392 // キャストに関する警告 393 393 ////////////////////////// 394 char temporary[255],temp2[255],temp3[255]; 395 396 if(IS_LITERAL(CalcIndex)) CalcIndex=-1; 394 char temporary[255]; 395 Type calcType( calcFormalType ); 396 397 if(IS_LITERAL(calcType.GetIndex())) 398 { 399 calcType.SetIndex( -1 ); 400 } 397 401 398 402 if(pszFuncName) … … 400 404 else temporary[0]=0; 401 405 402 if(!GetTypeName(VarType,VarIndex,temp2)) lstrcpy(temp2,"Any"); 403 if(memcmp(temp2,STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0){ 404 memmove(temp2, 405 temp2+lstrlen(STRING_SYSTEM_DECLAREHANDLE), 406 lstrlen(temp2+lstrlen(STRING_SYSTEM_DECLAREHANDLE))+1); 407 } 408 if(!GetTypeName(CalcType,CalcIndex,temp3)) lstrcpy(temp3,"Any"); 409 if(memcmp(temp3,STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0){ 410 memmove(temp3, 411 temp3+lstrlen(STRING_SYSTEM_DECLAREHANDLE), 412 lstrlen(temp3+lstrlen(STRING_SYSTEM_DECLAREHANDLE))+1); 413 } 414 sprintf(temporary+lstrlen(temporary),"%sから%s",temp3,temp2); 406 std::string varTypeName = Compiler::TypeToString( varType ); 407 if(memcmp( varTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0) 408 { 409 varTypeName = varTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) ); 410 } 411 412 std::string calcTypeName = Compiler::TypeToString( calcType ); 413 if(memcmp( calcTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0) 414 { 415 calcTypeName = calcTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) ); 416 } 417 sprintf(temporary+lstrlen(temporary),"%sから%s",calcTypeName.c_str(),varTypeName.c_str()); 415 418 416 419 extern int cp; … … 420 423 } 421 424 422 bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum){ 423 424 if(VarType==DEF_STRUCT||CalcType==DEF_STRUCT){ 425 bool CheckDifferentType( const Type &varType,const Type &calcFormalType,const char *pszFuncName,const int ParmNum) 426 { 427 Type calcType( calcFormalType ); 428 429 if( varType.IsStruct() || calcType.IsStruct() ) 430 { 425 431 //いずれかが構造体場合 426 if( VarType != CalcType || lpVarIndex != lpCalcIndex ){ 427 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum); 432 if( !varType.Equals( calcType ) ) 433 { 434 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 428 435 return false; 429 436 } 430 437 } 431 438 432 if(VarType==DEF_OBJECT||CalcType==DEF_OBJECT){ 433 //いずれかがオブジェクトインスタンスの場合 434 if( VarType != CalcType ){ 435 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum); 439 if( varType.IsObject() || calcType.IsObject() ) 440 { 441 //いずれかがオブジェクトの場合 442 if( varType.GetBasicType() != calcType.GetBasicType() ) 443 { 444 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 436 445 return false; 437 446 } 438 447 439 CClass *pClass = (CClass *)lpVarIndex;440 if( !pClass->IsEqualsOrSubClass( (CClass *)lpCalcIndex ) ){448 if( !varType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ) 449 { 441 450 //等しくなく、派生クラスでもないとき 442 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum);451 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 443 452 return false; 444 453 } … … 449 458 if(bStrict==0) return true; 450 459 451 if(CalcType&FLAG_PTR){ 460 if( calcType.GetBasicType() & FLAG_PTR ) 461 { 452 462 //配列先頭フラグがたっている場合は、ポインタ型として扱う 453 CalcType=MAKE_PTR_TYPE(NATURAL_TYPE(CalcType),PTR_LEVEL(CalcType)+1); 454 } 455 456 if(IsPtrType(VarType)||IsPtrType(CalcType)){ 463 calcType.SetBasicType( MAKE_PTR_TYPE(NATURAL_TYPE(calcType.GetBasicType()),PTR_LEVEL(calcType.GetBasicType())+1) ); 464 } 465 466 if( varType.IsPointer() || calcType.IsPointer() ) 467 { 457 468 /* 右辺及び左辺のいずれかがポインタ型の場合は、 458 469 型チェックを行う。 459 470 ・同一の種類のポインタ型以外はエラーとする */ 460 471 461 if(IsPtrType(VarType)&&lpCalcIndex==LITERAL_NULL){ 472 if( varType.IsPointer() && calcType.GetIndex() == LITERAL_NULL ) 473 { 462 474 //リテラルNULL値の場合 463 475 return true; 464 476 } 465 477 466 if(VarType==DEF_PTR_VOID){ 478 if( varType.IsVoidPtr() ) 479 { 467 480 //左辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる 468 if(IsPtrType(CalcType)) return true; 469 } 470 471 if(CalcType==DEF_PTR_VOID){ 481 if( calcType.IsPointer() ) 482 { 483 return true; 484 } 485 } 486 487 if( calcType.IsVoidPtr() ) 488 { 472 489 //右辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる 473 if(IsPtrType(VarType)) return true; 474 } 475 476 if(VarType!=CalcType){ 477 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,2,pszFuncName,ParmNum); 490 if( varType.IsPointer() ) 491 { 492 return true; 493 } 494 } 495 496 if( varType.GetBasicType() != calcType.GetBasicType() ) 497 { 498 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum); 478 499 return true; 479 500 } 480 501 481 if(VarType==DEF_PTR_OBJECT){ 502 if( varType.IsObjectPtr() ) 503 { 482 504 //双方がオブジェクトポインタ型の場合 483 if( lpVarIndex!=lpCalcIndex){484 const CClass *pobj_tempClass;485 pobj_tempClass=(CClass *)lpCalcIndex;505 if( varType.GetIndex() != calcType.GetIndex() ) 506 { 507 const CClass *pobj_tempClass = &calcType.GetClass(); 486 508 while(pobj_tempClass&&(!IS_LITERAL((LONG_PTR)pobj_tempClass))){ 487 509 pobj_tempClass=&pobj_tempClass->GetSuperClass(); 488 510 489 if(lpVarIndex==(LONG_PTR)pobj_tempClass){ 511 if( &varType.GetClass() == pobj_tempClass ) 512 { 490 513 //継承先が等しいとき 491 514 return true; 492 515 } 493 516 } 494 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,2,pszFuncName,ParmNum);517 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum); 495 518 return true; 496 519 } … … 498 521 } 499 522 500 if(VarType==DEF_DOUBLE){ 501 if(Is64Type(CalcType)){ 523 if( varType.IsDouble() ) 524 { 525 if( calcType.Is64() ) 526 { 502 527 //64ビット整数値の場合は警告を出す 503 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 504 } 505 } 506 else if(VarType==DEF_SINGLE){ 507 if(Is64Type(CalcType)||CalcType==DEF_DOUBLE){ 528 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 529 } 530 } 531 else if( varType.IsSingle() ) 532 { 533 if( calcType.Is64() || calcType.IsDouble() ) 534 { 508 535 //64ビット整数値、またはDouble型の場合は警告を出す 509 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 510 } 511 } 512 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(char)){ 513 if(GetTypeSize(CalcType,lpCalcIndex)>sizeof(char)&& 514 lpCalcIndex!=LITERAL_NULL&& 515 lpCalcIndex!=LITERAL_M128_0&& 516 lpCalcIndex!=LITERAL_0_255){ 536 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 537 } 538 } 539 else if( varType.GetSize() == sizeof(char) ) 540 { 541 if( calcType.GetSize() > sizeof(char) 542 && calcType.GetIndex() != LITERAL_NULL 543 && calcType.GetIndex() != LITERAL_M128_0 544 && calcType.GetIndex() != LITERAL_0_255 ) 545 { 517 546 //8ビット整数値より大きな型で、リテラル値でもない場合は警告を出す 518 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 519 } 520 } 521 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(short)){ 522 if(GetTypeSize(CalcType,lpCalcIndex)>sizeof(short)&& 523 lpCalcIndex!=LITERAL_NULL&& 524 lpCalcIndex!=LITERAL_M128_0&& 525 lpCalcIndex!=LITERAL_0_255&& 526 lpCalcIndex!=LITERAL_M32768_0&& 527 lpCalcIndex!=LITERAL_0_65535){ 547 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 548 } 549 } 550 else if( varType.GetSize() == sizeof(short) ) 551 { 552 if( calcType.GetSize() > sizeof(short) 553 && calcType.GetIndex() != LITERAL_NULL 554 && calcType.GetIndex() != LITERAL_M128_0 555 && calcType.GetIndex() != LITERAL_0_255 556 && calcType.GetIndex() != LITERAL_M32768_0 557 && calcType.GetIndex() != LITERAL_0_65535 ) 558 { 528 559 //16ビット整数値より大きな型で、リテラル値でもない場合は警告を出す 529 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 530 } 531 } 532 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(long)){ 533 if(IsRealNumberType(CalcType)|| 534 (IsWholeNumberType(CalcType)&& 535 GetTypeSize(CalcType,lpCalcIndex)>sizeof(long)&& 536 lpCalcIndex!=LITERAL_NULL) 537 ){ 560 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 561 } 562 } 563 else if( varType.GetSize() == sizeof(long) ) 564 { 565 if( calcType.IsReal() 566 || ( calcType.IsWhole() && calcType.GetSize() > sizeof(long) && calcType.GetIndex() != LITERAL_NULL ) ) 567 { 538 568 /* 32ビット整数値より大きな型、または実数、 539 569 またはリテラル値でもない場合は警告を出す */ 540 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 541 } 542 } 543 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(_int64)){ 544 if(IsRealNumberType(CalcType)){ 570 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 571 } 572 } 573 else if( varType.GetSize() == sizeof(_int64) ) 574 { 575 if( calcType.IsReal() ) 576 { 545 577 //実数の場合は警告を出す 546 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum);578 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 547 579 } 548 580 } … … 550 582 return true; 551 583 } 552 bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum){553 return CheckDifferentType(554 varType.GetBasicType(),555 varType.GetIndex(),556 calcType.GetBasicType(),557 calcType.GetIndex(),558 pszFuncName,559 ParmNum );560 } -
trunk/abdev/BasicCompiler_Common/include/Class.h
r282 r290 9 9 10 10 class UserProc; 11 class CClass; 11 12 12 13 class InheritedInterface … … 48 49 // importされている名前空間 49 50 NamespaceScopesCollection importedNamespaces; 50 51 52 // 型パラメータ 53 GenericTypes formalGenericTypes; 54 51 55 // 継承クラス 52 56 const CClass *pSuperClass; … … 108 112 , classType( Class ) 109 113 , pSuperClass( NULL ) 114 , blittableType( Type() ) 110 115 , isReady( false ) 111 116 , fixedAlignment( 0 ) … … 124 129 , classType() 125 130 , pSuperClass( NULL ) 131 , blittableType( Type() ) 126 132 , isReady( false ) 127 133 , fixedAlignment( 0 ) … … 173 179 } 174 180 181 // 型パラメータ 182 void AddFormalGenericType( GenericType genericType ) 183 { 184 this->formalGenericTypes.push_back( genericType ); 185 } 186 bool IsExistFormalGenericTypeParameter( const std::string &name ) const 187 { 188 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes ) 189 { 190 if( genericType.GetName() == name ) 191 { 192 return true; 193 } 194 } 195 return false; 196 } 197 175 198 // 継承元クラス 176 199 bool HasSuperClass() const -
trunk/abdev/BasicCompiler_Common/include/Type.h
r271 r290 16 16 17 17 class CClass; 18 19 class GenericType; 20 typedef std::vector<GenericType> GenericTypes; 18 21 19 22 class Type{ … … 23 26 const CClass *pClass; 24 27 }; 28 GenericTypes actualGenericTypes; 25 29 26 30 // XMLシリアライズ用 … … 52 56 index( -1 ){} 53 57 54 Type( int basicType, LONG_PTR index ): 55 basicType( basicType ), 56 index( index ){} 58 Type( int basicType, LONG_PTR index ) 59 : basicType( basicType ) 60 , index( index ) 61 { 62 } 57 63 58 64 Type( int basicType, const CClass &objClass ): … … 60 66 index( (LONG_PTR)&objClass ){} 61 67 62 Type( const Type &type ): 63 basicType( type.basicType ), 64 index( type.index ){} 68 Type( const Type &type ) 69 : basicType( type.basicType ) 70 , index( type.index ) 71 , actualGenericTypes( type.actualGenericTypes ) 72 { 73 } 74 75 ~Type(); 76 77 void operator= ( const Type &type ) 78 { 79 basicType = type.basicType; 80 index = type.index; 81 actualGenericTypes = type.actualGenericTypes; 82 } 65 83 66 84 __inline int GetBasicType() const … … 72 90 return index; 73 91 } 74 const CClass &GetClass() const 75 { 76 return *pClass; 77 } 92 const CClass &GetClass() const; 78 93 79 94 void SetBasicType( int basicType ){ … … 85 100 void SetClassPtr( const CClass *pClass ) 86 101 { 102 int naturalBasicType = NATURAL_TYPE( basicType ); 103 if( !HasMember() ) 104 { 105 Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" ); 106 } 87 107 this->pClass = pClass; 88 108 } … … 98 118 SetBasicType( basicType ); 99 119 this->pClass = pClass; 120 } 121 void SetActualGenericTypes( const GenericTypes &genericTypes ) 122 { 123 this->actualGenericTypes = genericTypes; 100 124 } 101 125 … … 142 166 bool IsObject() const; 143 167 bool IsObjectPtr() const; 168 bool IsTypeParameter() const; 144 169 bool IsObjectClass() const; 145 170 bool IsStringClass() const; … … 150 175 bool HasMember() const; 151 176 152 void operator= ( const Type &type ){ 153 basicType = type.basicType; 154 index = type.index; 155 } 177 // 未完成 178 const Type &GetDummyActualGenericType() const; 179 bool HasActualGenericType() const; 156 180 157 181 … … 163 187 static const char *Type::BasicTypeToCharPtr( const Type &type ); 164 188 static int GetBasicTypeFromSimpleName( const char *variable ); 189 }; 190 191 class GenericType 192 { 193 std::string name; 194 Type type; 195 public: 196 GenericType( const std::string &name, const Type &type ) 197 : name( name ) 198 , type( type ) 199 { 200 } 201 GenericType() 202 { 203 } 204 ~GenericType() 205 { 206 } 207 208 const std::string &GetName() const 209 { 210 return name; 211 } 212 const Type &GetType() const 213 { 214 return type; 215 } 165 216 }; 166 217 -
trunk/abdev/BasicCompiler_Common/src/Class.cpp
r282 r290 908 908 source[i+1]==ESC_TYPE|| 909 909 source[i+1]==ESC_INTERFACE 910 )){ 911 int nowLine; 912 nowLine=i; 910 )) 911 { 912 int nowLine = i; 913 i += 2; 914 915 Type blittableType; 916 if(memicmp(source.GetBuffer()+i,"Align(",6)==0){ 917 //アラインメント修飾子 918 i+=6; 919 i=JumpStringInPare(source.GetBuffer(),i)+1; 920 } 921 else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){ 922 // Blittable修飾子 923 i+=10; 924 i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1; 925 compiler.StringToType( temporary, blittableType ); 926 } 927 928 bool isEnum = false; 929 if( source[i] == 1 && source[i+1] == ESC_ENUM ){ 930 // 列挙型の場合 931 isEnum = true; 913 932 914 933 i+=2; 915 Type blittableType; 916 if(memicmp(source.GetBuffer()+i,"Align(",6)==0){ 917 //アラインメント修飾子 918 i+=6; 919 i=JumpStringInPare(source.GetBuffer(),i)+1; 920 } 921 else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){ 922 // Blittable修飾子 923 i+=10; 924 i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1; 925 compiler.StringToType( temporary, blittableType ); 926 } 927 928 bool isEnum = false; 929 if( source[i] == 1 && source[i+1] == ESC_ENUM ){ 930 // 列挙型の場合 931 isEnum = true; 932 933 i+=2; 934 } 935 936 int i2; 937 char temporary[VN_SIZE]; 938 for(i2=0;;i++,i2++){ 939 if(!IsVariableChar(source[i])){ 940 temporary[i2]=0; 941 break; 942 } 943 temporary[i2]=source[i]; 944 } 945 946 //クラスを追加 947 CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine); 948 if( pClass ){ 949 if( source[nowLine+1] == ESC_CLASS ){ 950 if( isEnum ){ 951 pClass->SetClassType( CClass::Enum ); 952 } 953 else{ 954 pClass->SetClassType( CClass::Class ); 955 } 956 } 957 else if( source[nowLine+1] == ESC_INTERFACE ){ 958 pClass->SetClassType( CClass::Interface ); 934 } 935 936 for(i2=0;;i++,i2++){ 937 if(!IsVariableChar(source[i])){ 938 temporary[i2]=0; 939 break; 940 } 941 temporary[i2]=source[i]; 942 } 943 944 //クラスを追加 945 CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine); 946 if( pClass ){ 947 if( source[nowLine+1] == ESC_CLASS ){ 948 if( isEnum ){ 949 pClass->SetClassType( CClass::Enum ); 959 950 } 960 951 else{ 961 pClass->SetClassType( CClass:: Structure);952 pClass->SetClassType( CClass::Class ); 962 953 } 963 954 } 964 965 // Blittable型の場合 966 if( !blittableType.IsNull() ){ 967 pClass->SetBlittableType( blittableType ); 968 969 // Blittable型として登録 970 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) ); 971 } 955 else if( source[nowLine+1] == ESC_INTERFACE ){ 956 pClass->SetClassType( CClass::Interface ); 957 } 958 else{ 959 pClass->SetClassType( CClass::Structure ); 960 } 961 } 962 963 // Blittable型の場合 964 if( !blittableType.IsNull() ){ 965 pClass->SetBlittableType( blittableType ); 966 967 // Blittable型として登録 968 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) ); 969 } 972 970 } 973 971 } … … 1266 1264 if(!pobj_c) continue; 1267 1265 1266 compiler.pCompilingClass = pobj_c; 1267 1268 1268 if(lpszInheritsClass){ 1269 1269 if( pobj_c->GetName() != lpszInheritsClass ){ … … 1277 1277 continue; 1278 1278 } 1279 1280 1281 ///////////////////////////////////////////////////////// 1282 // ☆★☆ ジェネリクスサポート ☆★☆ 1283 if( basbuf[i] == '<' ) 1284 { 1285 // 型パラメータを取得 1286 i++; 1287 GetIdentifierToken( temporary, basbuf, i ); 1288 1289 pobj_c->AddFormalGenericType( GenericType( temporary, Type(DEF_OBJECT,*GetObjectClassPtr()) ) ); 1290 1291 if( basbuf[i] == '>' ) 1292 { 1293 i++; 1294 } 1295 else 1296 { 1297 SetError(); 1298 } 1299 } 1300 ///////////////////////////////////////////////////////// 1301 1279 1302 1280 1303 pobj_c->SetFixedAlignment( iAlign ); -
trunk/abdev/BasicCompiler_Common/src/Compiler.cpp
r273 r290 19 19 bool Compiler::StringToType( const string &typeName, Type &type ){ 20 20 type.SetIndex( -1 ); 21 22 23 ///////////////////////////////////////////////////////// 24 // ☆★☆ ジェネリクスサポート ☆★☆ 25 26 if( strstr( typeName.c_str(), "<" ) ) 27 { 28 // ジェネリッククラスをインスタンス化した型の場合 29 int i = 0; 30 char className[VN_SIZE], typeParameter[VN_SIZE]; 31 GetIdentifierToken( className, typeName.c_str(), i ); 32 i++; 33 GetIdentifierToken( typeParameter, typeName.c_str(), i ); 34 35 // ジェネリクスクラスを取得 36 const CClass *pGenericClass = compiler.GetObjectModule().meta.GetClasses().Find( className ); 37 38 // 型パラメータの型情報を取得 39 Type baseType; 40 StringToType( typeParameter, baseType ); 41 42 GenericTypes genericTypes; 43 genericTypes.push_back( GenericType( "(non support)", baseType ) ); 44 45 // 基本型をセット 46 type.SetBasicType( DEF_OBJECT ); 47 48 // 拡張情報をセット 49 type.SetClassPtr( pGenericClass ); 50 type.SetActualGenericTypes( genericTypes ); 51 52 return true; 53 } 54 55 // 56 ///////////////////////////////////////////////////////// 57 21 58 22 59 if( typeName[0] == '*' ){ … … 74 111 const CClass *pobj_c = compiler.GetObjectModule().meta.GetClasses().Find( typeName ); 75 112 if(pobj_c){ 76 type.SetClassPtr( pobj_c );77 78 113 if( pobj_c->IsStructure() ){ 79 114 type.SetBasicType( DEF_STRUCT ); … … 82 117 type.SetBasicType( DEF_OBJECT ); 83 118 } 119 type.SetClassPtr( pobj_c ); 84 120 return true; 85 121 } 122 123 124 ///////////////////////////////////////////////////////// 125 // ☆★☆ ジェネリクスサポート ☆★☆ 126 127 // 型パラメータ 128 if( compiler.pCompilingClass ) 129 { 130 // クラスに属するメソッドをコンパイルしているとき 131 if( compiler.pCompilingClass->IsExistFormalGenericTypeParameter( typeName ) ) 132 { 133 // コンパイル中クラスにおけるジェネリクス用の型パラメータのとき 134 type.SetBasicType( DEF_TYPE_PARAMETER ); 135 type.SetClassPtr( compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ); 136 return true; 137 } 138 } 139 140 // 141 ///////////////////////////////////////////////////////// 86 142 87 143 return false; -
trunk/abdev/BasicCompiler_Common/src/LexicalScope.cpp
r288 r290 161 161 const CMethod *method = (*pVariabls)[indexSystemGC]->GetType().GetClass().GetDestructorMethod(); 162 162 if( method ){ 163 Opcode_CallProc("",&method->GetUserProc(),0,(*pVariabls)[indexSystemGC]->GetName().c_str() ,DEF_OBJECT);163 Opcode_CallProc("",&method->GetUserProc(),0,(*pVariabls)[indexSystemGC]->GetName().c_str()); 164 164 } 165 165 } -
trunk/abdev/BasicCompiler_Common/src/Source.cpp
r287 r290 815 815 816 816 // basic.sbpをインクルード 817 //const char *headCode = "#include <basic.sbp>\n";818 const char *headCode = "\n";817 const char *headCode = "#include <basic.sbp>\n"; 818 //const char *headCode = "\n"; 819 819 Realloc( length + lstrlen(headCode) ); 820 820 Text::SlideString( buffer, lstrlen(headCode) ); -
trunk/abdev/BasicCompiler_Common/src/Type.cpp
r206 r290 52 52 }; 53 53 54 Type::~Type() 55 { 56 } 57 54 58 bool Type::StringToBasicType( const string &typeName, int &basicType ){ 55 59 for( int i=0; ; i++ ){ … … 120 124 } 121 125 126 const CClass &Type::GetClass() const 127 { 128 if( !HasMember() ) 129 { 130 Jenga::Throw( "クラスまたは構造体でない型に対してGetClassを呼び出した" ); 131 } 132 133 return *pClass; 134 } 122 135 123 136 bool Type::Equals( const Type &type ) const … … 185 198 186 199 // 構造体 187 if( basicType == DEF_STRUCT ){ 200 if( IsStruct() ) 201 { 188 202 if( !pClass ){ 189 203 SmoothieException::Throw(); … … 195 209 196 210 // オブジェクト 197 if(basicType==DEF_OBJECT){ 211 if( IsObject() ) 212 { 198 213 if( GetClass().IsInterface() ){ 199 214 // vtblOffsetのサイズを含める … … 379 394 bool Type::IsObject() const 380 395 { 381 if( basicType == DEF_OBJECT ){382 return true;383 }384 return false;396 return ( 397 basicType == DEF_OBJECT 398 || IsTypeParameter() 399 ); 385 400 } 386 401 bool Type::IsObjectPtr() const … … 390 405 } 391 406 return false; 407 } 408 bool Type::IsTypeParameter() const 409 { 410 return ( basicType == DEF_TYPE_PARAMETER ); 392 411 } 393 412 bool Type::IsObjectClass() const … … 428 447 { 429 448 if( NATURAL_TYPE( basicType ) == DEF_OBJECT 430 || NATURAL_TYPE( basicType ) == DEF_STRUCT ){ 431 return true; 432 } 433 return false; 449 || NATURAL_TYPE( basicType ) == DEF_STRUCT 450 || NATURAL_TYPE( basicType ) == DEF_TYPE_PARAMETER 451 ){ 452 return true; 453 } 454 return false; 455 } 456 457 const Type &Type::GetDummyActualGenericType() const 458 { 459 return actualGenericTypes[0].GetType(); 460 } 461 bool Type::HasActualGenericType() const 462 { 463 return ( actualGenericTypes.size() > 0 ); 434 464 } 435 465
Note:
See TracChangeset
for help on using the changeset viewer.