source: dev/BasicCompiler_Common/common.h@ 80

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

バージョンをβ17にした。
#strictをデフォルトの状態で適用するようにした(#90)。
Dimステートメントにおいて、初期値式とAsが同時に指定されていたとき、As以降も初期値式の一部として捉えるよう、変更(#91)。
GetTypeDef関数を完全廃止。

File size: 13.9 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#include <fstream>
15
16//boost libraries
17#include <boost/foreach.hpp>
18
19#define foreach BOOST_FOREACH
20
21using namespace std;
22
23#ifdef _AMD64_
24#include "../BasicCompiler64/resource.h"
25#include "../BasicCompiler64/CommandValue.h"
26#include "../BasicCompiler64/FunctionValue.h"
27#define OPCODE_H_PATH "../BasicCompiler64/opcode.h"
28#else
29#include "../BasicCompiler32/resource.h"
30#include "../BasicCompiler32/CommandValue.h"
31#include "../BasicCompiler32/FunctionValue.h"
32#define OPCODE_H_PATH "../BasicCompiler32/opcode.h"
33#endif
34
35#include "../BasicCompiler_Common/BasicFixed.h"
36#include "../BasicCompiler_Common/NonVolatile.h"
37#include "../BasicCompiler_Common/psapi.h"
38#include "../BasicCompiler_Common/BreakPoint.h"
39#include "../BasicCompiler_Common/LexicalScoping.h"
40
41
42
43//バージョン
44#define MAJOR_VER 5
45#define MINOR_VER 00
46#define REVISION_VER 00
47
48#ifdef _AMD64_
49#define VER_INFO "β17 (x64)"
50#else
51#define VER_INFO "β17"
52#endif
53
54#if defined(JPN)
55//日本語
56#include "common_msg_jpn.h"
57#else
58//英語
59#include "common_msg_eng.h"
60#endif
61
62
63#pragma comment(lib, "psapi.lib")
64
65
66#define PTR_SIZE sizeof(LONG_PTR)
67
68#define MAX_LEN 65535
69#define VN_SIZE 512
70#define DIGIT_SIZE 128
71#define MAX_PARMS 64
72#define MAX_ARRAYDIM 16
73#define MAX_HASH 32761
74
75
76#ifdef _AMD64_
77#define PLATFORM 64
78#else
79#define PLATFORM 32
80typedef long LONG_PTR;
81typedef DWORD ULONG_PTR;
82#endif
83
84
85//未定義の定数情報
86#define IMAGE_FILE_MACHINE_AMD64 0x8664
87
88
89
90extern HWND hOwnerEditor;
91extern HANDLE hHeap;
92extern char BasicSystemDir[MAX_PATH];
93extern int cp;
94extern bool isUnicode;
95extern int typeOfPtrChar;
96
97
98
99//////////////////////////////////////////
100// BasicCompiler、ProjectEditor共通の定数
101//////////////////////////////////////////
102
103//サイズ変更枠の太さ
104#define LEVER_THICK 5
105
106#define WM_SHOWERROR WM_USER+70 //エラー表示メッセージ
107
108#define WM_SETCOMPILEVIEW WM_USER+71 //コンパイラウィンドウが表示されたとき
109#define WM_DESTROYCOMPILEVIEW WM_USER+72 //コンパイラウィンドウが破棄されたとき
110
111#define WM_SETDEBUGGERBASE WM_USER+73 //デバッガベースウィンドウが表示されたとき
112#define WM_DESTROYDEBUGGERBASE WM_USER+74 //デバッガベースウィンドウが破棄されたとき
113
114#define WM_SETDEBUGGERVIEW WM_USER+75 //デバッガウィンドウが表示されたとき
115#define WM_DESTROYDEBUGGERVIEW WM_USER+76 //デバッガウィンドウが表示されたとき
116
117///////////////////////////////////////////
118
119
120#define WM_SHOWVARLIST WM_USER+80
121#define WM_VARLIST_CLOSE WM_USER+81 //変数リストの終了メッセージ(破棄のみ、解放なし)
122
123
124
125///////////////////////////////////////////
126// デバッグ コマンド
127
128#define WM_DEBUG_CONTINUE WM_USER+200
129#define WM_STEP_IN WM_USER+201
130#define WM_STEP_OVER WM_USER+202
131#define WM_STEP_CURSOR WM_USER+203
132#define WM_DEBUG_STOP WM_USER+204
133#define WM_DEBUG_PAUSE WM_USER+205
134#define WM_CLOSE_DEBUGGER WM_USER+206
135
136///////////////////////////////////////////
137
138
139
140
141#define FILE_ALIGNMENT 0x1000
142#define MEM_ALIGNMENT 0x1000
143#define EXE_HEADER_SIZE 0x1000
144
145
146// クラス管理用のクラス
147#include "Class.h"
148
149// 列挙体管理用のクラス
150#include "Enum.h"
151
152// 定数管理用のクラス
153#include "Const.h"
154
155// 変数管理用のクラス
156#include "Variable.h"
157
158// パラメータ管理用のクラス
159#include "Parameter.h"
160
161// プロシージャ管理用のクラス
162#include "Procedure.h"
163
164// コンパイラが必要とするデータハウス
165#include <House.h>
166
167
168
169struct ERRORINFO{
170 char *FileName;
171 int line;
172};
173struct INCLUDEFILEINFO{
174 char **ppFileNames;
175 int FilesNum;
176 int LineOfFile[MAX_LEN];
177};
178
179//変数の相対情報
180struct RELATIVE_VAR{
181 DWORD dwKind;
182 LONG_PTR offset;
183 BOOL bOffsetOffset;
184};
185
186struct CONSTINFO{
187 char *name;
188 char *StrValue;
189
190 double DblValue;
191 _int64 i64Value;
192 int type;
193 LONG_PTR lpIndex;
194
195 int ParmNum;
196 char **ppParm;
197
198 CONSTINFO *pNextData;
199};
200
201
202#define CODETYPE_SYSTEMPROC 0x0001
203#define CODETYPE_DEBUGPROC 0x0002
204struct LINEINFO{
205 int TopCp;
206 int TopObp;
207 DWORD dwCodeType;
208};
209struct RESOURCEDATAINFO{
210 DWORD dwId;
211 char FileName[MAX_PATH];
212};
213
214
215//////////////////////////////////////////
216// リソース ヘッダ(アイコン、カーソル用)
217typedef struct{
218 WORD idReserved;
219 WORD idType;
220 WORD idCount;
221}ICONDIR,CURSORDIR;
222
223
224/////////////////////////////
225// .curファイルのヘッダ情報
226struct CURSORDIRENTRY{
227 BYTE bWidth;
228 BYTE bHeight;
229 BYTE bColorCount;
230 BYTE bReserved;
231 WORD wXHotspot;
232 WORD wYHotspot;
233 DWORD dwBytesInRes;
234 DWORD dwImageOffset;
235};
236struct CURSORDIRENTRY_RES{
237 WORD wWidth;
238 WORD wHeight;
239 WORD wXHotspot;
240 WORD wYHotspot;
241 DWORD dwBytesInRes;
242 WORD wCursorNum;
243};
244
245
246////////////////////////////
247//.icoファイルのヘッダ情報
248struct ICONDIRENTRY{
249 BYTE bWidth;
250 BYTE bHeight;
251 BYTE bColorCount;
252 BYTE bReserved;
253 WORD wPlanes;
254 WORD wBitCount;
255 DWORD dwBytesInRes;
256 DWORD dwImageOffset;
257};
258struct ICONDIRENTRY_RES{
259 BYTE bWidth;
260 BYTE bHeight;
261 BYTE bColorCount;
262 BYTE bReserved;
263 WORD wPlanes;
264 WORD wBitCount;
265 DWORD dwBytesInRes;
266 WORD wIconNum;
267};
268
269
270
271#include "../BasicCompiler_Common/PESchedule.h"
272#include "../BasicCompiler_Common/DebugSection.h"
273#include "../BasicCompiler_Common/VariableOpe.h"
274#include "../BasicCompiler_Common/Exception.h"
275
276
277
278bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList=0, bool *pIsMemoryAccessError=NULL);
279
280
281//BasicCompiler.cpp
282void HeapDefaultFree(LPVOID lpMem);
283void ts(int i);
284void ts(int i,int i2);
285void ts(char *msg);
286void ts(char *msg,char *title);
287void epi_check();
288void GetRelationalPath(char *path,char *dir);
289void GetFullPath(char *path,char *dir);
290void ShowErrorLine(int LineNum,char *FileName);
291BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
292void MakeMessageText(char *buffer,char *msg,int flag);
293
294//hash.cpp
295int hash_default(const char *name);
296CONSTINFO *GetConstHash(char *name);
297DllProc *GetDeclareHash(char *name);
298UserProc *GetSubHash(const char *name,BOOL bError=0);
299UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0);
300void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs );
301
302//Object.cpp
303void CallConstructor( const char *ObjectName,const int *SubScripts, const Type &type,const char *Parameter);
304bool Operator_New( const char *expression, const Type &baseType, Type &resultType );
305
306//Overload.sbp
307UserProc *OverloadSolutionWithStrParam(
308 const char *name,
309 std::vector<UserProc *> &subs,
310 const char *Parameter,
311 const char *ObjectName);
312UserProc *OverloadSolution(
313 const char *name,
314 std::vector<UserProc *> &subs,
315 const Parameters &params,
316 const Type &returnType );
317
318//Debug.cpp
319void Debugger_StepIn(void);
320void Debugger_StepOver(void);
321void Debugger_StepCursor(void);
322void Debugger_Stop(void);
323void Debugger_Pause(void);
324ULONG_PTR rva_to_real(DWORD p);
325UserProc *GetSubFromObp(ULONG_PTR pos);
326void ReadOpBuffer();
327void DebugProgram(void);
328
329//VarList.cpp
330void InitVarList(DWORD dwThreadId);
331BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
332BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
333
334//WatchList.cpp
335ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
336ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
337int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss);
338
339//MakeExe.cpp
340void StepCompileProgress(void);
341void DeleteConstInfo(CONSTINFO **ppConstHash);
342void DeleteDeclareInfo(void);
343void AddSourceCode(char *buffer);
344void OutputExe(void);
345int MainThread(DWORD dummy);
346
347//Intermediate_Step1.cpp
348void ChangeReturnCode(char *buffer);
349void DeleteComment(char *buffer);
350void KillReturnCode(char *buffer);
351void CheckParenthesis(char *buffer);
352BOOL CheckParenthesis2(char *buffer);
353void DirectiveCheck(void);
354void NextCommandFormat(char *buffer);
355void SetEscapeSequenceFormat(char *buffer);
356void DefCommandFormat(char *buffer);
357void IfCommandFormat(char *buffer);
358void CheckPareCommand(void);
359
360//Intermediate_Step2.cpp
361bool GetConstInfo(void);
362void ChangeCommandToCode(char *buffer);
363
364//preprocessor.cpp
365char *OpenBasicFile(char *FileName);
366
367//Resource.cpp
368void GetResourceData(char *FileName);
369
370//CommandFormat.cpp
371void ComOpen(char *Parameter,char *buffer,int nowLine);
372void ComClose(char *Parameter,char *buffer);
373void ComField(char *Parameter,char *buffer);
374void ComLine(char *Parameter,char *buffer,int nowLine);
375void ComCircle(char *Parameter,char *buffer,int nowLine);
376void ComPSet(char *Parameter,char *buffer,int nowLine);
377void ComPaint(char *Parameter,char *buffer,int nowLine);
378
379// StrOperation.cpp
380void KillSpaces(char *str1,char *str2);
381void KillStringSpaces(char *str);
382BOOL RemoveStringQuotes(char *str);
383void RemoveStringPare(char *str);
384void RemoveStringBracket(char *str);
385void SetStringQuotes(char *str);
386int FormatString_EscapeSequence(char *buffer);
387void SlideString(char *str,int slide);
388void SlideBuffer(char *buffer,int length,int slide);
389_int8 IsCommandDelimitation(char c);
390BOOL IsBlank(char c);
391int GetOneParameter(const char *Parameter,int pos,char *retAns);
392int JumpOneParameter(char *Parameter,int i);
393int GetStringInQuotation(char *buffer,char *ReadBuffer);
394int GetStringInPare(char *buffer,const char *ReadBuffer);
395int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer);
396int GetStringInBracket(char *buffer,const char *ReadBuffer);
397int JumpStringInPare(const char *buffer,int pos);
398int JumpStringInBracket(const char *buffer,int pos);
399int GetCpFromLine(int LineNum);
400BOOL GetLineNum(int pos,int *pLine,char *FileName);
401char GetEndXXXCommand(char es);
402void GetDefaultNameFromES(char es,char *name);
403void GetCalcName(int idCalc,char *name);
404BOOL IsFile(char *path);
405BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath);
406BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
407void ShortPathToLongPath(const char *ShortPath,char *LongPath);
408
409//calculation.cpp
410bool IsNumberTopChar(const char *buffer);
411bool IsNumberChar(const char c);
412BOOL IsNumCalcMark(const char *Command,int p);
413BOOL IsNumCalcMark_Back(const char *Command,int p);
414BOOL IsStrCalcMark(const char c);
415BOOL IsExponent(const char *Command,int p);
416int GetLiteralIndex(_int64 i64data);
417int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
418DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
419BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer);
420DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
421bool IsStringObjectType(const Type &TypeInfo);
422int IsStrCalculation(char *Command);
423BYTE GetCalcId(const char *Command,int *pi);
424BOOL GetNumOpeElements(const char *Command,int *pnum,
425 char *values[255],long calc[255],long stack[255]);
426
427//NumOpe_GetType.cpp
428int AutoBigCast(int BaseType,int CalcType);
429BOOL CheckCalcType(int idCalc,int *type,int sp);
430bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType );
431
432//Subroutine.cpp
433int GetCallProcName(char *buffer,char *name);
434int GetProc(char *name,void **ppInfo);
435void SplitObjectName(const char *name,char *ObjectName,int *pRefType);
436bool SplitMemberName( const char *desc, char *object, char *member );
437bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true );
438bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType);
439bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType );
440bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType );
441UserProc *AddSubData(char *buffer,int nowLine,BOOL bVirtual,CClass *pobj_c, bool isStatic = false );
442void GetSubInfo(void);
443void DeleteSubInfo(UserProc **ppSubHash,char **ppMacroNames,int MacroNum);
444void DeleteDeclareInfo(void);
445int AddProcPtrInfo( const string &typeExpression, int nowLine );
446void DeleteProcPtrInfo(void);
447
448//OldStatement.cpp
449void Opcode_Input(const char *Parameter);
450void Opcode_Print(const char *Parameter,BOOL bWrite);
451
452//LoopRefCheck.cpp
453class CLoopRefCheck{
454 char **names;
455 int num;
456 void init();
457public:
458 CLoopRefCheck();
459 ~CLoopRefCheck();
460 void add(char *lpszInheritsClass);
461 void del(char *lpszInheritsClass);
462 BOOL check(char *lpszInheritsClass);
463};
464extern CLoopRefCheck *pobj_LoopRefCheck;
465
466//DataTable.cpp
467class DataTable{
468 void *pdata;
469 int size;
470
471public:
472 DataTable();
473 ~DataTable();
474 void Init();
475
476 int AddBinary( const void *pdata, int size );
477 int Add( _int64 i64data );
478 int Add( int i32data );
479 int Add( double dbl );
480 int Add( float flt );
481 int AddString( const char *str, int length );
482 int AddString( const char *str );
483
484 const void *GetPtr() const;
485 int GetSize() const;
486};
487extern DataTable dataTable;
488
489//error.cpp
490void SetError(int ErrorNum,const char *KeyWord,int pos);
491void SetError(int ErrorNum,const string &keyWord,int pos);
492void SetError();
493void CompileMessage(char *buffer);
494bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,const int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum);
495bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum);
496
497//Compile.cpp
498void GetIdentifierToken( char *token, const char *source, int &pos );
499int JumpStatement(const char *source, int &pos);
500void DebugVariable(void);
501void Compile(void);
502
503//gc.cpp
504void InitGCVariables(void);
505void PerformedGcVarSchedule(void);
506
507
508
509#ifdef _DEBUG
510/*Debug*/
511/*
512#define HeapAlloc CheckHeapAlloc
513#define HeapReAlloc CheckHeapReAlloc
514LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
515LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
516*/
517#endif
Note: See TracBrowser for help on using the repository browser.