source: dev/BasicCompiler_Common/common.h@ 72

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

Parameter.cpp→ParamImpl.cpp
CParameter→ParamImpl

Type.cpp、Type.hを用意した。

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