source: dev/BasicCompiler_Common/common.h@ 55

Last change on this file since 55 was 55, checked in by dai_9181, 17 years ago

・コマンドラインオプション "/unicode" に対応。
・Unicode文字セットを使用する場合に "UNICODE" が自動的に#defineされるようにしました。
・SByte型(8ビット符号付き整数型)を追加。
・Char型を文字型に変更。
・プロジェクトオプションから「Unicode文字セットを使用する」チェックを選択できるようにしました。

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