source: dev/BasicCompiler_Common/common.h@ 9

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

Constステートメントで定数変数を宣言できるように改良。

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