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