source: dev/trunk/abdev/BasicCompiler_Common/common.h@ 185

Last change on this file since 185 was 182, checked in by dai_9181, 17 years ago
File size: 12.5 KB
Line 
1//#define _CRT_SECURE_NO_DEPRECATE
2#pragma warning(disable : 4996)
3
4#include <option.h>
5
6#include <windows.h>
7#include <stdio.h>
8#include <string.h>
9#include <math.h>
10#include <commctrl.h>
11#include <time.h>
12#include <limits.h>
13#include <shlobj.h>
14#include <vector>
15#include <string>
16#include <fstream>
17
18//boost libraries
19#include <boost/foreach.hpp>
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
40
41
42#if defined(JPN)
43//日本語
44#include "common_msg_jpn.h"
45#else
46//英語
47#include "common_msg_eng.h"
48#endif
49
50
51#define PTR_SIZE sizeof(LONG_PTR)
52#define OBJECT_HEAD_SIZE PTR_SIZE*4
53
54#define MAX_LEN 65535
55#define DIGIT_SIZE 128
56#define MAX_PARMS 64
57#define MAX_ARRAYDIM 16
58#define MAX_HASH 32761
59
60
61#ifdef _AMD64_
62#define PLATFORM 64
63#else
64#define PLATFORM 32
65typedef long LONG_PTR;
66typedef DWORD ULONG_PTR;
67#endif
68
69
70//未定義の定数情報
71#ifndef IMAGE_FILE_MACHINE_AMD64
72 #define IMAGE_FILE_MACHINE_AMD64 0x8664
73#endif
74
75#ifdef _AMD64_
76 #ifndef IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
77 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
78 #endif
79#else
80 #ifndef IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
81 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
82 #endif
83#endif
84
85
86extern HWND hOwnerEditor;
87extern HANDLE hHeap;
88extern int cp;
89extern int typeOfPtrChar;
90extern int typeOfPtrUChar;
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 "Enum.h"
143
144// 定数管理用のクラス
145#include "Const.h"
146
147
148
149struct ERRORINFO{
150 char *FileName;
151 int line;
152};
153
154//変数の相対情報
155struct RELATIVE_VAR{
156 DWORD dwKind;
157 LONG_PTR offset;
158 BOOL bOffsetOffset;
159};
160
161struct CONSTINFO{
162 char *name;
163 char *StrValue;
164
165 double DblValue;
166 _int64 i64Value;
167 int type;
168 LONG_PTR lpIndex;
169
170 int ParmNum;
171 char **ppParm;
172
173 CONSTINFO *pNextData;
174};
175
176
177#define CODETYPE_SYSTEMPROC 0x0001
178#define CODETYPE_DEBUGPROC 0x0002
179struct LINEINFO{
180 int TopCp;
181 int TopObp;
182 DWORD dwCodeType;
183};
184struct RESOURCEDATAINFO{
185 DWORD dwId;
186 char FileName[MAX_PATH];
187};
188
189
190//////////////////////////////////////////
191// リソース ヘッダ(アイコン、カーソル用)
192typedef struct{
193 WORD idReserved;
194 WORD idType;
195 WORD idCount;
196}ICONDIR,CURSORDIR;
197
198
199/////////////////////////////
200// .curファイルのヘッダ情報
201struct CURSORDIRENTRY{
202 BYTE bWidth;
203 BYTE bHeight;
204 BYTE bColorCount;
205 BYTE bReserved;
206 WORD wXHotspot;
207 WORD wYHotspot;
208 DWORD dwBytesInRes;
209 DWORD dwImageOffset;
210};
211struct CURSORDIRENTRY_RES{
212 WORD wWidth;
213 WORD wHeight;
214 WORD wXHotspot;
215 WORD wYHotspot;
216 DWORD dwBytesInRes;
217 WORD wCursorNum;
218};
219
220
221////////////////////////////
222//.icoファイルのヘッダ情報
223struct ICONDIRENTRY{
224 BYTE bWidth;
225 BYTE bHeight;
226 BYTE bColorCount;
227 BYTE bReserved;
228 WORD wPlanes;
229 WORD wBitCount;
230 DWORD dwBytesInRes;
231 DWORD dwImageOffset;
232};
233struct ICONDIRENTRY_RES{
234 BYTE bWidth;
235 BYTE bHeight;
236 BYTE bColorCount;
237 BYTE bReserved;
238 WORD wPlanes;
239 WORD wBitCount;
240 DWORD dwBytesInRes;
241 WORD wIconNum;
242};
243
244
245
246#include "../BasicCompiler_Common/PESchedule.h"
247#include "../BasicCompiler_Common/DebugSection.h"
248#include "../BasicCompiler_Common/VariableOpe.h"
249
250
251
252bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList=0, bool *pIsMemoryAccessError=NULL);
253
254
255//BasicCompiler.cpp
256void HeapDefaultFree(LPVOID lpMem);
257void ts(int i);
258void ts(int i,int i2);
259void ts(char *msg);
260void ts(char *msg,char *title);
261void epi_check();
262void GetRelationalPath(char *path,char *dir);
263void GetFullPath( char *path, const string &baseDirPath );
264void ShowErrorLine(int LineNum,char *FileName);
265BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
266void MakeMessageText(char *buffer,char *msg,int flag);
267
268//hash.cpp
269int hash_default(const char *name);
270CONSTINFO *GetConstHash(const char *name);
271DllProc *GetDeclareHash(char *name);
272void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs );
273UserProc *GetSubHash(const char *name,BOOL bError=0);
274UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0);
275UserProc *GetClassMethod( const char *className, const char *methodName );
276
277//Object.cpp
278void CallConstructor( const char *ObjectName,const int *SubScripts, const Type &type,const char *Parameter);
279bool Operator_New( const char *expression, const Type &baseType, Type &resultType );
280
281//Overload.sbp
282UserProc *OverloadSolutionWithStrParam(
283 const char *name,
284 std::vector<UserProc *> &subs,
285 const char *Parameter,
286 const char *ObjectName);
287UserProc *OverloadSolution(
288 const char *name,
289 std::vector<UserProc *> &subs,
290 const Parameters &params,
291 const Type &returnType );
292
293//Debug.cpp
294void Debugger_StepIn(void);
295void Debugger_StepOver(void);
296void Debugger_StepCursor(void);
297void Debugger_Stop(void);
298void Debugger_Pause(void);
299ULONG_PTR rva_to_real(DWORD p);
300GlobalProc *GetSubFromObp(ULONG_PTR pos);
301void ReadOpBuffer();
302void DebugProgram(void);
303
304//VarList.cpp
305void InitVarList(DWORD dwThreadId);
306BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
307BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
308
309//WatchList.cpp
310ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
311ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
312int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss);
313
314//MakeExe.cpp
315void StepCompileProgress(void);
316void DeleteConstInfo(CONSTINFO **ppConstHash);
317void DeleteDeclareInfo(void);
318void AddSourceCode(char *buffer);
319void OutputExe(void);
320int MainThread(DWORD dummy);
321
322//Intermediate_Step1.cpp
323void ChangeReturnCode(char *buffer);
324void DeleteComment(char *buffer);
325void KillReturnCode(char *buffer);
326void CheckParenthesis(char *buffer);
327BOOL CheckParenthesis2(char *buffer);
328void DirectiveCheck(void);
329void NextCommandFormat(char *buffer);
330void SetEscapeSequenceFormat(char *buffer);
331void DefCommandFormat(char *buffer);
332void IfCommandFormat(char *buffer);
333void CheckPareCommand(void);
334
335//Intermediate_Step2.cpp
336bool GetConstInfo(void);
337void ChangeCommandToCode(char *buffer);
338
339//preprocessor.cpp
340char *OpenBasicFile(char *FileName);
341
342//Resource.cpp
343void GetResourceData(char *FileName);
344
345//CommandFormat.cpp
346void ComOpen(char *Parameter,char *buffer,int nowLine);
347void ComClose(char *Parameter,char *buffer);
348void ComField(char *Parameter,char *buffer);
349void ComLine(char *Parameter,char *buffer,int nowLine);
350void ComCircle(char *Parameter,char *buffer,int nowLine);
351void ComPSet(char *Parameter,char *buffer,int nowLine);
352void ComPaint(char *Parameter,char *buffer,int nowLine);
353
354// StrOperation.cpp
355void KillSpaces(char *str1,char *str2);
356void KillStringSpaces(char *str);
357BOOL RemoveStringQuotes(char *str);
358void RemoveStringPare(char *str);
359void RemoveStringBracket(char *str);
360void SetStringQuotes(char *str);
361int FormatString_EscapeSequence(char *buffer);
362void SlideString(char *str,int slide);
363void SlideBuffer(char *buffer,int length,int slide);
364int GetCpFromLine(int LineNum);
365BOOL GetLineNum(int pos,int *pLine,char *FileName);
366char GetEndXXXCommand(char es);
367void GetDefaultNameFromES(char es,char *name);
368void GetCalcName(int idCalc,char *name);
369BOOL IsFile(char *path);
370BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath);
371BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
372void ShortPathToLongPath(const char *ShortPath,char *LongPath);
373
374//calculation.cpp
375bool IsNumberTopChar(const char *buffer);
376bool IsNumberChar(const char c);
377BOOL IsNumCalcMark(const char *Command,int p);
378BOOL IsNumCalcMark_Back(const char *Command,int p);
379BOOL IsStrCalcMark(const char c);
380BOOL IsExponent(const char *Command,int p);
381int GetLiteralIndex(_int64 i64data);
382int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
383DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
384BOOL GetConstCalcBuffer(const char *name,const char *Parameter,char *pCalcBuffer);
385DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
386int IsStrCalculation(char *Command);
387BYTE GetCalcId(const char *Command,int *pi);
388BOOL GetNumOpeElements(const char *Command,int *pnum,
389 char *values[255],long calc[255],long stack[255]);
390
391//NumOpe_GetType.cpp
392int AutoBigCast(int BaseType,int CalcType);
393BOOL CheckCalcType(int idCalc,int *type,int sp);
394bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL );
395bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType );
396
397//Subroutine.cpp
398int GetCallProcName(char *buffer,char *name);
399int GetProc(char *name,void **ppInfo);
400void SplitObjectName(const char *name,char *ObjectName,int *pRefType);
401bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true );
402bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType);
403bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType );
404bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType );
405GlobalProc *AddSubData( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic = false );
406void GetSubInfo(void);
407void DeleteSubInfo(GlobalProc **ppSubHash,char **ppMacroNames,int MacroNum);
408void DeleteDeclareInfo(void);
409int AddProcPtrInfo( const string &typeExpression, int nowLine );
410bool IsNeedProcCompile();
411
412//OldStatement.cpp
413void Opcode_Input(const char *Parameter);
414void Opcode_Print(const char *Parameter,BOOL bWrite);
415
416//error.cpp
417void SetError(int ErrorNum,const char *KeyWord,int pos);
418void SetError(int ErrorNum,const string &keyWord,int pos);
419void SetError();
420void CompileMessage(char *buffer);
421bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,const int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum);
422bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum);
423
424//Compile.cpp
425void GetIdentifierToken( char *token, const char *source, int &pos );
426int JumpStatement(const char *source, int &pos);
427void DebugVariable(void);
428void Compile(void);
429
430//Diagnose.cpp
431void Diagnose();
432
433//gc.cpp
434void InitGCVariables(void);
435void PerformedGcVarSchedule(void);
436
437
438
439#ifdef _DEBUG
440/*Debug*/
441/*
442#define HeapAlloc CheckHeapAlloc
443#define HeapReAlloc CheckHeapReAlloc
444LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
445LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
446*/
447#endif
Note: See TracBrowser for help on using the repository browser.