source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/error.cpp@ 673

Last change on this file since 673 was 562, checked in by dai_9181, 16 years ago

CClass::GetDelegateメソッドを廃止し、代わりにMeta::ToDelegateメソッドを実装。

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