1 | #pragma once |
---|
2 | |
---|
3 | //#define _CRT_SECURE_NO_DEPRECATE |
---|
4 | #pragma warning(disable : 4996) |
---|
5 | |
---|
6 | #include <option.h> |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | #ifdef _AMD64_ |
---|
11 | #include "../BasicCompiler64/resource.h" |
---|
12 | #include "../BasicCompiler64/CommandValue.h" |
---|
13 | #include "../BasicCompiler64/FunctionValue.h" |
---|
14 | #define OPCODE_H_PATH "../BasicCompiler64/opcode.h" |
---|
15 | #else |
---|
16 | #include "../BasicCompiler32/resource.h" |
---|
17 | #include "../BasicCompiler32/CommandValue.h" |
---|
18 | #include "../BasicCompiler32/FunctionValue.h" |
---|
19 | #define OPCODE_H_PATH "../BasicCompiler32/opcode.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <jenga/include/smoothie/BasicFixed.h> |
---|
23 | #include "../BasicCompiler_Common/NonVolatile.h" |
---|
24 | #include "../BasicCompiler_Common/psapi.h" |
---|
25 | #include "../BasicCompiler_Common/BreakPoint.h" |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | #if defined(JPN) |
---|
30 | //日本語 |
---|
31 | #include "common_msg_jpn.h" |
---|
32 | #else |
---|
33 | //英語 |
---|
34 | #include "common_msg_eng.h" |
---|
35 | #endif |
---|
36 | |
---|
37 | |
---|
38 | #define PTR_SIZE sizeof(LONG_PTR) |
---|
39 | #define OBJECT_HEAD_SIZE PTR_SIZE*4 |
---|
40 | |
---|
41 | #define MAX_LEN 65535 |
---|
42 | #define DIGIT_SIZE 128 |
---|
43 | #define MAX_PARMS 64 |
---|
44 | #define MAX_ARRAYDIM 16 |
---|
45 | #define MAX_HASH 32761 |
---|
46 | |
---|
47 | |
---|
48 | #ifdef _AMD64_ |
---|
49 | #define PLATFORM 64 |
---|
50 | #else |
---|
51 | #define PLATFORM 32 |
---|
52 | #ifndef LONG_PTR |
---|
53 | typedef long LONG_PTR; |
---|
54 | typedef DWORD ULONG_PTR; |
---|
55 | #endif |
---|
56 | #endif |
---|
57 | |
---|
58 | |
---|
59 | //未定義の定数情報 |
---|
60 | #ifndef IMAGE_FILE_MACHINE_AMD64 |
---|
61 | #define IMAGE_FILE_MACHINE_AMD64 0x8664 |
---|
62 | #endif |
---|
63 | |
---|
64 | #ifdef _AMD64_ |
---|
65 | #ifndef IMAGE_SIZEOF_NT_OPTIONAL64_HEADER |
---|
66 | #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240 |
---|
67 | #endif |
---|
68 | #else |
---|
69 | #ifndef IMAGE_SIZEOF_NT_OPTIONAL32_HEADER |
---|
70 | #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224 |
---|
71 | #endif |
---|
72 | #endif |
---|
73 | |
---|
74 | |
---|
75 | extern HWND hOwnerEditor; |
---|
76 | extern HANDLE hHeap; |
---|
77 | extern int cp; |
---|
78 | extern int typeOfPtrChar; |
---|
79 | extern int typeOfPtrUChar; |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | ////////////////////////////////////////// |
---|
84 | // BasicCompiler、ProjectEditor共通の定数 |
---|
85 | ////////////////////////////////////////// |
---|
86 | |
---|
87 | //サイズ変更枠の太さ |
---|
88 | #define LEVER_THICK 5 |
---|
89 | |
---|
90 | #define WM_SHOWERROR WM_USER+70 //エラー表示メッセージ |
---|
91 | |
---|
92 | #define WM_SETCOMPILEVIEW WM_USER+71 //コンパイラウィンドウが表示されたとき |
---|
93 | #define WM_DESTROYCOMPILEVIEW WM_USER+72 //コンパイラウィンドウが破棄されたとき |
---|
94 | |
---|
95 | #define WM_SETDEBUGGERBASE WM_USER+73 //デバッガベースウィンドウが表示されたとき |
---|
96 | #define WM_DESTROYDEBUGGERBASE WM_USER+74 //デバッガベースウィンドウが破棄されたとき |
---|
97 | |
---|
98 | #define WM_SETDEBUGGERVIEW WM_USER+75 //デバッガウィンドウが表示されたとき |
---|
99 | #define WM_DESTROYDEBUGGERVIEW WM_USER+76 //デバッガウィンドウが表示されたとき |
---|
100 | |
---|
101 | /////////////////////////////////////////// |
---|
102 | |
---|
103 | |
---|
104 | #define WM_SHOWVARLIST WM_USER+80 |
---|
105 | #define WM_VARLIST_CLOSE WM_USER+81 //変数リストの終了メッセージ(破棄のみ、解放なし) |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | /////////////////////////////////////////// |
---|
110 | // デバッグ コマンド |
---|
111 | |
---|
112 | #define WM_DEBUG_CONTINUE WM_USER+200 |
---|
113 | #define WM_STEP_IN WM_USER+201 |
---|
114 | #define WM_STEP_OVER WM_USER+202 |
---|
115 | #define WM_STEP_CURSOR WM_USER+203 |
---|
116 | #define WM_DEBUG_STOP WM_USER+204 |
---|
117 | #define WM_DEBUG_PAUSE WM_USER+205 |
---|
118 | #define WM_CLOSE_DEBUGGER WM_USER+206 |
---|
119 | |
---|
120 | /////////////////////////////////////////// |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | #define FILE_ALIGNMENT 0x1000 |
---|
126 | #define MEM_ALIGNMENT 0x1000 |
---|
127 | #define EXE_HEADER_SIZE 0x1000 |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | struct ERRORINFO{ |
---|
132 | char *FileName; |
---|
133 | int line; |
---|
134 | }; |
---|
135 | |
---|
136 | //変数の相対情報 |
---|
137 | struct RELATIVE_VAR{ |
---|
138 | DWORD dwKind; |
---|
139 | LONG_PTR offset; |
---|
140 | BOOL bOffsetOffset; |
---|
141 | }; |
---|
142 | |
---|
143 | |
---|
144 | struct RESOURCEDATAINFO{ |
---|
145 | DWORD dwId; |
---|
146 | char FileName[MAX_PATH]; |
---|
147 | }; |
---|
148 | |
---|
149 | |
---|
150 | ////////////////////////////////////////// |
---|
151 | // リソース ヘッダ(アイコン、カーソル用) |
---|
152 | typedef struct{ |
---|
153 | WORD idReserved; |
---|
154 | WORD idType; |
---|
155 | WORD idCount; |
---|
156 | }ICONDIR,CURSORDIR; |
---|
157 | |
---|
158 | |
---|
159 | ///////////////////////////// |
---|
160 | // .curファイルのヘッダ情報 |
---|
161 | struct CURSORDIRENTRY{ |
---|
162 | BYTE bWidth; |
---|
163 | BYTE bHeight; |
---|
164 | BYTE bColorCount; |
---|
165 | BYTE bReserved; |
---|
166 | WORD wXHotspot; |
---|
167 | WORD wYHotspot; |
---|
168 | DWORD dwBytesInRes; |
---|
169 | DWORD dwImageOffset; |
---|
170 | }; |
---|
171 | struct CURSORDIRENTRY_RES{ |
---|
172 | WORD wWidth; |
---|
173 | WORD wHeight; |
---|
174 | WORD wXHotspot; |
---|
175 | WORD wYHotspot; |
---|
176 | DWORD dwBytesInRes; |
---|
177 | WORD wCursorNum; |
---|
178 | }; |
---|
179 | |
---|
180 | |
---|
181 | //////////////////////////// |
---|
182 | //.icoファイルのヘッダ情報 |
---|
183 | struct ICONDIRENTRY{ |
---|
184 | BYTE bWidth; |
---|
185 | BYTE bHeight; |
---|
186 | BYTE bColorCount; |
---|
187 | BYTE bReserved; |
---|
188 | WORD wPlanes; |
---|
189 | WORD wBitCount; |
---|
190 | DWORD dwBytesInRes; |
---|
191 | DWORD dwImageOffset; |
---|
192 | }; |
---|
193 | struct ICONDIRENTRY_RES{ |
---|
194 | BYTE bWidth; |
---|
195 | BYTE bHeight; |
---|
196 | BYTE bColorCount; |
---|
197 | BYTE bReserved; |
---|
198 | WORD wPlanes; |
---|
199 | WORD wBitCount; |
---|
200 | DWORD dwBytesInRes; |
---|
201 | WORD wIconNum; |
---|
202 | }; |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | #include "../BasicCompiler_Common/PESchedule.h" |
---|
207 | #include "../BasicCompiler_Common/VariableOpe.h" |
---|
208 | |
---|
209 | |
---|
210 | |
---|
211 | bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList=0, bool *pIsMemoryAccessError=NULL); |
---|
212 | |
---|
213 | |
---|
214 | //BasicCompiler.cpp |
---|
215 | void HeapDefaultFree(LPVOID lpMem); |
---|
216 | void ts(int i); |
---|
217 | void ts(int i,int i2); |
---|
218 | void ts(const char *msg); |
---|
219 | void ts(const char *msg,const char *title); |
---|
220 | void epi_check(); |
---|
221 | void GetRelationalPath(char *path,char *dir); |
---|
222 | void GetFullPath( char *path, const string &baseDirPath ); |
---|
223 | std::string GetApplicationBaseFullPath( const std::string &relationalPath ); |
---|
224 | void ShowErrorLine(int LineNum,const char *FileName); |
---|
225 | BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen); |
---|
226 | void MakeMessageText(char *buffer,char *msg,int flag); |
---|
227 | |
---|
228 | //hash.cpp |
---|
229 | int hash_default(const char *name); |
---|
230 | DllProc *GetDeclareHash(const char *name); |
---|
231 | void GetOverloadSubHash( const char *lpszName, std::vector<const UserProc *> &subs ); |
---|
232 | const UserProc *GetSubHash(const char *name,BOOL bError=0); |
---|
233 | const UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0); |
---|
234 | const UserProc *GetClassMethod( const char *className, const char *methodName ); |
---|
235 | |
---|
236 | //Object.cpp |
---|
237 | void CallConstructor( const char *ObjectName,const Subscripts &subscripts, const Type &type,const char *Parameter); |
---|
238 | bool Operator_New( const char *expression, const Type &baseType, Type &resultType ); |
---|
239 | |
---|
240 | //Overload.sbp |
---|
241 | class Parameters; |
---|
242 | const UserProc *OverloadSolutionWithStrParam( |
---|
243 | const char *name, |
---|
244 | std::vector<const UserProc *> &subs, |
---|
245 | const char *Parameter, |
---|
246 | const char *ObjectName); |
---|
247 | const UserProc *OverloadSolution( |
---|
248 | const char *name, |
---|
249 | std::vector<const UserProc *> &subs, |
---|
250 | const Parameters ¶ms, |
---|
251 | const Type &returnType ); |
---|
252 | |
---|
253 | //Debug.cpp |
---|
254 | void Debugger_StepIn(void); |
---|
255 | void Debugger_StepOver(void); |
---|
256 | void Debugger_StepCursor(void); |
---|
257 | void Debugger_Stop(void); |
---|
258 | void Debugger_Pause(void); |
---|
259 | ULONG_PTR rva_to_real(DWORD p); |
---|
260 | UserProc *GetSubFromObp(ULONG_PTR pos); |
---|
261 | void ReadOpBuffer(); |
---|
262 | void DebugProgram(void); |
---|
263 | |
---|
264 | //VarList.cpp |
---|
265 | void InitVarList(DWORD dwThreadId); |
---|
266 | BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam); |
---|
267 | BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam); |
---|
268 | |
---|
269 | //WatchList.cpp |
---|
270 | ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar); |
---|
271 | ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip); |
---|
272 | int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, Subscripts *pResultSubscripts = NULL ); |
---|
273 | |
---|
274 | //MakeExe.cpp |
---|
275 | void StepCompileProgress(void); |
---|
276 | void MakeMiddleCode( char *buffer ); |
---|
277 | void AddSourceCode(const char *buffer); |
---|
278 | void OutputExe(void); |
---|
279 | int MainThread(DWORD dummy); |
---|
280 | |
---|
281 | //Intermediate_Step1.cpp |
---|
282 | void ChangeReturnCode(char *buffer); |
---|
283 | void DeleteComment(char *buffer); |
---|
284 | void KillReturnCode(char *buffer); |
---|
285 | void CheckParenthesis(char *buffer); |
---|
286 | BOOL CheckParenthesis2(char *buffer); |
---|
287 | void DirectiveCheck(void); |
---|
288 | void NextCommandFormat(char *buffer); |
---|
289 | void SetEscapeSequenceFormat(char *buffer); |
---|
290 | void DefCommandFormat(char *buffer); |
---|
291 | void IfCommandFormat(char *buffer); |
---|
292 | void CheckPareCommand(void); |
---|
293 | |
---|
294 | //Intermediate_Step2.cpp |
---|
295 | bool GetConstInfo(void); |
---|
296 | void ChangeCommandToCode(char *buffer); |
---|
297 | |
---|
298 | //preprocessor.cpp |
---|
299 | char *OpenBasicFile(char *FileName); |
---|
300 | |
---|
301 | //Resource.cpp |
---|
302 | void GetResourceData(char *FileName); |
---|
303 | |
---|
304 | //CommandFormat.cpp |
---|
305 | void ComOpen(char *Parameter,char *buffer,int nowLine); |
---|
306 | void ComClose(char *Parameter,char *buffer); |
---|
307 | void ComField(char *Parameter,char *buffer); |
---|
308 | void ComLine(char *Parameter,char *buffer,int nowLine); |
---|
309 | void ComCircle(char *Parameter,char *buffer,int nowLine); |
---|
310 | void ComPSet(char *Parameter,char *buffer,int nowLine); |
---|
311 | void ComPaint(char *Parameter,char *buffer,int nowLine); |
---|
312 | |
---|
313 | // StrOperation.cpp |
---|
314 | void KillSpaces(char *str1,char *str2); |
---|
315 | void KillStringSpaces(char *str); |
---|
316 | BOOL RemoveStringQuotes(char *str); |
---|
317 | bool RemoveStringQuotes( std::string &str ); |
---|
318 | void RemoveStringPare(char *str); |
---|
319 | void RemoveStringBracket(char *str); |
---|
320 | void SetStringQuotes(char *str); |
---|
321 | int FormatString_EscapeSequence(char *buffer); |
---|
322 | void SlideString(char *str,int slide); |
---|
323 | void SlideBuffer(char *buffer,int length,int slide); |
---|
324 | int GetSourceCodeIndexFromLine( const char *source, int LineNum ); |
---|
325 | char GetEndXXXCommand(char es); |
---|
326 | void GetDefaultNameFromES(char es,char *name); |
---|
327 | const std::string &FormatEscapeSequenceStringToDefaultString( const std::string &source ); |
---|
328 | bool IsFileExist(const char *path); |
---|
329 | BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath); |
---|
330 | BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle); |
---|
331 | void ShortPathToLongPath(const char *ShortPath,char *LongPath); |
---|
332 | |
---|
333 | //calculation.cpp |
---|
334 | bool IsNumberTopChar(const char *buffer); |
---|
335 | bool IsNumberChar(const char c); |
---|
336 | BOOL IsNumCalcMark(const char *Command,int p); |
---|
337 | BOOL IsNumCalcMark_Back(const char *Command,int p); |
---|
338 | BOOL IsStrCalcMark(const char c); |
---|
339 | BOOL IsExponent(const char *Command,int p); |
---|
340 | int GetLiteralIndex(_int64 i64data); |
---|
341 | int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2); |
---|
342 | DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType, bool isNotifyError = true ); |
---|
343 | int IsStrCalculation(const char *Command); |
---|
344 | BYTE GetCalcId(const char *Command,int *pi); |
---|
345 | BOOL GetNumOpeElements(const char *Command,int *pnum, |
---|
346 | char *values[255],long calc[255],long stack[255]); |
---|
347 | |
---|
348 | //NumOpe_GetType.cpp |
---|
349 | int AutoBigCast(int BaseType,int CalcType); |
---|
350 | BOOL CheckCalcType(int idCalc,int *type,int sp); |
---|
351 | bool GetTermType( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL ); |
---|
352 | bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType, bool *pIsLiteralCalculation = NULL ); |
---|
353 | |
---|
354 | //Subroutine.cpp |
---|
355 | int GetCallProcName(char *buffer,char *name); |
---|
356 | int GetProc(char *name,void **ppInfo); |
---|
357 | void SplitObjectName(const char *name,char *ObjectName, ReferenceKind &referenceFind ); |
---|
358 | bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, const Type &baseType, Type &resultType, bool isCallOn = true ); |
---|
359 | bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType); |
---|
360 | bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ); |
---|
361 | bool GetReturnTypeOfIndexerGetterProc( const Type &classType, Type &resultType ); |
---|
362 | int AddProcPtrInfo( const string &typeExpression, int nowLine ); |
---|
363 | bool IsNeedProcCompile(); |
---|
364 | void CompileLocal(); |
---|
365 | |
---|
366 | //OldStatement.cpp |
---|
367 | void Opcode_Input(const char *Parameter); |
---|
368 | void Opcode_Print(const char *Parameter,BOOL bWrite); |
---|
369 | |
---|
370 | //error.cpp |
---|
371 | void SetError(int ErrorNum,const char *KeyWord,int pos); |
---|
372 | void SetError(int ErrorNum,const string &keyWord,int pos); |
---|
373 | void SetError(); |
---|
374 | void CompileMessage(const char *buffer); |
---|
375 | bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum); |
---|
376 | |
---|
377 | //Compile.cpp |
---|
378 | void GetIdentifierToken( char *token, const char *source, int &pos ); |
---|
379 | void GetCommandToken( char *token, const char *source, int &pos ); |
---|
380 | void GetCustomToken( char *token, const char *source, int &pos, char delimitation, bool isEscapeSequence ); |
---|
381 | void SplitGenericClassInstance( const char *fullName, char *className, Jenga::Common::Strings &typeParameters ); |
---|
382 | int JumpStatement(const char *source, int &pos); |
---|
383 | void Compile(void); |
---|
384 | |
---|
385 | //Diagnose.cpp |
---|
386 | void Diagnose(); |
---|
387 | |
---|
388 | //gc.cpp |
---|
389 | void InitGCVariables(void); |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | #ifdef _DEBUG |
---|
394 | /*Debug*/ |
---|
395 | /* |
---|
396 | #define HeapAlloc CheckHeapAlloc |
---|
397 | #define HeapReAlloc CheckHeapReAlloc |
---|
398 | LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes); |
---|
399 | LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes); |
---|
400 | */ |
---|
401 | #endif |
---|