source: dev/BasicCompiler_Common/common.h@ 28

Last change on this file since 28 was 28, checked in by dai_9181, 18 years ago

・【32ビットコンパイラ】戻り値に実態オブジェクトを持つインデクサを呼び出すと強制終了してしまうバグを修正。
・仮想関数のオーバーロードが正常に動作しないバグを修正。
・純仮想関数(抽象メソッド)が仮想関数でオーバーロードされていると、クラスのインスタンスが生成できてしまうバグを修正。

File size: 14.7 KB
Line 
1//#define _CRT_SECURE_NO_DEPRECATE
2#pragma warning(disable : 4996)
3
4#include <windows.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <commctrl.h>
9#include <time.h>
10#include <limits.h>
11#include <shlobj.h>
12#include <vector>
13
14#ifdef _AMD64_
15#include "../BasicCompiler64/resource.h"
16#include "../BasicCompiler64/CommandValue.h"
17#include "../BasicCompiler64/FunctionValue.h"
18#define OPCODE_H_PATH "../BasicCompiler64/opcode.h"
19#else
20#include "../BasicCompiler32/resource.h"
21#include "../BasicCompiler32/CommandValue.h"
22#include "../BasicCompiler32/FunctionValue.h"
23#define OPCODE_H_PATH "../BasicCompiler32/opcode.h"
24#endif
25
26#include "../BasicCompiler_Common/BasicFixed.h"
27#include "../BasicCompiler_Common/NonVolatile.h"
28#include "../BasicCompiler_Common/TypeDef.h"
29#include "../BasicCompiler_Common/psapi.h"
30#include "../BasicCompiler_Common/BreakPoint.h"
31
32
33
34//バージョン
35#define MAJOR_VER 5
36#define MINOR_VER 00
37#define REVISION_VER 00
38
39#ifdef _AMD64_
40#define VER_INFO "β9 (x64)"
41#else
42#define VER_INFO "β9"
43#endif
44
45#if defined(JPN)
46//日本語
47#include "common_msg_jpn.h"
48#else
49//英語
50#include "common_msg_eng.h"
51#endif
52
53
54#pragma comment(lib, "psapi.lib")
55
56
57#define PTR_SIZE sizeof(LONG_PTR)
58
59#define MAX_LEN 65535
60#define VN_SIZE 512
61#define DIGIT_SIZE 128
62#define MAX_PARMS 64
63#define MAX_ARRAYDIM 16
64#define MAX_HASH 32761
65
66
67#ifdef _AMD64_
68#define PLATFORM 64
69#else
70#define PLATFORM 32
71typedef long LONG_PTR;
72typedef DWORD ULONG_PTR;
73#endif
74
75
76//未定義の定数情報
77#define IMAGE_FILE_MACHINE_AMD64 0x8664
78
79
80
81extern HWND hOwnerEditor;
82extern HANDLE hHeap;
83extern char BasicSystemDir[MAX_PATH];
84extern int cp;
85
86
87
88//////////////////////////////////////////
89// BasicCompiler、ProjectEditor共通の定数
90//////////////////////////////////////////
91
92//サイズ変更枠の太さ
93#define LEVER_THICK 5
94
95#define WM_SHOWERROR WM_USER+70 //エラー表示メッセージ
96
97#define WM_SETCOMPILEVIEW WM_USER+71 //コンパイラウィンドウが表示されたとき
98#define WM_DESTROYCOMPILEVIEW WM_USER+72 //コンパイラウィンドウが破棄されたとき
99
100#define WM_SETDEBUGGERBASE WM_USER+73 //デバッガベースウィンドウが表示されたとき
101#define WM_DESTROYDEBUGGERBASE WM_USER+74 //デバッガベースウィンドウが破棄されたとき
102
103#define WM_SETDEBUGGERVIEW WM_USER+75 //デバッガウィンドウが表示されたとき
104#define WM_DESTROYDEBUGGERVIEW WM_USER+76 //デバッガウィンドウが表示されたとき
105
106///////////////////////////////////////////
107
108
109#define WM_SHOWVARLIST WM_USER+80
110#define WM_VARLIST_CLOSE WM_USER+81 //変数リストの終了メッセージ(破棄のみ、解放なし)
111
112
113
114///////////////////////////////////////////
115// デバッグ コマンド
116
117#define WM_DEBUG_CONTINUE WM_USER+200
118#define WM_STEP_IN WM_USER+201
119#define WM_STEP_OVER WM_USER+202
120#define WM_STEP_CURSOR WM_USER+203
121#define WM_DEBUG_STOP WM_USER+204
122#define WM_DEBUG_PAUSE WM_USER+205
123#define WM_CLOSE_DEBUGGER WM_USER+206
124
125///////////////////////////////////////////
126
127
128
129
130#define FILE_ALIGNMENT 0x1000
131#define MEM_ALIGNMENT 0x1000
132#define EXE_HEADER_SIZE 0x1000
133
134
135//クラス管理用のクラス
136#include "Class.h"
137
138//列挙体管理用のクラス
139#include "Enum.h"
140
141//定数管理用のクラス
142#include "Const.h"
143
144
145struct ERRORINFO{
146 char *FileName;
147 int line;
148};
149struct INCLUDEFILEINFO{
150 char **ppFileNames;
151 int FilesNum;
152 int LineOfFile[MAX_LEN];
153};
154
155
156//変数
157#define REF_PARAMETER 1
158#define OBJECT_PARAMETER 2
159struct VARIABLE{
160 char name[255];
161 int type;
162 union{
163 LONG_PTR index;
164 CClass *pobj_c;
165 }u;
166
167 DWORD fRef;
168
169 //定数変数かどうか
170 bool bConst;
171
172 BOOL bArray;
173 int SubScripts[MAX_ARRAYDIM];
174
175 //コンストラクタ用パラメータ
176 char *ConstractParameter;
177
178 /* --- オフセット ---
179
180 ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
181 初期バッファの有無が識別される。
182 (その後、スケジュール実行により、実際の配置に並び替えられる)*/
183 int offset;
184
185
186 //レキシカルスコープ用
187 int ScopeStartAddress;
188 int ScopeEndAddress;
189 int ScopeLevel;
190 BOOL bLiving;
191
192
193 int source_code_address;
194};
195
196//変数の相対情報
197struct RELATIVE_VAR{
198 DWORD dwKind;
199 LONG_PTR offset;
200 BOOL bOffsetOffset;
201};
202
203//パラメータ
204struct PARAMETER_INFO{
205 char *name;
206 int type;
207 union{
208 LONG_PTR index;
209 CClass *pobj_c;
210 }u;
211
212 BOOL bByVal;
213 BOOL bArray;
214 int SubScripts[MAX_ARRAYDIM];
215};
216
217#define SUBTYPE_SUB 1
218#define SUBTYPE_FUNCTION 2
219#define SUBTYPE_MACRO 3
220struct SUBINFO{
221 DWORD dwType;
222
223 //クラス情報
224 CClass *pobj_ParentClass;
225
226 long id;
227
228 char *name;
229 long address;
230
231 //パラメータ
232 PARAMETER_INFO *pParmInfo;
233 int ParmNum;
234 int SecondParmNum;
235 PARAMETER_INFO *pRealParmInfo;
236 int RealParmNum;
237 int RealSecondParmNum;
238
239 //戻り値
240 int ReturnType;
241 union{
242 LONG_PTR ReturnIndex;
243 CClass *Return_pobj_c;
244 }u;
245
246 DWORD CompileAddress;
247 DWORD EndOpAddr;
248 VARIABLE *pVar;
249 int VarNum;
250
251 BOOL bExport;
252 BOOL bCdecl;
253 BOOL bVirtual;
254 BOOL bUse;
255 BOOL bCompile;
256 BOOL bSystem;
257
258 SUBINFO *pNextData;
259};
260#define DECLARE_DYNAMIC 1
261#define DECLARE_STATIC 2
262struct DECLAREINFO{
263 DWORD dwType;
264
265 char *file;
266 char *name;
267 char *alias;
268 BOOL bCdecl;
269
270 //パラメータ
271 PARAMETER_INFO *pParmInfo;
272 int ParmNum;
273
274 //戻り値
275 int ReturnType;
276 union{
277 LONG_PTR ReturnIndex;
278 CClass *Return_pobj_c;
279 }u;
280
281 union{
282 int LookupAddress;
283 int StaticProc_CodeAddress;
284 };
285
286 BOOL bUse;
287
288 int pos;
289
290 DECLAREINFO *pNextData;
291};
292struct PROCPTRINFO{
293 PARAMETER_INFO *pParmInfo;
294 int ParmNum;
295
296 int ReturnType;
297 union{
298 LONG_PTR ReturnIndex;
299 CClass *Return_pobj_c;
300 }u;
301};
302struct CONSTINFO{
303 char *name;
304 char *StrValue;
305
306 double DblValue;
307 _int64 i64Value;
308 int type;
309 LONG_PTR lpIndex;
310
311 int ParmNum;
312 char **ppParm;
313
314 CONSTINFO *pNextData;
315};
316
317
318#define CODETYPE_SYSTEMPROC 0x0001
319#define CODETYPE_DEBUGPROC 0x0002
320struct LINEINFO{
321 int TopCp;
322 int TopObp;
323 DWORD dwCodeType;
324};
325struct RESOURCEDATAINFO{
326 DWORD dwId;
327 char FileName[MAX_PATH];
328};
329
330
331//////////////////////////////////////////
332// リソース ヘッダ(アイコン、カーソル用)
333typedef struct{
334 WORD idReserved;
335 WORD idType;
336 WORD idCount;
337}ICONDIR,CURSORDIR;
338
339
340/////////////////////////////
341// .curファイルのヘッダ情報
342struct CURSORDIRENTRY{
343 BYTE bWidth;
344 BYTE bHeight;
345 BYTE bColorCount;
346 BYTE bReserved;
347 WORD wXHotspot;
348 WORD wYHotspot;
349 DWORD dwBytesInRes;
350 DWORD dwImageOffset;
351};
352struct CURSORDIRENTRY_RES{
353 WORD wWidth;
354 WORD wHeight;
355 WORD wXHotspot;
356 WORD wYHotspot;
357 DWORD dwBytesInRes;
358 WORD wCursorNum;
359};
360
361
362////////////////////////////
363//.icoファイルのヘッダ情報
364struct ICONDIRENTRY{
365 BYTE bWidth;
366 BYTE bHeight;
367 BYTE bColorCount;
368 BYTE bReserved;
369 WORD wPlanes;
370 WORD wBitCount;
371 DWORD dwBytesInRes;
372 DWORD dwImageOffset;
373};
374struct ICONDIRENTRY_RES{
375 BYTE bWidth;
376 BYTE bHeight;
377 BYTE bColorCount;
378 BYTE bReserved;
379 WORD wPlanes;
380 WORD wBitCount;
381 DWORD dwBytesInRes;
382 WORD wIconNum;
383};
384
385
386
387#include "../BasicCompiler_Common/schedule.h"
388#include "../BasicCompiler_Common/DebugSection.h"
389#include "../BasicCompiler_Common/LexicalScoping.h"
390#include "../BasicCompiler_Common/Variable.h"
391#include "../BasicCompiler_Common/Exception.h"
392
393
394
395int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList=0);
396
397
398//BasicCompiler.cpp
399void HeapDefaultFree(LPVOID lpMem);
400void ts(int i);
401void ts(int i,int i2);
402void ts(char *msg);
403void ts(char *msg,char *title);
404void epi_check();
405void GetRelationalPath(char *path,char *dir);
406void GetFullPath(char *path,char *dir);
407void ShowErrorLine(int LineNum,char *FileName);
408BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
409void MakeMessageText(char *buffer,char *msg,int flag);
410
411//hash.cpp
412int hash_default(char *name);
413CONSTINFO *GetConstHash(char *name);
414DECLAREINFO *GetDeclareHash(char *name);
415SUBINFO *GetSubHash(char *name,BOOL bError=0);
416SUBINFO *GetMethodHash(char *ObjectName,char *MethodName,char *Parameter,BOOL bError=0);
417SUBINFO **GetOverloadObjectSubHash(char *name,CClass *pobj_c, int *pNum);
418SUBINFO **GetOverloadSubHash(char *name,int *pNum);
419
420//Object.cpp
421int GetSizeOfClassMember(CClass *pobj_c,char *pMemberName,int *pMemberNum);
422int GetSizeOfClass(CClass *pobj_c);
423void AddClassName(char *Parameter,int NowLine);
424void CallConstractor(char *VarName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter);
425void CallDestrouctorsOfScope(void);
426
427//Overload.sbp
428SUBINFO *OverloadSolutionWithStrParam(char *name,SUBINFO **ppsi,int num,char *Parameter,char *ObjectName,TYPEINFO *pReturnTypeInfo);
429SUBINFO *OverloadSolution(char *name,SUBINFO **ppsi,int num,PARAMETER_INFO *ppi,int ParmNum,TYPEINFO *pReturnTypeInfo);
430
431//Debug.cpp
432void Debugger_StepIn(void);
433void Debugger_StepOver(void);
434void Debugger_StepCursor(void);
435void Debugger_Stop(void);
436void Debugger_Pause(void);
437ULONG_PTR rva_to_real(DWORD p);
438SUBINFO *GetSubFromObp(ULONG_PTR pos);
439void ReadOpBuffer();
440void DebugProgram(void);
441
442//VarList.cpp
443void InitVarList(DWORD dwThreadId);
444BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
445BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
446
447//WatchList.cpp
448ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
449ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
450int Debugging_GetVarOffset(char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss);
451
452//MakeExe.cpp
453void StepCompileProgress(void);
454void DeleteConstInfo(CONSTINFO **ppConstHash);
455void DeleteDeclareInfo(void);
456void AddSourceCode(char *buffer);
457void OutputExe(void);
458int MainThread(DWORD dummy);
459
460//Intermediate_Step1.cpp
461void ChangeReturnCode(char *buffer);
462void DeleteComment(char *buffer);
463void KillReturnCode(char *buffer);
464void CheckParenthesis(char *buffer);
465BOOL CheckParenthesis2(char *buffer);
466void DirectiveCheck(void);
467void NextCommandFormat(char *buffer);
468void SetEscapeSequenceFormat(char *buffer);
469void DefCommandFormat(char *buffer);
470void IfCommandFormat(char *buffer);
471void CheckPareCommand(void);
472
473//Intermediate_Step2.cpp
474bool GetConstInfo(void);
475void ChangeCommandToCode(char *buffer);
476
477//preprocessor.cpp
478char *OpenBasicFile(char *FileName);
479
480//Resource.cpp
481void GetResourceData(char *FileName);
482
483//CommandFormat.cpp
484void ComOpen(char *Parameter,char *buffer,int NowLine);
485void ComClose(char *Parameter,char *buffer);
486void ComField(char *Parameter,char *buffer);
487void ComLine(char *Parameter,char *buffer,int NowLine);
488void ComCircle(char *Parameter,char *buffer,int NowLine);
489void ComPSet(char *Parameter,char *buffer,int NowLine);
490void ComPaint(char *Parameter,char *buffer,int NowLine);
491
492// StrOperation.cpp
493void KillSpaces(char *str1,char *str2);
494void KillStringSpaces(char *str);
495BOOL RemoveStringQuotes(char *str);
496void RemoveStringPare(char *str);
497void RemoveStringBracket(char *str);
498void SetStringQuotes(char *str);
499int FormatString_EscapeSequence(char *buffer);
500void SlideString(char *str,int slide);
501void SlideBuffer(char *buffer,int length,int slide);
502_int8 IsCommandDelimitation(char c);
503BOOL IsBlank(char c);
504int GetOneParameter(char *Parameter,int pos,char *retAns);
505int JumpOneParameter(char *Parameter,int i);
506int GetStringInQuotation(char *buffer,char *ReadBuffer);
507int GetStringInPare(char *buffer,const char *ReadBuffer);
508int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer);
509int GetStringInBracket(char *buffer,const char *ReadBuffer);
510int JumpStringInPare(char *buffer,int pos);
511int JumpStringInBracket(char *buffer,int pos);
512int GetCpFromLine(int LineNum);
513BOOL GetLineNum(int pos,int *pLine,char *FileName);
514char GetEndXXXCommand(char es);
515void GetDefaultNameFromES(char es,char *name);
516void GetCalcName(int idCalc,char *name);
517BOOL IsFile(char *path);
518BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
519
520//calculation.cpp
521bool IsNumberTopChar(const char *buffer);
522bool IsNumberChar(const char c);
523BOOL IsNumCalcMark(const char *Command,int p);
524BOOL IsNumCalcMark_Back(const char *Command,int p);
525BOOL IsStrCalcMark(const char c);
526BOOL IsExponent(const char *Command,int p);
527int GetLiteralIndex(_int64 i64data);
528int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
529DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
530BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer);
531DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
532BOOL IsStringObjectType(TYPEINFO *pTypeInfo);
533BOOL IsStringSubsituation(CClass *pobj_c);
534int IsStrCalculation(char *Command);
535BYTE GetCalcId(const char *Command,int *pi);
536BOOL GetNumOpeElements(const char *Command,int *pnum,
537 char *values[255],long calc[255],long stack[255]);
538
539//NumOpe_GetType.cpp
540int AutoBigCast(int BaseType,int CalcType);
541BOOL CheckCalcType(int idCalc,int *type,int sp);
542int NumOpe_GetType(char *Command,TYPEINFO *pBaseType,LONG_PTR *plpIndex);
543
544//Subroutine.cpp
545int GetCallProcName(char *buffer,char *name);
546int GetProc(char *name,void **ppInfo);
547void SplitObjectName(char *name,char *ObjectName,int *pRefType);
548bool SplitMemberName( const char *desc, char *object, char *member );
549int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
550BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
551BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2);
552SUBINFO *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic=0);
553void GetSubInfo(void);
554void DeleteSubInfo(SUBINFO **ppSubHash,char **ppMacroNames,int MacroNum);
555void DeleteDeclareInfo(void);
556int AddProcPtrInfo(char *buffer,DWORD dwProcType);
557void DeleteProcPtrInfo(void);
558
559//LoopRefCheck.cpp
560class CLoopRefCheck{
561 char **names;
562 int num;
563 void init();
564public:
565 CLoopRefCheck();
566 ~CLoopRefCheck();
567 void add(char *lpszInheritsClass);
568 void del(char *lpszInheritsClass);
569 BOOL check(char *lpszInheritsClass);
570};
571extern CLoopRefCheck *pobj_LoopRefCheck;
572
573//error.cpp
574void SetError(int ErrorNum,char *KeyWord,int pos);
575void CompileMessage(char *buffer);
576void CheckDifferentType(int VarType,LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,char *pszFuncName,int ParmNum);
577
578//Compile.cpp
579void GetIdentifierToken( char *token, const char *source, int &pos );
580int JumpStatement(const char *source, int &pos);
581void DebugVariable(void);
582void Compile(void);
583
584//gc.cpp
585void InitGCVariables(void);
586void PerformedGcVarSchedule(void);
587
588
589
590#ifdef _DEBUG
591/*Debug*/
592/*
593#define HeapAlloc CheckHeapAlloc
594#define HeapReAlloc CheckHeapReAlloc
595LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
596LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
597*/
598#endif
Note: See TracBrowser for help on using the repository browser.