Index: BasicCompiler32/NumOpe.cpp
===================================================================
--- BasicCompiler32/NumOpe.cpp	(revision 75)
+++ BasicCompiler32/NumOpe.cpp	(revision 76)
@@ -67,5 +67,5 @@
 }
 
-void NewStringObject(LPSTR lpszText){
+void NewStringObject( const char *str ){
 	///////////////////////////////////////////////////////
 	// lpszTextを元にStringオブジェクトを生成し、
@@ -73,11 +73,10 @@
 	///////////////////////////////////////////////////////
 
-	char *parameter = (char *)malloc( lstrlen( lpszText ) + 32 );
-	sprintf( parameter, "\"%s\"%c%c*Char", lpszText, 1, ESC_AS );
+	char *parameter = (char *)malloc( lstrlen( str ) + 32 );
+	sprintf( parameter, "\"%s\"%c%c*Char", str, 1, ESC_AS );
 	SetStringQuotes( parameter );
 
 	extern CClass *pobj_StringClass;
-	Type baseTypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass };
-	Operator_New( *pobj_StringClass, "", parameter, baseTypeInfo );
+	Operator_New( *pobj_StringClass, "", parameter, Type( DEF_OBJECT, *pobj_StringClass ) );
 
 	free( parameter );
@@ -85,20 +84,25 @@
 
 
-int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap){
-	extern HANDLE hHeap;
+bool NumOpe( const char *expression,
+			const Type &baseType,
+			Type &resultType,
+			BOOL *pbUseHeap ){
+
 	int i,i2,i3,i4;
-	char temporary[8192],temp2[1024],temp3[1024];
-
-	if(Command[0]=='\0'){
+	char temporary[1024],temp2[1024],temp3[1024];
+
+	if(expression[0]=='\0'){
 		SetError(1,NULL,cp);
-		return -1;
-	}
-
-	if(Command[0]==1&& Command[1]==ESC_NEW ){
+		return false;
+	}
+
+	if(expression[0]==1&& expression[1]==ESC_NEW ){
 		//New演算子（オブジェクト生成）
-		Type baseTypeInfo = { BaseType, lpBaseIndex };
-		int resultType = Operator_New(Command+2,plpIndex, baseTypeInfo );
-
-		return resultType;
+
+		if( !Operator_New( expression+2, baseType, resultType ) ){
+			return false;
+		}
+
+		return true;
 	}
 
@@ -112,9 +116,9 @@
 	long stack[255];
 	int pnum;
-	if(!GetNumOpeElements(Command,&pnum,values,calc,stack)){
+	if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
 		for(i=0;i<pnum;i++){
 			if(values[i]) HeapDefaultFree(values[i]);
 		}
-		return 0;
+		return false;
 	}
 
@@ -146,5 +150,5 @@
 	double dbl;
 	int sp;
-	int type[255];
+	int type_stack[255];
 	LONG_PTR index_stack[255];
 	BOOL bUseHeap[255];
@@ -155,8 +159,7 @@
 
 		if(idCalc){
-			if(type[sp-2]==DEF_OBJECT){
+			if(type_stack[sp-2]==DEF_OBJECT){
 				//オーバーロードされたオペレータを呼び出す
-				Type BaseTypeInfo={BaseType,lpBaseIndex};
-				i2=CallOperatorProc(idCalc,&BaseTypeInfo,type,index_stack,bUseHeap,sp);
+				i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
 				if(i2==0){
 					if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
@@ -171,5 +174,5 @@
 			}
 
-			if(!CheckCalcType(idCalc,type,sp)) goto error;
+			if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
 		}
 
@@ -192,10 +195,7 @@
 StrLiteral:
 
-					if(BaseType==DEF_OBJECT){
-						CClass *pobj_Class;
-						pobj_Class=(CClass *)lpBaseIndex;
-						Type BaseTypeInfo = {BaseType,lpBaseIndex};
-						if(IsStringObjectType(BaseTypeInfo)){
-							//要求タイプがオブジェクトであり、Stringの受け入れが可能な場合
+					if( baseType.IsObject() ){
+						if( baseType.IsStringObject() ){
+							//要求タイプがStringのとき
 
 							//String型オブジェクトを生成
@@ -203,5 +203,5 @@
 
 							extern CClass *pobj_StringClass;
-							type[sp]=DEF_OBJECT;
+							type_stack[sp]=DEF_OBJECT;
 							index_stack[sp]=(LONG_PTR)pobj_StringClass;
 							bLiteralCalculation=0;
@@ -213,6 +213,5 @@
 
 
-					type[sp]=typeOfPtrChar;
-					index_stack[sp]=LITERAL_STRING;
+					type_stack[sp]=typeOfPtrChar;
 					bLiteralCalculation=0;
 
@@ -252,8 +251,8 @@
 						i4=GetStringInPare_RemovePare(temp2,term+i2+1);
 
-						int idProc;
 						void *pInfo;
-						idProc=GetProc(temporary,&pInfo);
-
+						int idProc=GetProc(temporary,(void **)&pInfo);
+
+						Type resultType;
 						if(idProc){
 							//閉じカッコ")"に続く文字がNULLでないとき
@@ -272,6 +271,6 @@
 							////////////////
 
-							i2=CallProc(idProc,pInfo,temporary,temp2,&index_stack[sp]);
-							if(i2==-1){
+							CallProc(idProc,pInfo,temporary,temp2,resultType);
+							if(resultType.IsNull()){
 								//戻り値が存在しないとき
 								for(i2=2;;i2++){
@@ -292,16 +291,19 @@
 
 							//大きな型への暗黙の変換
-							type[sp]=AutoBigCast(BaseType,i2);
+							type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
+							index_stack[sp] = resultType.GetIndex();
 							bLiteralCalculation=0;
 
 							//スタックへプッシュ
-							PushReturnValue(i2);
-
-							if(Is64Type(type[sp])&&IsWholeNumberType(i2)&&GetTypeSize(i2,-1)<=sizeof(long)){
-								//必要に応じて64ビット拡張
-								ExtendStackTo64(i2);
+							PushReturnValue( resultType.GetBasicType() );
+
+							if( Is64Type(type_stack[sp])
+								&& resultType.IsWhole()
+								&& resultType.GetBasicSize() <= sizeof(long) ){
+									//必要に応じて64ビット拡張
+									ExtendStackTo64( resultType.GetBasicType() );
 							}
 
-							if(i2==DEF_STRUCT){
+							if( resultType.IsStruct() ){
 								//構造体が戻ったときはヒープ領域にインスタンスが格納されている
 								//※後にfreeする必要あり
@@ -321,11 +323,14 @@
 
 							//マクロ関数の場合
-							type[sp]=NumOpe(temp3,0,0,&index_stack[sp]);
-
-							if(!IS_LITERAL(index_stack[sp])){
+							NumOpe(temp3,Type(),resultType);
+
+							if(!IS_LITERAL(resultType.GetIndex())){
 								//リテラル値ではなかったとき
 								bLiteralCalculation=0;
 							}
 
+							type_stack[sp] = resultType.GetBasicType();
+							index_stack[sp] = resultType.GetIndex();
+
 							sp++;
 							break;
@@ -335,15 +340,14 @@
 
 
-
+					//インデクサ（getアクセサ）
 					char variable[VN_SIZE],array_element[VN_SIZE];
-					CClass *pobj_c;
 					GetArrayElement(term,variable,array_element);
 					if(array_element[0]){
-						i2=GetVarType(variable,(LONG_PTR *)&pobj_c,0);
-						if(i2==DEF_OBJECT){
-							Type RetTypeInfo;
-							CallIndexerGetterProc(pobj_c,variable,array_element,RetTypeInfo);
-							type[sp]=RetTypeInfo.type;
-							index_stack[sp]=RetTypeInfo.u.lpIndex;
+						Type resultType;
+						GetVarType(variable,resultType,0);
+						if( resultType.IsObject() ){
+							CallIndexerGetterProc(&resultType.GetClass(),variable,array_element,resultType);
+							type_stack[sp]=resultType.GetBasicType();
+							index_stack[sp]=resultType.GetIndex();
 							bLiteralCalculation=0;
 
@@ -359,7 +363,7 @@
 					// Nothing
 					if( lstrcmp( term, "Nothing" ) == 0 ){
-						type[sp] = DEF_OBJECT;
-						if( BaseType == DEF_OBJECT ){
-							index_stack[sp] = lpBaseIndex;
+						type_stack[sp] = DEF_OBJECT;
+						if( baseType.IsObject() ){
+							index_stack[sp] = baseType.GetIndex();
 						}
 						else{
@@ -377,10 +381,16 @@
 
 
+					if( (string)term=="value"){
+						int test=0;
+					}
+
 
 					RELATIVE_VAR RelativeVar;
+					Type varType;
 					if(GetVarOffset(
 						false,	//エラー表示あり
 						false,	//読み込み専用
-						term,&i2,&RelativeVar,&index_stack[sp])){
+						term,
+						&RelativeVar,varType)){
 						//////////
 						// 変数
@@ -388,10 +398,11 @@
 
 						//大きな型への暗黙の変換
-						type[sp]=AutoBigCast(BaseType,i2);
+						type_stack[sp]=AutoBigCast(baseType.GetBasicType(),varType.GetBasicType());
+						index_stack[sp] = varType.GetIndex();
 						bLiteralCalculation=0;
 
-						if(i2&FLAG_PTR){
+						if(varType.GetBasicType()&FLAG_PTR){
 							//配列ポインタ
-							type[sp]=GetPtrType(i2^FLAG_PTR,index_stack[sp]);
+							type_stack[sp]=GetPtrType(varType.GetBasicType()^FLAG_PTR);
 
 							SetVarPtrToEax(&RelativeVar);
@@ -400,39 +411,38 @@
 							op_push(REG_EAX);
 						}
-						else if(i2==DEF_DOUBLE||
-							i2==DEF_INT64||
-							i2==DEF_QWORD){
+						else if( varType.IsStruct() ){
+							//構造体ポインタをeaxへ格納（構造体は値型）
+							SetVarPtrToEax(&RelativeVar);
+
+							//push eax
+							op_push(REG_EAX);
+						}
+						else if( varType.GetBasicSize() == sizeof(_int64) ){
 							//64ビット型
 							PushDoubleVariable(&RelativeVar);
 						}
-						else if(i2==DEF_LONG||i2==DEF_DWORD||i2==DEF_SINGLE||
-							IsPtrType(i2) || i2==DEF_OBJECT){
+						else if( varType.GetBasicSize() == sizeof(long) ){
 							//32ビット型
 							PushLongVariable(&RelativeVar);
 						}
-						else if(i2==DEF_INTEGER || (isUnicode&&i2==DEF_CHAR)){
+						else if( varType.IsInteger() ){
 							PushIntegerVariable(&RelativeVar);
 						}
-						else if(i2==DEF_WORD){
+						else if( varType.IsWord() ){
 							PushWordVariable(&RelativeVar);
 						}
-						else if(i2==DEF_SBYTE || (isUnicode==false&&i2==DEF_CHAR)){
+						else if( varType.IsSByte() ){
 							PushCharVariable(&RelativeVar);
 						}
-						else if(i2==DEF_BYTE||i2==DEF_BOOLEAN){
+						else if( varType.IsByte() || varType.IsBoolean() ){
 							PushByteVariable(&RelativeVar);
 						}
-						else if(i2==DEF_STRUCT){
-							//構造体ポインタをeaxへ格納（構造体は値型）
-							SetVarPtrToEax(&RelativeVar);
-
-							//push eax
-							op_push(REG_EAX);
-						}
 						else SetError(11,term,cp);
 
-						if(Is64Type(type[sp])&&IsWholeNumberType(i2)&&GetTypeSize(i2,-1)<=sizeof(long)){
+						if( Is64Type(type_stack[sp])
+							&& varType.IsWhole()
+							&& varType.GetBasicSize()<=sizeof(long)){
 							//必要に応じて64ビット拡張
-							ExtendStackTo64(i2);
+								ExtendStackTo64( varType.GetBasicType() );
 						}
 
@@ -448,5 +458,5 @@
 					i3 = CDBConst::obj.GetType(term);
 					if(i3){
-						type[sp]=i3;
+						type_stack[sp]=i3;
 						if(IsRealNumberType(i3)){
 							//実数
@@ -483,5 +493,5 @@
 					i3=GetTypeFixed(term,&lp);
 					if(i3!=-1){
-						type[sp]=i3|FLAG_CAST;
+						type_stack[sp]=i3|FLAG_CAST;
 						index_stack[sp]=lp;
 						sp++;
@@ -500,17 +510,16 @@
 
 					if(GetSubHash(VarName,0)){
-						Type RetTypeInfo;
-						CallPropertyMethod(term,NULL,&RetTypeInfo);
+						Type resultType;
+						CallPropertyMethod(term,NULL,resultType);
 
 						//大きな型への暗黙の変換
-						type[sp]=AutoBigCast(BaseType,RetTypeInfo.type);
-
-						index_stack[sp]=RetTypeInfo.u.lpIndex;
+						type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
+						index_stack[sp]=resultType.GetIndex();
 						bLiteralCalculation=0;
 
 						//スタックへプッシュ
-						PushReturnValue(RetTypeInfo.type);
-
-						if(type[sp]==DEF_STRUCT){
+						PushReturnValue( resultType.GetBasicType() );
+
+						if(type_stack[sp]==DEF_STRUCT){
 							//構造体が戻ったときはヒープ領域にインスタンスが格納されている
 							//※後にfreeする必要あり
@@ -527,13 +536,13 @@
 					bError=1;
 					SetError(3,term,cp);
-					type[sp]=DEF_DOUBLE;
+					type_stack[sp]=DEF_DOUBLE;
 				}
 				else{
 					//リテラル値
-					type[sp]=GetLiteralValue(term,&i64data,BaseType);
+					type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
 Literal:
-					if(type[sp]==DEF_INT64||
-						type[sp]==DEF_QWORD||
-						type[sp]==DEF_DOUBLE){
+					if(type_stack[sp]==DEF_INT64||
+						type_stack[sp]==DEF_QWORD||
+						type_stack[sp]==DEF_DOUBLE){
 						//64ビット（符号有り整数/実数）
 
@@ -544,5 +553,5 @@
 						op_push_V(*(long *)(&i64data));
 					}
-					else if(type[sp]==DEF_SINGLE){
+					else if(type_stack[sp]==DEF_SINGLE){
 						//single実数
 
@@ -566,5 +575,5 @@
 
 					//リテラル値の種類
-					if(Is64Type(type[sp])==0&&IsRealNumberType(type[sp])==0){
+					if(Is64Type(type_stack[sp])==0&&IsRealNumberType(type_stack[sp])==0){
 						//整数（符号有り/無し）
 
@@ -579,20 +588,20 @@
 				//value[sp-2] xor= value[sp-1]
 				//xor演算
-				if(!Calc_Xor(type,index_stack,&sp)) goto error;
+				if(!Calc_Xor(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_OR:
 				//value[sp-2] or= value[sp-1]
 				//or演算
-				if(!Calc_Or(type,index_stack,&sp)) goto error;
+				if(!Calc_Or(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_AND:
 				//value[sp-2] and= value[sp-1]
 				//and演算
-				if(!Calc_And(type,index_stack,&sp)) goto error;
+				if(!Calc_And(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_NOT:
 				//value[sp-1]=Not value[sp-1]
 				//NOT演算子
-				if(!Calc_Not(type,sp)) goto error;
+				if(!Calc_Not(type_stack,sp)) goto error;
 				break;
 
@@ -600,25 +609,25 @@
 			case CALC_PE:
 				//value[sp-2]<=value[sp-1]
-				if(!Calc_Relation_PE(type,index_stack,&sp)) goto error;
+				if(!Calc_Relation_PE(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_QE:
 				//value[sp-2]>=value[sp-1]
-				if(!Calc_Relation_QE(type,index_stack,&sp)) goto error;
+				if(!Calc_Relation_QE(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_P:
 				//value[sp-2]<value[sp-1]
-				if(!Calc_Relation_P(type,index_stack,&sp)) goto error;
+				if(!Calc_Relation_P(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_Q:
 				//value[sp-2]>value[sp-1]
-				if(!Calc_Relation_Q(type,index_stack,&sp)) goto error;
+				if(!Calc_Relation_Q(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_NOTEQUAL:
 				//value[sp-2]<>value[sp-1]
-				if(!Calc_Relation_NotEqual(type,&sp)) goto error;
+				if(!Calc_Relation_NotEqual(type_stack,&sp)) goto error;
 				break;
 			case CALC_EQUAL:
 				//value[sp-2]=value[sp-1]
-				if(!Calc_Relation_Equal(type,&sp)) goto error;
+				if(!Calc_Relation_Equal(type_stack,&sp)) goto error;
 				break;
 
@@ -626,9 +635,9 @@
 			case CALC_SHL:
 				//value[sp-2]=value[sp-2]<<value[sp-1]
-				if(!Calc_SHL(type,&sp)) goto error;
+				if(!Calc_SHL(type_stack,&sp)) goto error;
 				break;
 			case CALC_SHR:
 				//value[sp-2]=value[sp-2]>>value[sp-1]
-				if(!Calc_SHR(type,&sp)) goto error;
+				if(!Calc_SHR(type_stack,&sp)) goto error;
 				break;
 
@@ -637,5 +646,5 @@
 			case CALC_SUBTRACTION:
 			case CALC_PRODUCT:
-				if(!CalcTwoTerm_Arithmetic(idCalc,type,index_stack,&sp)) goto error;
+				if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
 				break;
 
@@ -643,34 +652,34 @@
 				//value[sp-2]%=value[sp-1]
 				//剰余演算
-				if(!Calc_Mod(type,&sp)) goto error;
+				if(!Calc_Mod(type_stack,&sp)) goto error;
 				break;
 			case CALC_QUOTIENT:
 				//value[sp-2]/=value[sp-1];
 				//除算
-				if(!Calc_Divide(type,&sp,BaseType)) goto error;
+				if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
 				break;
 			case CALC_INTQUOTIENT:
 				//value[sp-2]/=value[sp-1]
 				//整数除算
-				if(!Calc_IntDivide(type,index_stack,&sp)) goto error;
+				if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
 				break;
 			case CALC_MINUSMARK:
 				//value[sp-1]=-value[sp-1]
 				//符号反転
-				if(!Calc_MinusMark(type,sp)) goto error;
+				if(!Calc_MinusMark(type_stack,sp)) goto error;
 				index_stack[sp-1]=-1;
 				break;
 			case CALC_POWER:
 				//べき乗演算（浮動小数点演算のみ）
-				if(!Calc_Power(type,&sp)) goto error;
+				if(!Calc_Power(type_stack,&sp)) goto error;
 				break;
 			case CALC_AS:
 				//キャスト
-				if(!Calc_Cast(type,index_stack,&sp)) goto error;
+				if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
 				break;
 
 			case CALC_BYVAL:
 				//ポインタ型→参照型
-				if( PTR_LEVEL( type[sp-1] ) <= 0 ){
+				if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
 					//ポインタ型ではないとき
 					SetError( 3, NULL, cp );
@@ -678,5 +687,5 @@
 				}
 
-				type[sp-1] = PTR_LEVEL_DOWN( type[sp-1] );
+				type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
 
 				break;
@@ -697,6 +706,6 @@
 	if(bLiteralCalculation){
 		//右辺値が数値の定数式の場合
-		LONG_PTR lpClassIndex;
-		i2=StaticCalculation(true, Command,BaseType,&i64data,&lpClassIndex);
+		Type resultType;
+		StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
 
 		obp=BeforeObp;
@@ -705,7 +714,5 @@
 		pobj_Reloc->copy(pobj_BackReloc);
 
-		if(i2==DEF_INT64||
-			i2==DEF_QWORD||
-			i2==DEF_DOUBLE){
+		if( resultType.GetBasicSize() == sizeof(_int64) ){
 			//64ビット（符号有り整数/実数）
 
@@ -716,5 +723,5 @@
 			op_push_V(*(long *)(&i64data));
 		}
-		else if(i2==DEF_SINGLE){
+		else if( resultType.IsSingle() ){
 			//single実数
 
@@ -733,6 +740,6 @@
 			i3=(long)i64data;
 
-			if(i2==DEF_SBYTE||i2==DEF_BYTE||i2==DEF_BOOLEAN || (isUnicode==false&&i2==DEF_CHAR)) i3=i3&0x000000FF;
-			if(i2==DEF_INTEGER||i2==DEF_WORD || (isUnicode&&i2==DEF_CHAR)) i3=i3&0x0000FFFF;
+			if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF;
+			if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF;
 
 			//push term
@@ -740,6 +747,6 @@
 		}
 
-		type[0]=i2;
-		index_stack[0]=lpClassIndex;
+		type_stack[0]=resultType.GetBasicType();
+		index_stack[0]=resultType.GetIndex();
 	}
 	else{
@@ -748,14 +755,14 @@
 	}
 
-	if(plpIndex) *plpIndex=index_stack[0];
 	if(pbUseHeap) *pbUseHeap=bUseHeap[0];
 
-	int RetType;
-	RetType=type[0];
+	resultType.SetType( type_stack[0], index_stack[0] );
+
+	bool isSuccessful = true;
 	goto finish;
 
 
 error:
-	RetType=-1;
+	isSuccessful = false;
 	goto finish;
 
@@ -770,4 +777,4 @@
 	delete pobj_BackReloc;
 
-	return RetType;
+	return isSuccessful;
 }
