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

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

BasicSysDirをGetAppDirに置き換えた

File size: 14.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
21#define foreach BOOST_FOREACH
22
23using namespace std;
24
25#ifdef _AMD64_
26#include "../BasicCompiler64/resource.h"
27#include "../BasicCompiler64/CommandValue.h"
28#include "../BasicCompiler64/FunctionValue.h"
29#define OPCODE_H_PATH "../BasicCompiler64/opcode.h"
30#else
31#include "../BasicCompiler32/resource.h"
32#include "../BasicCompiler32/CommandValue.h"
33#include "../BasicCompiler32/FunctionValue.h"
34#define OPCODE_H_PATH "../BasicCompiler32/opcode.h"
35#endif
36
37#include "../BasicCompiler_Common/BasicFixed.h"
38#include "../BasicCompiler_Common/NonVolatile.h"
39#include "../BasicCompiler_Common/psapi.h"
40#include "../BasicCompiler_Common/BreakPoint.h"
41#include "../BasicCompiler_Common/LexicalScoping.h"
42
43
44
45#if defined(JPN)
46//日本語
47#include "common_msg_jpn.h"
48#else
49//英語
50#include "common_msg_eng.h"
51#endif
52
53
54#define PTR_SIZE sizeof(LONG_PTR)
55#define OBJECT_HEAD_SIZE PTR_SIZE*4
56
57#define MAX_LEN 65535
58#define VN_SIZE 512
59#define DIGIT_SIZE 128
60#define MAX_PARMS 64
61#define MAX_ARRAYDIM 16
62#define MAX_HASH 32761
63
64
65#ifdef _AMD64_
66#define PLATFORM 64
67#else
68#define PLATFORM 32
69typedef long LONG_PTR;
70typedef DWORD ULONG_PTR;
71#endif
72
73
74//未定義の定数情報
75#ifndef IMAGE_FILE_MACHINE_AMD64
76 #define IMAGE_FILE_MACHINE_AMD64 0x8664
77#endif
78
79#ifdef _AMD64_
80 #ifndef IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
81 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
82 #endif
83#else
84 #ifndef IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
85 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
86 #endif
87#endif
88
89
90extern HWND hOwnerEditor;
91extern HANDLE hHeap;
92extern int cp;
93extern bool isUnicode;
94extern int typeOfPtrChar;
95extern int typeOfPtrUChar;
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 <Smoothie.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 <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, const string &baseDirPath );
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(const char *name);
297DllProc *GetDeclareHash(char *name);
298void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs );
299UserProc *GetSubHash(const char *name,BOOL bError=0);
300UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0);
301UserProc *GetClassMethod( const char *className, const char *methodName );
302
303//Object.cpp
304void CallConstructor( const char *ObjectName,const int *SubScripts, const Type &type,const char *Parameter);
305bool Operator_New( const char *expression, const Type &baseType, Type &resultType );
306
307//Overload.sbp
308UserProc *OverloadSolutionWithStrParam(
309 const char *name,
310 std::vector<UserProc *> &subs,
311 const char *Parameter,
312 const char *ObjectName);
313UserProc *OverloadSolution(
314 const char *name,
315 std::vector<UserProc *> &subs,
316 const Parameters &params,
317 const Type &returnType );
318
319//Debug.cpp
320void Debugger_StepIn(void);
321void Debugger_StepOver(void);
322void Debugger_StepCursor(void);
323void Debugger_Stop(void);
324void Debugger_Pause(void);
325ULONG_PTR rva_to_real(DWORD p);
326GlobalProc *GetSubFromObp(ULONG_PTR pos);
327void ReadOpBuffer();
328void DebugProgram(void);
329
330//VarList.cpp
331void InitVarList(DWORD dwThreadId);
332BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
333BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
334
335//WatchList.cpp
336ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
337ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
338int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss);
339
340//MakeExe.cpp
341void StepCompileProgress(void);
342void DeleteConstInfo(CONSTINFO **ppConstHash);
343void DeleteDeclareInfo(void);
344void AddSourceCode(char *buffer);
345void OutputExe(void);
346int MainThread(DWORD dummy);
347
348//Intermediate_Step1.cpp
349void ChangeReturnCode(char *buffer);
350void DeleteComment(char *buffer);
351void KillReturnCode(char *buffer);
352void CheckParenthesis(char *buffer);
353BOOL CheckParenthesis2(char *buffer);
354void DirectiveCheck(void);
355void NextCommandFormat(char *buffer);
356void SetEscapeSequenceFormat(char *buffer);
357void DefCommandFormat(char *buffer);
358void IfCommandFormat(char *buffer);
359void CheckPareCommand(void);
360
361//Intermediate_Step2.cpp
362bool GetConstInfo(void);
363void ChangeCommandToCode(char *buffer);
364
365//preprocessor.cpp
366char *OpenBasicFile(char *FileName);
367
368//Resource.cpp
369void GetResourceData(char *FileName);
370
371//CommandFormat.cpp
372void ComOpen(char *Parameter,char *buffer,int nowLine);
373void ComClose(char *Parameter,char *buffer);
374void ComField(char *Parameter,char *buffer);
375void ComLine(char *Parameter,char *buffer,int nowLine);
376void ComCircle(char *Parameter,char *buffer,int nowLine);
377void ComPSet(char *Parameter,char *buffer,int nowLine);
378void ComPaint(char *Parameter,char *buffer,int nowLine);
379
380// StrOperation.cpp
381void KillSpaces(char *str1,char *str2);
382void KillStringSpaces(char *str);
383BOOL RemoveStringQuotes(char *str);
384void RemoveStringPare(char *str);
385void RemoveStringBracket(char *str);
386void SetStringQuotes(char *str);
387int FormatString_EscapeSequence(char *buffer);
388void SlideString(char *str,int slide);
389void SlideBuffer(char *buffer,int length,int slide);
390_int8 IsCommandDelimitation(char c);
391BOOL IsBlank(char c);
392int GetOneParameter(const char *Parameter,int pos,char *retAns);
393int JumpOneParameter(char *Parameter,int i);
394int GetStringInQuotation(char *buffer,char *ReadBuffer);
395int GetStringInPare(char *buffer,const char *ReadBuffer);
396int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer);
397int GetStringInBracket(char *buffer,const char *ReadBuffer);
398int JumpStringInPare(const char *buffer,int pos);
399int JumpStringInBracket(const char *buffer,int pos);
400int GetCpFromLine(int LineNum);
401BOOL GetLineNum(int pos,int *pLine,char *FileName);
402char GetEndXXXCommand(char es);
403void GetDefaultNameFromES(char es,char *name);
404void GetCalcName(int idCalc,char *name);
405BOOL IsFile(char *path);
406BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath);
407BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
408void ShortPathToLongPath(const char *ShortPath,char *LongPath);
409
410//calculation.cpp
411bool IsNumberTopChar(const char *buffer);
412bool IsNumberChar(const char c);
413BOOL IsNumCalcMark(const char *Command,int p);
414BOOL IsNumCalcMark_Back(const char *Command,int p);
415BOOL IsStrCalcMark(const char c);
416BOOL IsExponent(const char *Command,int p);
417int GetLiteralIndex(_int64 i64data);
418int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
419DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
420BOOL GetConstCalcBuffer(const char *name,const char *Parameter,char *pCalcBuffer);
421DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
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 GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL );
431bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType );
432
433//Subroutine.cpp
434int GetCallProcName(char *buffer,char *name);
435int GetProc(char *name,void **ppInfo);
436void SplitObjectName(const char *name,char *ObjectName,int *pRefType);
437bool SplitMemberName( const char *desc, char *object, char *member, CClass::RefType &refType );
438bool SplitMemberName( const char *desc, char *object, char *member );
439bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true );
440bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType);
441bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType );
442bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType );
443GlobalProc *AddSubData( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic = false );
444void GetSubInfo(void);
445void DeleteSubInfo(GlobalProc **ppSubHash,char **ppMacroNames,int MacroNum);
446void DeleteDeclareInfo(void);
447int AddProcPtrInfo( const string &typeExpression, int nowLine );
448void DeleteProcPtrInfo(void);
449bool IsNeedProcCompile();
450
451//OldStatement.cpp
452void Opcode_Input(const char *Parameter);
453void Opcode_Print(const char *Parameter,BOOL bWrite);
454
455//LoopRefCheck.cpp
456class CLoopRefCheck{
457 char **names;
458 int num;
459 void init();
460public:
461 CLoopRefCheck();
462 ~CLoopRefCheck();
463 void add(const char *lpszInheritsClass);
464 void del(const char *lpszInheritsClass);
465 BOOL check(const CClass &inheritsClass) const;
466};
467extern CLoopRefCheck *pobj_LoopRefCheck;
468
469//DataTable.cpp
470class DataTable{
471 void *pdata;
472 int size;
473
474public:
475 DataTable();
476 ~DataTable();
477 void Init();
478
479 int AddBinary( const void *pdata, int size );
480 int Add( _int64 i64data );
481 int Add( int i32data );
482 int Add( double dbl );
483 int Add( float flt );
484 int AddString( const char *str, int length );
485 int AddString( const char *str );
486
487 const void *GetPtr() const;
488 int GetSize() const;
489};
490extern DataTable dataTable;
491
492//error.cpp
493void SetError(int ErrorNum,const char *KeyWord,int pos);
494void SetError(int ErrorNum,const string &keyWord,int pos);
495void SetError();
496void CompileMessage(char *buffer);
497bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,const int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum);
498bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum);
499
500//Compile.cpp
501void ReallocNativeCodeBuffer();
502void GetIdentifierToken( char *token, const char *source, int &pos );
503int JumpStatement(const char *source, int &pos);
504void DebugVariable(void);
505void Compile(void);
506
507//Diagnose.cpp
508void Diagnose();
509
510//gc.cpp
511void InitGCVariables(void);
512void PerformedGcVarSchedule(void);
513
514
515
516#ifdef _DEBUG
517/*Debug*/
518/*
519#define HeapAlloc CheckHeapAlloc
520#define HeapReAlloc CheckHeapReAlloc
521LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
522LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
523*/
524#endif
Note: See TracBrowser for help on using the repository browser.