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

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

・コンパイルビューへの出力を標準出力にも行うようにした。
#164への対応。コンパイルを中断すると高確率で強制終了してしまうバグを修正。
・ProjectEditorをVista用Microsoft SDKにてビルドできるようにした(WINVER定数を0x0501に指定した)。
#168への対応。エディタ上のDelegateキーワードを青色で表示するようにした。

File size: 26.0 KB
Line 
1#include "stdafx.h"
2
3#include <iostream>
4
5#include <Program.h>
6#include <Compiler.h>
7
8#include "../BasicCompiler_Common/common.h"
9
10BOOL GetErrorMsg(int num,const char *KeyWord,char *msg,int pos){
11 extern HANDLE hHeap;
12 int i2;
13 char temporary[64];
14
15 char tempKeyWord[1024];
16 if(KeyWord){
17 lstrcpy(tempKeyWord,KeyWord);
18 for(i2=0;;i2++){
19 if(tempKeyWord[i2]=='\0') break;
20 if(tempKeyWord[i2]==1){
21 GetDefaultNameFromES(tempKeyWord[i2+1],temporary);
22 SlideString(tempKeyWord+i2+2,lstrlen(temporary)-2);
23 memcpy(tempKeyWord+i2,temporary,lstrlen(temporary));
24 }
25 }
26 }
27 else{
28 lstrcpy(tempKeyWord,"");
29 }
30
31 if(num==-1||num==-2) lstrcpy(msg,tempKeyWord); //部分エラー
32
33 if(num==3){
34 temporary[0]=tempKeyWord[0];
35 for(i2=1;;i2++){
36 if((!IsVariableChar(tempKeyWord[i2]))||i2>=255){
37 temporary[i2]=0;
38 break;
39 }
40 temporary[i2]=tempKeyWord[i2];
41 }
42
43 extern char **SynonymErrorWords;
44 extern int SynonymErrorNum;
45 for(i2=0;i2<SynonymErrorNum;i2++){
46 if(lstrcmp(SynonymErrorWords[i2],temporary)==0) return 0;
47 }
48
49#if defined(JPN)
50 //日本語
51 sprintf(msg,"\"%s\" 無効な識別子です",temporary);
52#else
53 //英語
54 sprintf(msg,"\"%s\" Invalid identifier.",temporary);
55#endif
56
57 //重複エラー情報を追加
58 SynonymErrorWords=(char **)HeapReAlloc(hHeap,0,SynonymErrorWords,(SynonymErrorNum+1)*sizeof(char *));
59 SynonymErrorWords[SynonymErrorNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
60 lstrcpy(SynonymErrorWords[SynonymErrorNum],temporary);
61 SynonymErrorNum++;
62 }
63 if(num==30){
64#if defined(JPN)
65 //日本語
66 if(temporary[0]) sprintf(msg,"\"%s\" の使い方が不正です",tempKeyWord);
67 else lstrcpy(msg,"文法が間違っています");
68#else
69 //英語
70 if(temporary[0]) sprintf(msg,"How to use the \"%s\" is wrong.",tempKeyWord);
71 else lstrcpy(msg,"Syntax Error.");
72#endif
73 }
74
75
76 /////////////////////
77 // ワーニングエラー
78 /////////////////////
79#if defined(JPN)
80 ////////////////////
81 //日本語
82 ////////////////////
83 if(num==-101) sprintf(msg,"[警告] %sに強制変換されています。データが失われる可能性があります。",tempKeyWord);
84 if(num==-102) sprintf(msg,"[警告] %sに強制変換されています。",tempKeyWord);
85 if(num==-103) sprintf(msg,"[警告] \"%s\" 型が指定されていません。Double型として扱います。",tempKeyWord);
86 if(num==-104) sprintf(msg,"[警告] \"%s\" 戻り値の型が指定されていません。Double型として扱います。",tempKeyWord);
87 if(num==-105) sprintf(msg,"[警告] 一時オブジェクトの解放を行えません。キャスト用オブジェクトを用意してください。",tempKeyWord);
88 if(num==-106) sprintf(msg,"[警告] DLLファイル \"%s\" が見つかりません。",tempKeyWord);
89 if(num==-107) sprintf(msg,"[警告] DLL関数 \"%s\" を参照できません。",tempKeyWord);
90 if(num==-108) lstrcpy(msg,"[警告] Catch節、Finally節を持たない意味のないTryスコープです。");
91 if(num==-120) sprintf(msg,"[警告] VarPtr関数の引数にオブジェクト インスタンスが指定されました。オブジェクトの先頭アドレスを取得したいときはObjPtr関数に切り替えをお願いします。m(__)m(この警告はVarPtr→ObjPtrへの切り替えが完了したら消します(切り替えは \"適材箇所に限り\" ですので、ご注意ください!))",tempKeyWord);
92#else
93#endif
94
95
96 ///////////////
97 // 一般エラー
98 ///////////////
99
100#if defined(JPN)
101 ////////////////////
102 //日本語
103 ////////////////////
104 if(num==1) lstrcpy(msg,"文法が間違っています。");
105 if(num==2) sprintf(msg,"左のオペランドが、左辺値になっていません。");
106 //num==3は予約されています
107 if(num==4) sprintf(msg,"%sの相互関係が一致しません。",tempKeyWord);
108 if(num==5) sprintf(msg,"ダブルクォートの数が一致しません。");
109 if(num==6) sprintf(msg,"\"%s\" ジャンプ先が不正です。",tempKeyWord);
110 if(num==7) lstrcpy(msg,"DLL名が長すぎます(拡張子を含め、16文字以下にして下さい)。");
111 if(num==8) lstrcpy(msg,"コンパイラが認識できない文字コードが含まれています。");
112 if(num==9) sprintf(msg,"型が違います。");
113 if(num==10) sprintf(msg,"\"%s\" のパラメータ指定が間違っています。",tempKeyWord);
114 if(num==11) sprintf(msg,"\"%s\" 型が違います。",tempKeyWord);
115 if(num==12) sprintf(msg,"%s の使い方が不正です。",tempKeyWord);
116 if(num==13) sprintf(msg,"\"%s\" を参照できません。",tempKeyWord);
117 if(num==14) sprintf(msg,"\"%s\" 配列指定が不正です。",tempKeyWord);
118 if(num==15) sprintf(msg,"\"%s\" はすでに定義されています。",tempKeyWord);
119 if(num==16) sprintf(msg,"\"%s\" 配列、またはポインタ以外の変数に添え字が指定されています。",tempKeyWord);
120 if(num==17) sprintf(msg,"リソース データが不正です。");
121 if(num==18) sprintf(msg,"\"%s\"はポインタ変数型です。文字列演算を指定することはできません。",tempKeyWord);
122 if(num==19) sprintf(msg,"\"%s\"は値参照型です。ByVal指定することはできません。",tempKeyWord);
123 if(num==20) lstrcpy(msg,"全角スペースが含まれています(全角スペースはコンパイラが認識できないので、半角スペースまたはタブ文字にしてください)。");
124 if(num==21) sprintf(msg,"If制御のブロック指定が不正です。");
125 if(num==22) sprintf(msg,"%s に対する End %s が見つかりません。",tempKeyWord,tempKeyWord);
126 if(num==23) sprintf(msg,"リソース ファイル \"%s\" の読み込みに失敗。",tempKeyWord);
127 if(num==24) lstrcpy(msg,"Export指定の関数のパラメータには実体オブジェクトを利用することはできません(BytePtr型などを利用して下さい)。");
128 if(num==25) sprintf(msg,"DLL関数にオブジェクトを引き渡すことはできません(%s)。",tempKeyWord);
129 if(num==26) sprintf(msg,"\"%s\" 戻り値の型が指定されていません。",tempKeyWord);
130 if(num==27) sprintf(msg,"\"%s\" は定義されていません。",tempKeyWord);
131 if(num==28) sprintf(msg,"構造体パラメータは参照渡しにしてください(%s)。",tempKeyWord);
132 if(num==29) sprintf(msg,"配列ポインタを要素と同時に引渡すときは、ポインタ参照(ByRef)にしてください。");
133 //num==30は予約されています
134 if(num==31) sprintf(msg,"\"%s\" は構造体です(メンバの参照はピリオド \".\" で区切ってください)。",tempKeyWord);
135 if(num==32) sprintf(msg,"\"%s\" は構造体ポインタです(メンバの参照は \"->\" で区切ってください)。",tempKeyWord);
136 if(num==33) sprintf(msg,"定数式にリテラル値、または定数以外のものが含まれています。");
137 if(num==34) sprintf(msg,"定数はモジュールレベルで宣言して下さい。");
138 if(num==38) sprintf(msg,"\"%s\" 戻り値が存在しないプロシージャです。",tempKeyWord);
139 if(num==39) sprintf(msg,"\"%s\" はオブジェクトポインタではありません(\"->\" 参照はできません)。",tempKeyWord);
140 if(num==40) lstrcpy(msg,"DLL関数の戻り値としてオブジェクトを受け取ることはできません。");
141 if(num==41) lstrcpy(msg,"初期データが不正です。");
142 if(num==42) lstrcpy(msg,"閉じカッコ \")\" の後に不正な文字が含まれています。");
143 if(num==43) lstrcpy(msg,"ダブルクォートの後に不正な文字が含まれています。");
144 if(num==45) sprintf(msg,"実数に対して \"%s\" 演算子は利用できません。",tempKeyWord);
145 if(num==46) lstrcpy(msg,"配列の添え字に整数以外の値が与えられています。");
146 if(num==47) lstrcpy(msg,"As演算子の右辺値に型名以外の識別子が指定されています。");
147 if(num==48) sprintf(msg,"%s演算子に対して型名が指定されています。",tempKeyWord);
148 if(num==49) lstrcpy(msg,"添え字に整数以外の型が指定されています。");
149 if(num==50) sprintf(msg,"%sに変換できません。",tempKeyWord);
150 if(num==51) lstrcpy(msg,"オブジェクト、構造体のアラインメント値は 1, 2, 4, 8, 16 のいずれかでなければなりません。");
151 if(num==52) sprintf(msg,"\"%s\" オーバーロードを解決できません。",tempKeyWord);
152 if(num==53) sprintf(msg,"\"%s\" 出力ファイルの書き込みに失敗しました。実行されている可能性があります。",tempKeyWord);
153 if(num==54) sprintf(msg,"対応する%sが存在しません。",tempKeyWord);
154 if(num==55) sprintf(msg,"\"%s\" は対応するForステートメントで利用されるカウンタ変数ではありません。",tempKeyWord);
155 if(num==56) lstrcpy(msg,"ゼロ割りが行われました。");
156 if(num==57) lstrcpy(msg,"8進数のリテラル表記が不正です。");
157 if(num==58) lstrcpy(msg,"16進数のリテラル表記が不正です。");
158 if(num==59) sprintf(msg,"マニフェスト ファイル \"%s\" の読み込みに失敗。",tempKeyWord);
159 if(num==60) lstrcpy(msg,"Staticステートメントはグローバル領域では使用できません。");
160 if(num==61) sprintf(msg,"\"%s\" は定数です。書き込みアクセスはできません。",tempKeyWord);
161 if(num==62) sprintf(msg,"グローバル領域でのReturnは禁止されています。",tempKeyWord);
162 if(num==63) lstrcpy(msg,"名前空間が正しく閉じられていません。");
163 if(num==64) sprintf(msg,"\"%s\" 無効な名前空間です。",tempKeyWord);
164 if(num==65) sprintf(msg,"ローカル領域で%sは使用できません。",tempKeyWord);
165 if(num==66) sprintf(msg,"%s 要求されている関数ポインタのパラメータまたは戻り値が一致しません。", tempKeyWord );
166 if(num==67) sprintf(msg,"%s 要求されているデリゲートのパラメータまたは戻り値が一致しません。", tempKeyWord );
167 if(num==68) sprintf(msg,"\"%s\" 不正な関数名です。", tempKeyWord);
168 if(num==69) sprintf(msg,"\"%s\" 不正なメソッド名です。", tempKeyWord);
169 if(num==70) lstrcpy(msg,"一つのTryに対して複数のFinallyを記述できません。");
170 if(num==71) lstrcpy(msg,"Finallyの後ろにCatchを記述することはできません。");
171 if(num==72) lstrcpy(msg,"Catchのパラメータの型が指定されていません。");
172 if(num==73) lstrcpy(msg,"\"%s\" Catchのパラメータの型はクラス型でなければなりません。");
173 if(num==74) sprintf(msg,"\"%s\" 型として認識できません。",tempKeyWord);
174
175
176 //オブジェクト関連
177 if(num==102) sprintf(msg,"\"%s\" オブジェクトは定義されていません。",tempKeyWord);
178 if(num==103) sprintf(msg,"\"%s\" メンバは定義されていません。",tempKeyWord);
179 if(num==104) sprintf(msg,"\"%s\" 参照方法が違います。",tempKeyWord);
180 if(num==105) sprintf(msg,"\"%s\" 自身のクラスを継承することはできません。",tempKeyWord);
181 if(num==106) sprintf(msg,"\"%s\" 存在しないクラスです。",tempKeyWord);
182 if(num==107) sprintf(msg,"Privateメンバ \"%s\" にアクセスすることはできません。",tempKeyWord);
183 if(num==108) sprintf(msg,"Protectedメンバ \"%s\" にアクセスすることはできません。",tempKeyWord);
184 if(num==109) sprintf(msg,"Privateメンバ関数 \"%s\" を呼び出すことはできません。",tempKeyWord);
185 if(num==110) sprintf(msg,"Protectedメンバ関数 \"%s\" を呼び出すことはできません。",tempKeyWord);
186 if(num==111) lstrcpy(msg,"InheritsはClass定義内の先頭に記述する必要があります。");
187 if(num==112) sprintf(msg,"\"%s\" はクラス型ではないため、初期パラメータを指定することはできません。",tempKeyWord);
188 if(num==113) sprintf(msg,"\"%s\" コンストラクタへ渡すパラメータが不正です。",tempKeyWord);
189 if(num==114) lstrcpy(msg,"デストラクタはパラメータを持てません。");
190 if(num==115) lstrcpy(msg,"コンストラクタ及びデストラクタは戻り値を持てません。");
191 //if(num==116) lstrcpy(msg,"コンストラクタ及びデストラクタはパブリックアクセスにしなければなりません。");
192 if(num==117) lstrcpy(msg,"デストラクタの名前が \"~クラス名\" になっていません。");
193 if(num==118) lstrcpy(msg,"参照する基底クラスが存在しません。");
194 if(num==119) sprintf(msg,"\"%s\" メンバは基底クラスで定義されていません。",tempKeyWord);
195 if(num==120) lstrcpy(msg,"デストラクトするオブジェクトの型が不明です。");
196 if(num==121) lstrcpy(msg,"New演算子にはクラス以外の型を指定できません。");
197 if(num==122) lstrcpy(msg,"Delete演算子にポインタ以外の型が指定されています。");
198 if(num==123) lstrcpy(msg,"ループ継承が行われました。");
199 if(num==124) lstrcpy(msg,"循環参照が行われました。");
200 if(num==125) sprintf(msg,"\"%s\" は抽象クラスです。インスタンス化することはできません。",tempKeyWord);
201 if(num==126) lstrcpy(msg,"オペレータのオーバーロードをクラスの外で行うことはできません。");
202 if(num==127) lstrcpy(msg,"Override修飾子の指定が無い状況でオーバーライドを行うことはできません。");
203 if(num==128) lstrcpy(msg,"オーバーライドを行うときはアクセシビリティを同一にしなければなりません。");
204 if(num==129) sprintf(msg,"静的メンバ \"%s\" は定義されていません。",tempKeyWord);
205 if(num==130) sprintf(msg,"\"%s\" はオブジェクト定数です。書き込みアクセスはできません。",tempKeyWord);
206 if(num==131) lstrcpy(msg,"Const定義されたメソッド内でクラスメンバへの書き込みアクセスはできません。");
207 if(num==132) lstrcpy(msg,"明示的なコンストラクタ呼び出しと初期値の指定を同時に行うことはできません。");
208 if(num==133) lstrcpy(msg,"Thisに代入はできません。");
209 if(num==134) lstrcpy( msg,"ObjPtr関数にはオブジェクト インスタンス以外を指定できません。" );
210 if(num==135) lstrcpy( msg, "クラス以外の型を継承元として指定することはできません。" );
211 if(num==136) sprintf( msg, "\"%s\" 非仮想関数に対してオーバーライドしようとしました。", tempKeyWord );
212 if(num==137) lstrcpy(msg,"ImplementsはClass定義内の先頭に記述する必要があります。");
213 if(num==138) sprintf(msg,"%s はインターフェイスではありません。Implementsできるのはインターフェイスに限ります。",tempKeyWord);
214 if(num==139) sprintf(msg,"%s はインターフェイスではありません。",tempKeyWord);
215 if(num==140) lstrcpy(msg,"Align修飾子を構造体以外の型に指定することはできません。");
216 if(num==141) lstrcpy(msg,"Blittable修飾子をクラス以外の型に指定することはできません。");
217 if(num==142) lstrcpy(msg,"不正なThis参照です。");
218
219 //Enum関連
220 if(num==150) sprintf(msg,"\"%s\" 値が定義されていません。",tempKeyWord);
221 if(num==151) sprintf(msg,"\"%s\" 列挙リストに登録されていません。",tempKeyWord);
222
223 //リンカ
224 if(num==200) sprintf(msg,"\"%s\" 未解決です (リンク エラー)。",tempKeyWord);
225 if(num==201) sprintf(msg,"\"%s\" の読み込みに失敗。",tempKeyWord);
226
227 //原因不明
228 if(num==300) lstrcpy(msg,"内部エラー");
229
230 // ベースライブラリ不整合
231 if( num == 400 ) sprintf( msg, "\"%s\" が存在しません。標準ライブラリの内容が古い可能性があります。", tempKeyWord );
232
233#else
234 ////////////////////
235 //英語
236 ////////////////////
237 if(num==1) lstrcpy(msg,"Syntax Error.");
238 if(num==2) sprintf(msg,"Left operand must be l-value.");
239 //num==3は予約されています
240 if(num==4) sprintf(msg,"Correlation of %s is wrong.",tempKeyWord);
241 if(num==5) sprintf(msg,"Correlation of double quotes is wrong.");
242 if(num==6) sprintf(msg,"\"%s\" Label not found.",tempKeyWord);
243 if(num==7) lstrcpy(msg,"The DLL name is too long. Must be 16 characters or less.");
244 if(num==8) lstrcpy(msg,"The inaccurate characters are contained.");
245 if(num==9) sprintf(msg,"Type is wrong.");
246 if(num==10) sprintf(msg,"\"%s\" Rule of parameter is wrong.",tempKeyWord);
247 if(num==11) sprintf(msg,"\"%s\" Type is wrong.",tempKeyWord);
248 if(num==12) sprintf(msg,"\"%s\" Not a valid use.",tempKeyWord);
249 if(num==13) sprintf(msg,"Cannot refer to \"%s\".",tempKeyWord);
250 if(num==14) sprintf(msg,"\"%s\" Array argument(s) out of bound.",tempKeyWord);
251 if(num==15) sprintf(msg,"\"%s\" is already defined.",tempKeyWord);
252 if(num==16) sprintf(msg,"\"%s\" Argument(s) following variable which is not pointer or array.",tempKeyWord);
253 if(num==17) sprintf(msg,"Invalid resource data.");
254 if(num==18) sprintf(msg,"\"%s\" Invalid operation on a pointer variable.",tempKeyWord);
255 if(num==19) sprintf(msg,"\"%s\" is already to be passed by value. You cannot use \"ByVal\".",tempKeyWord);
256 if(num==21) sprintf(msg,"Wrong structure of \"If\" block.");
257 if(num==22) sprintf(msg,"No matching \"End %s\" found for \"%s\".",tempKeyWord,tempKeyWord);
258 if(num==23) sprintf(msg,"Cannot read the resource file \"%s\".",tempKeyWord);
259 if(num==24) lstrcpy(msg,"Must not use String type as an argument for exported function. (Use BytePtr type instead.)");
260 if(num==27) sprintf(msg,"\"%s\" Undefined procedure.",tempKeyWord);
261 if(num==28) sprintf(msg,"\"%s\" Structure must not be passed by value. (Use \"ByRef\".)",tempKeyWord);
262 if(num==29) sprintf(msg,"Array must not be passed by value. (Use \"ByRef\".)");
263 //num==30は予約されています
264 if(num==31) sprintf(msg,"\"%s\" is a struct. (Use period \".\" to refer to the members.)",tempKeyWord);
265 if(num==32) sprintf(msg,"\"%s\" is a pointer of struct. (Use arrow \"->\" to refer to the members.)",tempKeyWord);
266 if(num==33) sprintf(msg,"Constant formula has a thing that is not literal value or constant value.");
267 if(num==34) sprintf(msg,"Constant formula must be defined in the module level.");
268 if(num==38) sprintf(msg,"\"%s\" is a procedure without a return value.",tempKeyWord);
269 if(num==39) sprintf(msg,"\"%s\" is not object pointer. \"->\" is invalid.",tempKeyWord);
270 if(num==40) lstrcpy(msg,"Cannot set a object to return value.");
271 if(num==41) lstrcpy(msg,"Init data is wrong.");
272 if(num==42) lstrcpy(msg,"The inaccurate characters are contained after the closing parenthesis \")\".");
273 if(num==43) lstrcpy(msg,"The inaccurate characters are contained after the double quote.");
274
275 //オブジェクト関連
276 if(num==102) sprintf(msg,"\"%s\" The object is not defined.",tempKeyWord);
277 if(num==103) sprintf(msg,"\"%s\" The member is not defined.",tempKeyWord);
278 if(num==104) sprintf(msg,"\"%s\" The reference character is different.",tempKeyWord);
279 if(num==105) sprintf(msg,"\"%s\" An own class is not inheritable.",tempKeyWord);
280 if(num==106) sprintf(msg,"\"%s\" It class is not defined.",tempKeyWord);
281 if(num==107) sprintf(msg,"\"%s\" Cannot access the private member.",tempKeyWord);
282 if(num==108) sprintf(msg,"\"%s\" Cannot access the protected member.",tempKeyWord);
283 if(num==109) sprintf(msg,"\"%s\" Cannot call the private member.",tempKeyWord);
284 if(num==110) sprintf(msg,"\"%s\" Cannot call the protected member.",tempKeyWord);
285 if(num==111) lstrcpy(msg,"The Inherits phrase must be described to the 1st line of class module");
286 if(num==112) sprintf(msg,"\"%s\" is not class object. Therefor you cannot set the parameter for constructor.",tempKeyWord);
287 if(num==113) sprintf(msg,"\"%s\" The parameter for constructor is wrong.",tempKeyWord);
288 if(num==114) lstrcpy(msg,"Destructor cannot have a parameter.");
289 if(num==115) lstrcpy(msg,"Constructor and Destructor cannot have a return value.");
290 if(num==116) lstrcpy(msg,"Constructor and Destructor must be public access.");
291 if(num==117) lstrcpy(msg,"Destructors name must be \"~ClassName\".");
292 if(num==118) lstrcpy(msg,"Super class is not found.");
293 if(num==119) sprintf(msg,"\"%s\" The member is not defined in the super class.",tempKeyWord);
294
295 //Enum関連
296 if(num==150) sprintf(msg,"\"%s\" The value is not set",tempKeyWord);
297 if(num==151) sprintf(msg,"\"%s\" is not found from enum lists.",tempKeyWord);
298
299 //リンカ
300 if(num==200) sprintf(msg,"\"%s\" Unknown error.",tempKeyWord);
301#endif
302
303 return 1;
304}
305void SetError(int ErrorNum,const string &keyWord,int pos){
306 SetError( ErrorNum, keyWord.c_str(), pos );
307}
308void SetError(int num,const char *KeyWord,int pos){
309 extern HANDLE hHeap;
310 extern HWND hMainDlg;
311 extern ERRORINFO *pErrorInfo;
312 extern int ErrorNum;
313 char temporary[1024],temp2[1024],temp3[32];
314 BOOL bFirst;
315 int i2;
316
317 extern BOOL bDebugRun;
318 if(bDebugRun) return;
319
320 if(num!=-2){
321 //一般エラーまたは警告
322 i2=0; //ここにブレークポイントをおく
323
324 if(num>-100){
325 //エラーのみ
326
327 i2=0;
328
329 if( num == 300 )
330 {
331 // 内部エラー
332 i2=0;
333 }
334 }
335
336 }
337
338 if(!GetErrorMsg(num,KeyWord,temporary,pos)) return;
339
340 if(ErrorNum==0){
341 SetDlgItemText(hMainDlg,IDC_ERRORLIST,"");
342 EnableWindow(GetDlgItem(hMainDlg,IDC_ERRORLIST),1);
343 bFirst=1;
344 }
345 else bFirst=0;
346
347
348 ////////////////////
349 // エラー情報を追加
350 pErrorInfo=(ERRORINFO *)HeapReAlloc(hHeap,0,pErrorInfo,(ErrorNum+1)*sizeof(ERRORINFO));
351
352 if(pos==-1){
353 pErrorInfo[ErrorNum].FileName=0;
354 lstrcpy(temp2,temporary);
355 }
356 else{
357 std::string dummyStr;
358 compiler.GetObjectModule().GetCurrentSource().GetLineInfo( pos, pErrorInfo[ErrorNum].line, dummyStr );
359
360 pErrorInfo[ErrorNum].FileName=(char *)HeapAlloc(hHeap,0,lstrlen(dummyStr.c_str())+1);
361 lstrcpy(pErrorInfo[ErrorNum].FileName,dummyStr.c_str());
362
363 _splitpath(pErrorInfo[ErrorNum].FileName,0,0,temp2,temp3);
364 lstrcat(temp2,temp3);
365
366 if(pErrorInfo[ErrorNum].line==-1)
367 sprintf(temp2+lstrlen(temp2),"(no area) %s",temporary);
368 else
369 sprintf(temp2+lstrlen(temp2),"(%d) - %s",pErrorInfo[ErrorNum].line+1,temporary);
370 }
371
372 i2=GetWindowTextLength(GetDlgItem(hMainDlg,IDC_ERRORLIST));
373 SendDlgItemMessage(hMainDlg,IDC_ERRORLIST,EM_SETSEL,i2,i2);
374 if(bFirst==0){
375 SendDlgItemMessage(hMainDlg,IDC_ERRORLIST,EM_REPLACESEL,0,(LPARAM)"\r\n");
376 i2+=2;
377 SendDlgItemMessage(hMainDlg,IDC_ERRORLIST,EM_SETSEL,i2,i2);
378 }
379 SendDlgItemMessage(hMainDlg,IDC_ERRORLIST,EM_REPLACESEL,0,(LPARAM)temp2);
380
381 std::string msg = temp2;
382 if(num==-2){
383 //コンパイルメッセージ
384 //※何もしない
385 extern int CompileMsgNum;
386 CompileMsgNum++;
387 }
388 else{
389 msg = (num>-100) ? "error - " : "warning - ";
390 msg += temp2;
391 if(num>-100){
392 //警告ではなく、エラーの場合はエラーチェックフラグを立てる
393 extern BOOL bError;
394 bError=1;
395 }
396 else{
397 extern int WarningNum;
398 WarningNum++;
399 }
400
401 // ログに出力
402 trace( msg );
403 }
404
405 std::cout << msg << endl;
406
407
408 ErrorNum++;
409}
410void SetError(){
411 SetError(300,NULL,cp);
412}
413void CompileMessage(const char *buffer){
414 SetError(-2,buffer,-1);
415}
416
417#define STRING_SYSTEM_DECLAREHANDLE "*_System_DeclareHandle_"
418void DifferentTypeError( const Type &varType, const Type &calcFormalType, const int iWarning,const char *pszFuncName,const int ParmNum){
419 //////////////////////////
420 // キャストに関する警告
421 //////////////////////////
422 char temporary[255];
423 Type calcType( calcFormalType );
424
425 if(IS_LITERAL(calcType.GetIndex()))
426 {
427 calcType.SetIndex( -1 );
428 }
429
430 if(pszFuncName)
431 sprintf(temporary,"\"%s\"の第%dパラメータが、",pszFuncName,ParmNum+1);
432 else temporary[0]=0;
433
434 std::string varTypeName = compiler.TypeToString( varType );
435 if(memcmp( varTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0)
436 {
437 varTypeName = varTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) );
438 }
439
440 std::string calcTypeName = compiler.TypeToString( calcType );
441 if(memcmp( calcTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0)
442 {
443 calcTypeName = calcTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) );
444 }
445 sprintf(temporary+lstrlen(temporary),"%sから%s",calcTypeName.c_str(),varTypeName.c_str());
446
447 extern int cp;
448 if(iWarning==1) SetError(-101,temporary,cp);
449 else if(iWarning==2) SetError(-102,temporary,cp);
450 else if(iWarning==3) SetError(50,temporary,cp);
451}
452
453bool CheckDifferentType( const Type &varType,const Type &calcFormalType,const char *pszFuncName,const int ParmNum)
454{
455 Type calcType( calcFormalType );
456
457 if( varType.IsStruct() || calcType.IsStruct() )
458 {
459 //いずれかが構造体場合
460 if( !varType.Equals( calcType ) )
461 {
462 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
463 return false;
464 }
465 }
466
467 if( varType.IsObject() || calcType.IsObject() )
468 {
469 //いずれかがオブジェクトではない場合
470 if( (!varType.IsObject()) || (!calcType.IsObject()) )
471 {
472 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
473 return false;
474 }
475
476 if( varType.IsDelegate() && calcType.IsDelegate() )
477 {
478 // デリゲート同士の比較の場合
479 // ※共変戻り値及び反辺引数をサポートすること
480 if( !varType.GetClass().GetDelegate().IsSimilar( calcType.GetClass().GetDelegate() ) )
481 {
482 // 等しいと見なされないとき
483 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
484 return false;
485 }
486 }
487 else
488 {
489 // 一般的なクラスの比較の場合
490
491 if( !varType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) )
492 {
493 //等しくなく、派生クラスでもないとき
494 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum);
495 return false;
496 }
497 }
498 }
499
500 //#strictが指定されていないときは型チェックを行わないようにする
501 extern BOOL bStrict;
502 if(bStrict==0) return true;
503
504 if( calcType.GetBasicType() & FLAG_PTR )
505 {
506 //配列先頭フラグがたっている場合は、ポインタ型として扱う
507 calcType.SetBasicType( MAKE_PTR_TYPE(NATURAL_TYPE(calcType.GetBasicType()),PTR_LEVEL(calcType.GetBasicType())+1) );
508 }
509
510 if( varType.IsPointer() || calcType.IsPointer() )
511 {
512 /* 右辺及び左辺のいずれかがポインタ型の場合は、
513 型チェックを行う。
514 ・同一の種類のポインタ型以外はエラーとする */
515
516 if( varType.IsPointer() && calcType.GetIndex() == LITERAL_NULL )
517 {
518 //リテラルNULL値の場合
519 return true;
520 }
521
522 if( varType.IsVoidPtr() )
523 {
524 //左辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
525 if( calcType.IsPointer() )
526 {
527 return true;
528 }
529 }
530
531 if( calcType.IsVoidPtr() )
532 {
533 //右辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる
534 if( varType.IsPointer() )
535 {
536 return true;
537 }
538 }
539
540 if( varType.GetBasicType() != calcType.GetBasicType() )
541 {
542 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
543 return true;
544 }
545
546 if( varType.IsObjectPtr() )
547 {
548 //双方がオブジェクトポインタ型の場合
549 if( varType.GetIndex() != calcType.GetIndex() )
550 {
551 const CClass *pobj_tempClass = &calcType.GetClass();
552 while(pobj_tempClass&&(!IS_LITERAL((LONG_PTR)pobj_tempClass))){
553 pobj_tempClass=&pobj_tempClass->GetSuperClass();
554
555 if( &varType.GetClass() == pobj_tempClass )
556 {
557 //継承先が等しいとき
558 return true;
559 }
560 }
561 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum);
562 return true;
563 }
564 }
565 }
566
567 if( varType.IsDouble() )
568 {
569 if( calcType.Is64() )
570 {
571 //64ビット整数値の場合は警告を出す
572 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
573 }
574 }
575 else if( varType.IsSingle() )
576 {
577 if( calcType.Is64() || calcType.IsDouble() )
578 {
579 //64ビット整数値、またはDouble型の場合は警告を出す
580 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
581 }
582 }
583 else if( varType.GetSize() == sizeof(char) )
584 {
585 if( calcType.GetSize() > sizeof(char)
586 && calcType.GetIndex() != LITERAL_NULL
587 && calcType.GetIndex() != LITERAL_M128_0
588 && calcType.GetIndex() != LITERAL_0_255 )
589 {
590 //8ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
591 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
592 }
593 }
594 else if( varType.GetSize() == sizeof(short) )
595 {
596 if( calcType.GetSize() > sizeof(short)
597 && calcType.GetIndex() != LITERAL_NULL
598 && calcType.GetIndex() != LITERAL_M128_0
599 && calcType.GetIndex() != LITERAL_0_255
600 && calcType.GetIndex() != LITERAL_M32768_0
601 && calcType.GetIndex() != LITERAL_0_65535 )
602 {
603 //16ビット整数値より大きな型で、リテラル値でもない場合は警告を出す
604 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
605 }
606 }
607 else if( varType.GetSize() == sizeof(long) )
608 {
609 if( calcType.IsReal()
610 || ( calcType.IsWhole() && calcType.GetSize() > sizeof(long) && calcType.GetIndex() != LITERAL_NULL ) )
611 {
612 /* 32ビット整数値より大きな型、または実数、
613 またはリテラル値でもない場合は警告を出す */
614 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
615 }
616 }
617 else if( varType.GetSize() == sizeof(_int64) )
618 {
619 if( calcType.IsReal() )
620 {
621 //実数の場合は警告を出す
622 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum);
623 }
624 }
625
626 return true;
627}
Note: See TracBrowser for help on using the repository browser.