[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[4] | 3 | #include "../BasicCompiler_Common/common.h"
|
---|
| 4 |
|
---|
| 5 | #define STRING_SYSTEM_DECLAREHANDLE "*_System_DeclareHandle_"
|
---|
[290] | 6 | void DifferentTypeError( const Type &varType, const Type &calcFormalType, const int iWarning,const char *pszFuncName,const int ParmNum){
|
---|
[4] | 7 | //////////////////////////
|
---|
| 8 | // キャストに関する警告
|
---|
| 9 | //////////////////////////
|
---|
[290] | 10 | char temporary[255];
|
---|
| 11 | Type calcType( calcFormalType );
|
---|
[4] | 12 |
|
---|
[290] | 13 | if(IS_LITERAL(calcType.GetIndex()))
|
---|
| 14 | {
|
---|
| 15 | calcType.SetIndex( -1 );
|
---|
| 16 | }
|
---|
[4] | 17 |
|
---|
| 18 | if(pszFuncName)
|
---|
| 19 | sprintf(temporary,"\"%s\"の第%dパラメータが、",pszFuncName,ParmNum+1);
|
---|
| 20 | else temporary[0]=0;
|
---|
| 21 |
|
---|
[299] | 22 | std::string varTypeName = compiler.TypeToString( varType );
|
---|
[290] | 23 | if(memcmp( varTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0)
|
---|
| 24 | {
|
---|
| 25 | varTypeName = varTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) );
|
---|
[4] | 26 | }
|
---|
[290] | 27 |
|
---|
[299] | 28 | std::string calcTypeName = compiler.TypeToString( calcType );
|
---|
[290] | 29 | if(memcmp( calcTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0)
|
---|
| 30 | {
|
---|
| 31 | calcTypeName = calcTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) );
|
---|
[4] | 32 | }
|
---|
[290] | 33 | sprintf(temporary+lstrlen(temporary),"%sから%s",calcTypeName.c_str(),varTypeName.c_str());
|
---|
[4] | 34 |
|
---|
| 35 | extern int cp;
|
---|
[465] | 36 | if(iWarning==1) compiler.errorMessenger.Output(-101,temporary,cp);
|
---|
| 37 | else if(iWarning==2) compiler.errorMessenger.Output(-102,temporary,cp);
|
---|
| 38 | else if(iWarning==3) compiler.errorMessenger.Output(50,temporary,cp);
|
---|
[4] | 39 | }
|
---|
| 40 |
|
---|
[290] | 41 | bool CheckDifferentType( const Type &varType,const Type &calcFormalType,const char *pszFuncName,const int ParmNum)
|
---|
| 42 | {
|
---|
| 43 | Type calcType( calcFormalType );
|
---|
[4] | 44 |
|
---|
[290] | 45 | if( varType.IsStruct() || calcType.IsStruct() )
|
---|
| 46 | {
|
---|
[64] | 47 | //いずれかが構造体場合
|
---|
[290] | 48 | if( !varType.Equals( calcType ) )
|
---|
| 49 | {
|
---|
| 50 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
[64] | 51 | return false;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[290] | 55 | if( varType.IsObject() || calcType.IsObject() )
|
---|
| 56 | {
|
---|
[424] | 57 | //いずれかがオブジェクトではない場合
|
---|
| 58 | if( (!varType.IsObject()) || (!calcType.IsObject()) )
|
---|
[290] | 59 | {
|
---|
| 60 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
[45] | 61 | return false;
|
---|
[4] | 62 | }
|
---|
[59] | 63 |
|
---|
[448] | 64 | if( varType.IsDelegate() && calcType.IsDelegate() )
|
---|
[290] | 65 | {
|
---|
[448] | 66 | // デリゲート同士の比較の場合
|
---|
| 67 | // ※共変戻り値及び反辺引数をサポートすること
|
---|
[562] | 68 | const ::Delegate *pVarDelegate = &compiler.GetObjectModule().meta.ToDelegate( varType.GetClass() );
|
---|
| 69 | const ::Delegate *pCalcDelegate = &compiler.GetObjectModule().meta.ToDelegate( calcType.GetClass() );
|
---|
| 70 | if( !pVarDelegate->IsSimilar( *pCalcDelegate ) )
|
---|
[448] | 71 | {
|
---|
| 72 | // 等しいと見なされないとき
|
---|
| 73 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
| 74 | return false;
|
---|
| 75 | }
|
---|
[59] | 76 | }
|
---|
[448] | 77 | else
|
---|
| 78 | {
|
---|
| 79 | // 一般的なクラスの比較の場合
|
---|
| 80 |
|
---|
| 81 | if( !varType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) )
|
---|
| 82 | {
|
---|
| 83 | //等しくなく、派生クラスでもないとき
|
---|
| 84 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
| 85 | return false;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
[4] | 88 | }
|
---|
| 89 |
|
---|
[290] | 90 | if( calcType.GetBasicType() & FLAG_PTR )
|
---|
| 91 | {
|
---|
[4] | 92 | //配列先頭フラグがたっている場合は、ポインタ型として扱う
|
---|
[290] | 93 | calcType.SetBasicType( MAKE_PTR_TYPE(NATURAL_TYPE(calcType.GetBasicType()),PTR_LEVEL(calcType.GetBasicType())+1) );
|
---|
[4] | 94 | }
|
---|
| 95 |
|
---|
[290] | 96 | if( varType.IsPointer() || calcType.IsPointer() )
|
---|
| 97 | {
|
---|
[4] | 98 | /* 右辺及び左辺のいずれかがポインタ型の場合は、
|
---|
| 99 | 型チェックを行う。
|
---|
| 100 | ・同一の種類のポインタ型以外はエラーとする */
|
---|
| 101 |
|
---|
[290] | 102 | if( varType.IsPointer() && calcType.GetIndex() == LITERAL_NULL )
|
---|
| 103 | {
|
---|
[4] | 104 | //リテラルNULL値の場合
|
---|
[45] | 105 | return true;
|
---|
[4] | 106 | }
|
---|
| 107 |
|
---|
[290] | 108 | if( varType.IsVoidPtr() )
|
---|
| 109 | {
|
---|
[4] | 110 | //左辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
|
---|
[290] | 111 | if( calcType.IsPointer() )
|
---|
| 112 | {
|
---|
| 113 | return true;
|
---|
| 114 | }
|
---|
[4] | 115 | }
|
---|
| 116 |
|
---|
[290] | 117 | if( calcType.IsVoidPtr() )
|
---|
| 118 | {
|
---|
[4] | 119 | //右辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
|
---|
[290] | 120 | if( varType.IsPointer() )
|
---|
| 121 | {
|
---|
| 122 | return true;
|
---|
| 123 | }
|
---|
[4] | 124 | }
|
---|
| 125 |
|
---|
[290] | 126 | if( varType.GetBasicType() != calcType.GetBasicType() )
|
---|
| 127 | {
|
---|
| 128 | DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
|
---|
[45] | 129 | return true;
|
---|
[4] | 130 | }
|
---|
| 131 |
|
---|
[290] | 132 | if( varType.IsObjectPtr() )
|
---|
| 133 | {
|
---|
[4] | 134 | //双方がオブジェクトポインタ型の場合
|
---|
[290] | 135 | if( varType.GetIndex() != calcType.GetIndex() )
|
---|
| 136 | {
|
---|
| 137 | const CClass *pobj_tempClass = &calcType.GetClass();
|
---|
[4] | 138 | while(pobj_tempClass&&(!IS_LITERAL((LONG_PTR)pobj_tempClass))){
|
---|
[204] | 139 | pobj_tempClass=&pobj_tempClass->GetSuperClass();
|
---|
[4] | 140 |
|
---|
[290] | 141 | if( &varType.GetClass() == pobj_tempClass )
|
---|
| 142 | {
|
---|
[4] | 143 | //継承先が等しいとき
|
---|
[45] | 144 | return true;
|
---|
[4] | 145 | }
|
---|
| 146 | }
|
---|
[290] | 147 | DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
|
---|
[45] | 148 | return true;
|
---|
[4] | 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[290] | 153 | if( varType.IsDouble() )
|
---|
| 154 | {
|
---|
| 155 | if( calcType.Is64() )
|
---|
| 156 | {
|
---|
[4] | 157 | //64ビット整数値の場合は警告を出す
|
---|
[290] | 158 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 159 | }
|
---|
| 160 | }
|
---|
[290] | 161 | else if( varType.IsSingle() )
|
---|
| 162 | {
|
---|
| 163 | if( calcType.Is64() || calcType.IsDouble() )
|
---|
| 164 | {
|
---|
[4] | 165 | //64ビット整数値、またはDouble型の場合は警告を出す
|
---|
[290] | 166 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 167 | }
|
---|
| 168 | }
|
---|
[290] | 169 | else if( varType.GetSize() == sizeof(char) )
|
---|
| 170 | {
|
---|
| 171 | if( calcType.GetSize() > sizeof(char)
|
---|
| 172 | && calcType.GetIndex() != LITERAL_NULL
|
---|
| 173 | && calcType.GetIndex() != LITERAL_M128_0
|
---|
| 174 | && calcType.GetIndex() != LITERAL_0_255 )
|
---|
| 175 | {
|
---|
[4] | 176 | //8ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
|
---|
[290] | 177 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 178 | }
|
---|
| 179 | }
|
---|
[290] | 180 | else if( varType.GetSize() == sizeof(short) )
|
---|
| 181 | {
|
---|
| 182 | if( calcType.GetSize() > sizeof(short)
|
---|
| 183 | && calcType.GetIndex() != LITERAL_NULL
|
---|
| 184 | && calcType.GetIndex() != LITERAL_M128_0
|
---|
| 185 | && calcType.GetIndex() != LITERAL_0_255
|
---|
| 186 | && calcType.GetIndex() != LITERAL_M32768_0
|
---|
| 187 | && calcType.GetIndex() != LITERAL_0_65535 )
|
---|
| 188 | {
|
---|
[4] | 189 | //16ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
|
---|
[290] | 190 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 191 | }
|
---|
| 192 | }
|
---|
[290] | 193 | else if( varType.GetSize() == sizeof(long) )
|
---|
| 194 | {
|
---|
| 195 | if( calcType.IsReal()
|
---|
| 196 | || ( calcType.IsWhole() && calcType.GetSize() > sizeof(long) && calcType.GetIndex() != LITERAL_NULL ) )
|
---|
| 197 | {
|
---|
[4] | 198 | /* 32ビット整数値より大きな型、または実数、
|
---|
| 199 | またはリテラル値でもない場合は警告を出す */
|
---|
[290] | 200 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 201 | }
|
---|
| 202 | }
|
---|
[290] | 203 | else if( varType.GetSize() == sizeof(_int64) )
|
---|
| 204 | {
|
---|
| 205 | if( calcType.IsReal() )
|
---|
| 206 | {
|
---|
[4] | 207 | //実数の場合は警告を出す
|
---|
[290] | 208 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 209 | }
|
---|
| 210 | }
|
---|
[45] | 211 |
|
---|
| 212 | return true;
|
---|
[4] | 213 | }
|
---|