source: dev/BasicCompiler_Common/common.h@ 6

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