[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 | // ※共変戻り値及び反辺引数をサポートすること
|
---|
| 68 | if( !varType.GetClass().GetDelegate().IsSimilar( calcType.GetClass().GetDelegate() ) )
|
---|
| 69 | {
|
---|
| 70 | // 等しいと見なされないとき
|
---|
| 71 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
[59] | 74 | }
|
---|
[448] | 75 | else
|
---|
| 76 | {
|
---|
| 77 | // 一般的なクラスの比較の場合
|
---|
| 78 |
|
---|
| 79 | if( !varType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) )
|
---|
| 80 | {
|
---|
| 81 | //等しくなく、派生クラスでもないとき
|
---|
| 82 | DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
|
---|
| 83 | return false;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
[4] | 86 | }
|
---|
| 87 |
|
---|
[290] | 88 | if( calcType.GetBasicType() & FLAG_PTR )
|
---|
| 89 | {
|
---|
[4] | 90 | //配列先頭フラグがたっている場合は、ポインタ型として扱う
|
---|
[290] | 91 | calcType.SetBasicType( MAKE_PTR_TYPE(NATURAL_TYPE(calcType.GetBasicType()),PTR_LEVEL(calcType.GetBasicType())+1) );
|
---|
[4] | 92 | }
|
---|
| 93 |
|
---|
[290] | 94 | if( varType.IsPointer() || calcType.IsPointer() )
|
---|
| 95 | {
|
---|
[4] | 96 | /* 右辺及び左辺のいずれかがポインタ型の場合は、
|
---|
| 97 | 型チェックを行う。
|
---|
| 98 | ・同一の種類のポインタ型以外はエラーとする */
|
---|
| 99 |
|
---|
[290] | 100 | if( varType.IsPointer() && calcType.GetIndex() == LITERAL_NULL )
|
---|
| 101 | {
|
---|
[4] | 102 | //リテラルNULL値の場合
|
---|
[45] | 103 | return true;
|
---|
[4] | 104 | }
|
---|
| 105 |
|
---|
[290] | 106 | if( varType.IsVoidPtr() )
|
---|
| 107 | {
|
---|
[4] | 108 | //左辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
|
---|
[290] | 109 | if( calcType.IsPointer() )
|
---|
| 110 | {
|
---|
| 111 | return true;
|
---|
| 112 | }
|
---|
[4] | 113 | }
|
---|
| 114 |
|
---|
[290] | 115 | if( calcType.IsVoidPtr() )
|
---|
| 116 | {
|
---|
[4] | 117 | //右辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
|
---|
[290] | 118 | if( varType.IsPointer() )
|
---|
| 119 | {
|
---|
| 120 | return true;
|
---|
| 121 | }
|
---|
[4] | 122 | }
|
---|
| 123 |
|
---|
[290] | 124 | if( varType.GetBasicType() != calcType.GetBasicType() )
|
---|
| 125 | {
|
---|
| 126 | DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
|
---|
[45] | 127 | return true;
|
---|
[4] | 128 | }
|
---|
| 129 |
|
---|
[290] | 130 | if( varType.IsObjectPtr() )
|
---|
| 131 | {
|
---|
[4] | 132 | //双方がオブジェクトポインタ型の場合
|
---|
[290] | 133 | if( varType.GetIndex() != calcType.GetIndex() )
|
---|
| 134 | {
|
---|
| 135 | const CClass *pobj_tempClass = &calcType.GetClass();
|
---|
[4] | 136 | while(pobj_tempClass&&(!IS_LITERAL((LONG_PTR)pobj_tempClass))){
|
---|
[204] | 137 | pobj_tempClass=&pobj_tempClass->GetSuperClass();
|
---|
[4] | 138 |
|
---|
[290] | 139 | if( &varType.GetClass() == pobj_tempClass )
|
---|
| 140 | {
|
---|
[4] | 141 | //継承先が等しいとき
|
---|
[45] | 142 | return true;
|
---|
[4] | 143 | }
|
---|
| 144 | }
|
---|
[290] | 145 | DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
|
---|
[45] | 146 | return true;
|
---|
[4] | 147 | }
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[290] | 151 | if( varType.IsDouble() )
|
---|
| 152 | {
|
---|
| 153 | if( calcType.Is64() )
|
---|
| 154 | {
|
---|
[4] | 155 | //64ビット整数値の場合は警告を出す
|
---|
[290] | 156 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 157 | }
|
---|
| 158 | }
|
---|
[290] | 159 | else if( varType.IsSingle() )
|
---|
| 160 | {
|
---|
| 161 | if( calcType.Is64() || calcType.IsDouble() )
|
---|
| 162 | {
|
---|
[4] | 163 | //64ビット整数値、またはDouble型の場合は警告を出す
|
---|
[290] | 164 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 165 | }
|
---|
| 166 | }
|
---|
[290] | 167 | else if( varType.GetSize() == sizeof(char) )
|
---|
| 168 | {
|
---|
| 169 | if( calcType.GetSize() > sizeof(char)
|
---|
| 170 | && calcType.GetIndex() != LITERAL_NULL
|
---|
| 171 | && calcType.GetIndex() != LITERAL_M128_0
|
---|
| 172 | && calcType.GetIndex() != LITERAL_0_255 )
|
---|
| 173 | {
|
---|
[4] | 174 | //8ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
|
---|
[290] | 175 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 176 | }
|
---|
| 177 | }
|
---|
[290] | 178 | else if( varType.GetSize() == sizeof(short) )
|
---|
| 179 | {
|
---|
| 180 | if( calcType.GetSize() > sizeof(short)
|
---|
| 181 | && calcType.GetIndex() != LITERAL_NULL
|
---|
| 182 | && calcType.GetIndex() != LITERAL_M128_0
|
---|
| 183 | && calcType.GetIndex() != LITERAL_0_255
|
---|
| 184 | && calcType.GetIndex() != LITERAL_M32768_0
|
---|
| 185 | && calcType.GetIndex() != LITERAL_0_65535 )
|
---|
| 186 | {
|
---|
[4] | 187 | //16ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
|
---|
[290] | 188 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 189 | }
|
---|
| 190 | }
|
---|
[290] | 191 | else if( varType.GetSize() == sizeof(long) )
|
---|
| 192 | {
|
---|
| 193 | if( calcType.IsReal()
|
---|
| 194 | || ( calcType.IsWhole() && calcType.GetSize() > sizeof(long) && calcType.GetIndex() != LITERAL_NULL ) )
|
---|
| 195 | {
|
---|
[4] | 196 | /* 32ビット整数値より大きな型、または実数、
|
---|
| 197 | またはリテラル値でもない場合は警告を出す */
|
---|
[290] | 198 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 199 | }
|
---|
| 200 | }
|
---|
[290] | 201 | else if( varType.GetSize() == sizeof(_int64) )
|
---|
| 202 | {
|
---|
| 203 | if( calcType.IsReal() )
|
---|
| 204 | {
|
---|
[4] | 205 | //実数の場合は警告を出す
|
---|
[290] | 206 | DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
|
---|
[4] | 207 | }
|
---|
| 208 | }
|
---|
[45] | 209 |
|
---|
| 210 | return true;
|
---|
[4] | 211 | }
|
---|