source: dev/BasicCompiler_Common/common.h@ 16

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

グローバル領域外のConst定義を初期段階で収集しないようにしました。

File size: 14.5 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 "β8 (x64)"
41#else
42#define VER_INFO "β8"
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
392
393
394int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList=0);
395
396
397//BasicCompiler.cpp
398void HeapDefaultFree(LPVOID lpMem);
399void ts(int i);
400void ts(int i,int i2);
401void ts(char *msg);
402void ts(char *msg,char *title);
403void epi_check();
404void GetRelationalPath(char *path,char *dir);
405void GetFullPath(char *path,char *dir);
406void ShowErrorLine(int LineNum,char *FileName);
407BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
408void MakeMessageText(char *buffer,char *msg,int flag);
409
410//hash.cpp
411int hash_default(char *name);
412CONSTINFO *GetConstHash(char *name);
413DECLAREINFO *GetDeclareHash(char *name);
414SUBINFO *GetSubHash(char *name,BOOL bError=0);
415SUBINFO *GetMethodHash(char *ObjectName,char *MethodName,char *Parameter,BOOL bError=0);
416SUBINFO **GetOverloadObjectSubHash(char *name,CClass *pobj_c, int *pNum);
417SUBINFO **GetOverloadSubHash(char *name,int *pNum);
418
419//Object.cpp
420int GetSizeOfClassMember(CClass *pobj_c,char *pMemberName,int *pMemberNum);
421int GetSizeOfClass(CClass *pobj_c);
422void AddClassName(char *Parameter,int NowLine);
423void CallConstractor(char *VarName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter);
424void CallDestrouctorsOfScope(void);
425
426//Overload.sbp
427SUBINFO *OverloadSolutionWithStrParam(char *name,SUBINFO **ppsi,int num,char *Parameter,char *ObjectName,TYPEINFO *pReturnTypeInfo);
428SUBINFO *OverloadSolution(char *name,SUBINFO **ppsi,int num,PARAMETER_INFO *ppi,int ParmNum,TYPEINFO *pReturnTypeInfo);
429
430//Debug.cpp
431void Debugger_StepIn(void);
432void Debugger_StepOver(void);
433void Debugger_StepCursor(void);
434void Debugger_Stop(void);
435void Debugger_Pause(void);
436ULONG_PTR rva_to_real(DWORD p);
437SUBINFO *GetSubFromObp(ULONG_PTR pos);
438void ReadOpBuffer();
439void DebugProgram(void);
440
441//VarList.cpp
442void InitVarList(DWORD dwThreadId);
443BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
444BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
445
446//WatchList.cpp
447ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
448ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
449int Debugging_GetVarOffset(char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss);
450
451//MakeExe.cpp
452void StepCompileProgress(void);
453void DeleteConstInfo(CONSTINFO **ppConstHash);
454void DeleteDeclareInfo(void);
455void AddSourceCode(char *buffer);
456void OutputExe(void);
457int MainThread(DWORD dummy);
458
459//Intermediate_Step1.cpp
460void ChangeReturnCode(char *buffer);
461void DeleteComment(char *buffer);
462void KillReturnCode(char *buffer);
463void CheckParenthesis(char *buffer);
464BOOL CheckParenthesis2(char *buffer);
465void DirectiveCheck(void);
466void NextCommandFormat(char *buffer);
467void SetEscapeSequenceFormat(char *buffer);
468void DefCommandFormat(char *buffer);
469void IfCommandFormat(char *buffer);
470void CheckPareCommand(void);
471
472//Intermediate_Step2.cpp
473bool GetConstInfo(void);
474void ChangeCommandToCode(char *buffer);
475
476//preprocessor.cpp
477char *OpenBasicFile(char *FileName);
478
479//Resource.cpp
480void GetResourceData(char *FileName);
481
482//CommandFormat.cpp
483void ComOpen(char *Parameter,char *buffer,int NowLine);
484void ComClose(char *Parameter,char *buffer);
485void ComField(char *Parameter,char *buffer);
486void ComLine(char *Parameter,char *buffer,int NowLine);
487void ComCircle(char *Parameter,char *buffer,int NowLine);
488void ComPSet(char *Parameter,char *buffer,int NowLine);
489void ComPaint(char *Parameter,char *buffer,int NowLine);
490
491// StrOperation.cpp
492void KillSpaces(char *str1,char *str2);
493void KillStringSpaces(char *str);
494BOOL RemoveStringQuotes(char *str);
495void RemoveStringPare(char *str);
496void RemoveStringBracket(char *str);
497void SetStringQuotes(char *str);
498int FormatString_EscapeSequence(char *buffer);
499void SlideString(char *str,int slide);
500void SlideBuffer(char *buffer,int length,int slide);
501_int8 IsCommandDelimitation(char c);
502BOOL IsBlank(char c);
503int GetOneParameter(char *Parameter,int pos,char *retAns);
504int JumpOneParameter(char *Parameter,int i);
505int GetStringInQuotation(char *buffer,char *ReadBuffer);
506int GetStringInPare(char *buffer,const char *ReadBuffer);
507int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer);
508int GetStringInBracket(char *buffer,const char *ReadBuffer);
509int JumpStringInPare(char *buffer,int pos);
510int JumpStringInBracket(char *buffer,int pos);
511int GetCpFromLine(int LineNum);
512BOOL GetLineNum(int pos,int *pLine,char *FileName);
513char GetEndXXXCommand(char es);
514void GetDefaultNameFromES(char es,char *name);
515void GetCalcName(int idCalc,char *name);
516BOOL IsFile(char *path);
517BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
518
519//calculation.cpp
520bool IsNumberTopChar(const char *buffer);
521bool IsNumberChar(const char c);
522BOOL IsNumCalcMark(const char *Command,int p);
523BOOL IsNumCalcMark_Back(const char *Command,int p);
524BOOL IsStrCalcMark(const char c);
525BOOL IsExponent(const char *Command,int p);
526int GetLiteralIndex(_int64 i64data);
527int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
528DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
529BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer);
530DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
531BOOL IsStringObjectType(TYPEINFO *pTypeInfo);
532BOOL IsStringSubsituation(CClass *pobj_c);
533int IsStrCalculation(char *Command);
534BYTE GetCalcId(const char *Command,int *pi);
535BOOL GetNumOpeElements(const char *Command,int *pnum,
536 char *values[255],long calc[255],long stack[255]);
537
538//NumOpe_GetType.cpp
539int AutoBigCast(int BaseType,int CalcType);
540BOOL CheckCalcType(int idCalc,int *type,int sp);
541int NumOpe_GetType(char *Command,TYPEINFO *pBaseType,LONG_PTR *plpIndex);
542
543//Subroutine.cpp
544int GetCallProcName(char *buffer,char *name);
545int GetProc(char *name,void **ppInfo);
546void GetObjectName(char *name,char *ObjectName,int *pRefType);
547int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
548BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
549BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2);
550SUBINFO *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic=0);
551void GetSubInfo(void);
552void DeleteSubInfo(SUBINFO **ppSubHash,char **ppMacroNames,int MacroNum);
553void DeleteDeclareInfo(void);
554int AddProcPtrInfo(char *buffer,DWORD dwProcType);
555void DeleteProcPtrInfo(void);
556
557//LoopRefCheck.cpp
558class CLoopRefCheck{
559 char **names;
560 int num;
561 void init();
562public:
563 CLoopRefCheck();
564 ~CLoopRefCheck();
565 void add(char *lpszInheritsClass);
566 void del(char *lpszInheritsClass);
567 BOOL check(char *lpszInheritsClass);
568};
569extern CLoopRefCheck *pobj_LoopRefCheck;
570
571//error.cpp
572void SetError(int ErrorNum,char *KeyWord,int pos);
573void CompileMessage(char *buffer);
574void CheckDifferentType(int VarType,LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,char *pszFuncName,int ParmNum);
575
576//Compile.cpp
577int JumpStatement(const char *source, int &pos);
578void DebugVariable(void);
579void Compile(void);
580
581//gc.cpp
582void InitGCVariables(void);
583void PerformedGcVarSchedule(void);
584
585
586
587#ifdef _DEBUG
588/*Debug*/
589/*
590#define HeapAlloc CheckHeapAlloc
591#define HeapReAlloc CheckHeapReAlloc
592LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
593LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
594*/
595#endif
Note: See TracBrowser for help on using the repository browser.